Pygrr PolyArt (part 2)

Here we are, part two out of three! In this episode, we'll tackle the shape editing and drawing!

First of all, let's add some "nodes" onto each vertex, to allow the user to interact with the shape. If the user right clicks on a node, then it deletes that vertex. Note that it's impossible to delete any node if there are only 3, as then it wouldn't be a polygon anymore!

Now, if the user left clicks on one of the lines (not the smoothed lines, just the rigid ones), it should create a point at their mouse click. We can do this by doing some maths, the wedge product and the dot product. We simply iterate through each line on the shape, checking if the mouse position plugged into the wedge and dot gives us the right output. If they do, then it's on the line! Here's it working:

Now all we need is if the user left clicks and drags a point, then it'll move the point. Note also, in both creating points and moving points, turning the snap grid on and off does indeed have an impact! Here we go:

Let's show off and draw a rubber duck...

Now all we need is to be able to use the arrow keys to re-centre the drawing by moving it around.

Tada! That's all for this, next up, saving and importing. Note that in this art program, you're limited to only 1 polygon, as it's a "pygrr.Polygon" object... In further updates, I'll make another program which supports multiple polygons, so you can create proper detailed things, with multiple colours and everything...

Isaac, over and out...

Popular posts from this blog

Messing around with procedural art - Turtle graphics

The fossils of Morocco | Mosasaurus beaugei

Blog post #0 - Hello, world!