Computer Science Canada N Sided Figures |
Author: | mirhagk [ Mon Oct 04, 2010 10:43 pm ] | ||
Post subject: | N Sided Figures | ||
I was working on a few ideas for a game roughly based on Flatland (the book). It is a two dimensional world, and I would set the game as playing as a sort of god-like figure that would control the little shapes. In order to do this I would need to draw shapes of any type. I came up with a few ideas, the worst of which was switching between different functions for each shape, or even using pictures. Then I remembered, in Flatland the highest level shape was the one closest to a circle, so I started with a circle. If I took two points on that circle and connected them, I'd get a line. If I took 3, I'd get a triangle. 4 would be a square, and n would be a n-sided shape. The method accepts 5 arguments. The first two are the x and y of the CENTER of the shape. The third is the number of sides it has. The fourth is the radius of the circle it draws points from, which controls the size of the figure. The last argument is used to rotate the figure by any angle (rotations are around the center in a counter-clockwise direction) So what you may ask? Well haven't you ever wanted to maybe draw a triangle, or a pentagon, but didn't want to have to define every point. Or maybe you wanted to draw a square, but with the ability for it to rotate. Well now you can, and here is my code. If anyone has some suggestions for performance boosts, I'm open to them (I'm thinking of a system right now that will not need an array, only the first point and the current point need to be stored)
|
Author: | DemonWasp [ Tue Oct 05, 2010 4:20 am ] |
Post subject: | RE:N Sided Figures |
Not a bad implementation (specifically, the method signature is well-done), but you should be able to figure out a way to do this without using arrays. Doing so will improve the performance of your drawing algorithm, letting you draw more complex scenes. You probably also want a parameter for draw-colour. |
Author: | mirhagk [ Tue Oct 05, 2010 7:46 am ] |
Post subject: | RE:N Sided Figures |
Or would it be faster to leave the array and call draw polygon, it would severly decrease the amount of drawing calls. |