Forum Archive

Canvas Paths

Cubbarooney104

I have been experimenting with the canvas module a lot, but as of yet there is one thing that still doesn't make sense : path.

I understand the concept (you make a custom shape into the "memory" of the program and then print it), but the syntax doesn't make sense to me. For example, "canvas.add_curve" has six inputs. The first four are "control points", which I imagine are two points on the curve (just a guess). The last two are a (x,y) co-ord. But where are these co-ords ending up (as in, where is the line in relation to the co-ord)?

Lastly, I take it you have to close the figure in path before you can draw it.

Thanks,
Cubbarooney

omz

Maybe an example will help:

https://gist.github.com/omz/5087533

This shows how a curve is drawn, with some additional lines that hopefully make it a bit clearer how the two control points shape the curve.

Those are Bézier curves that are also used by most vector graphics apps, like Illustrator.

omz

Regarding your second question: You don't have to close a path to draw it, but when you're drawing lines and curves, you should have a move_to call after begin_path to define where the line starts. You'll see this in the example too. To see the effect of the close_path function, add canvas.close_path() just before the draw_path call.

Cubbarooney104

Thank you omz!

Makes sense now :)

Cubbarooney