Giter Club home page Giter Club logo

lart's Introduction

Lart

Lart is a library for generating 2D vector art in Rust meant to be plotted.

It provides a set of primitives geometric types and operations on them alongside a "canvas" to draw on.

Here's an example that showcases:

  • automatic command line generation and parsing via the sketch_parms! macro
  • boolean operations on geometries (union, intersection, difference)
  • polygon buffering
# use lart::*;

sketch_parms! {
    lines: u8 = 2,
    points: u16 = 10,
}

fn main() {
    let parms = Parms::from_cli();
    let mut doc = Sketch::new("example").with_page(Page::A6);

    let bbox = doc.page_bbox();

    let mut drawn = Geometry::new();

    for _ in 0..parms.lines {
        let mut p = Path::new();
        for _ in 0..parms.points {
            p.push(V::in_rect(&mut doc, &bbox));
        }
        let g = Geometry::from(p).buffer(-2.0);
        let g = g - &drawn;
        drawn = drawn | &g;
        doc.geometry(g);
    }

    doc.fit_to_page(20.0);
    doc.save().unwrap();
}

To run a sketch you can run it from the command line and the svg is automatically saved in a wip/<sketch_name>/ directory. The parameters defined with the sketch_parms! macro are automatically parsed as long command line options.

$ cargo run --example chaotic_hex
$ cargo run --example chaotic_hex -- --iterations 200 --page A5

Check out the lart-sketches directory for more usage patterns.

lart-viewer

lart also provides an interactive viewer in Rust based on vsvg that allows to quickly change the parameters of the sketch via an autogenerated GUI.

To use it run it from the command line providing it the command to run

$ cargo run --release --bin lart-viewer -- cargo run --example chaotic_hex --

Note that if you pass a cargo run invocation the sketch will be automatically re-compiled each time the source changes.

lart's People

Contributors

danieledapo avatar

Stargazers

Jonathan Dahan avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.