Pygrr PolyArt (part 1)
Pygrr... It's doing pretty well at the moment! However, if we truly want users to be able to express themselves through it, what else do we need? Art. We need art. Custom models, here we go!
So, what's this post? This 3 part series is about PolyArt, a separate program I am developing to allow users to draw their own polygons and models to use within their games in Pygrr. What does it need? Here's a list of features:
- ability to add or remove points
- moving points around
- changing colours
- saving and opening
- importing into Pygrr
First, let's work on the UI. Tkinter (the module that Pygrr itself uses for rendering) also comes with some pretty neat UI packages for Python, with entry widgets, buttons and labels!
Here's a basic mock-up of how we want it to look:
Anyways, let's make the grid turn on and off with the "snap" button. This grid is just made up of lines drawn on the canvas on the start, so we can simply just remove their fill to make them transparent, and then give it back to them to make them visible once more. Putting this into a function toggle_snap(), which is then called when clicking the button gets the job done.
As you can see, I've just provided the user with a default square when they open the program, which works nicely, as you can see all the inputs are working! Note that for colours you can use both hex codes, or string colour names (from tkinter's colour system), and for numbers you can use whole or decimals. Oh yeah, I also removed the background colour chooser, because it was a bit pointless.
Fine, I'll show you what "smooth" means, now... Basically we can just input each point into a continuous spline, and create a smoothed version of the shape. I'll just show you:
As you can see, the square gets turned into a nice little circle! This works for every shape, too, you'll just have to wait and see the stuff you can do with it...
Isaac, over and out...