🖋️
valora
  • Introduction
  • Painting the Canvas
  • Path Creation
  • Path Manipulation
  • Custom Shaders
  • Being the Artist
  • Gallery
Powered by GitBook
On this page
  • Immediate
  • Held

Was this helpful?

Path Creation

PreviousPainting the CanvasNextPath Manipulation

Last updated 5 years ago

Was this helpful?

There are two ways to create a path in valora.

Immediate

You could use draw commands on the canvas which immediately result in the path, but the path can only be drawn and not held for mutation or other work.

canvas.move_to(P2::new(430., 225.));
canvas.line_to(P2::new(83., 225.));
canvas.line_to(P2::new(256., 525.));
canvas.close_path();
canvas.set_stroke_width(2.);
canvas.stroke();

Held

Alternatively, you could use some types provided by valora to define the path in a way you can hold, mutate, and otherwise do work with. For example, this code which repeats the triangle scaling down each time:

let triangle = Ngon::triangle(world.center(), 200.);
let repeated = std::iter::successors(Some(triangle), |t| {
    Some(t.clone().scale(0.9))
});

for triangle in repeated.take(15) {
    canvas.paint(Stroked {
        width: 2.,
        element: triangle,
    });
}

Valora provides for equilateral shapes, for ellipses, and for all other shapes.

Ngon
Ellipse
Polygon
A path created immediately.
A path generated, held, and manipulated.