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:

  1. ability to add or remove points
  2. moving points around
  3. changing colours
  4. saving and opening
  5. 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:


Very minimalistic design, I don't want to bloat it with unnecessary features...


Here's the first draft of the UI. As you can see, there's some nice buttons and entry widgets, and a nice grid on the canvas. There's even a little cross to show users where the "origin" of their shape is (the centre of the shape, thus, where it will rotate around). In this draft, you can see I haven't implemented the file options (clear, save, open), and in this one, the only data that would be saved is the shape itself, and whether or not it is "smooth"... You'll see what that means in part 2, when I code the shape creation aspect itself... It's awesome - you don't wanna miss it!

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.


Cool beans, what to do now? Let's make the entry widgets at the bottom work, by simply binding the "return" key (referred to as the "enter" key in some countries) to a function, wherein, if it's pressed inside a widget, it applies the colour. This has no error catching, however. For example, if you inputted colour "wadahdawjbd", you'd just crash the program, as the colour does not exist... I'll do error catching at the end of this series!

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...

Popular posts from this blog

Messing around with procedural art - Turtle graphics

The fossils of Morocco | Mosasaurus beaugei

Blog post #0 - Hello, world!