The Task

We will practice our basic understanding of Processing and polar coordinates. In class we build a simple polygon function. In this assignment you will produce a Processing program that will generate a series of random fading stars on a black background. We have covered in class all of the parts you need to know.

A k-pointed star is defined as we saw in class by using k evenly spaced points around a circle. The points are connected as we go around the star in clockwise order starting at point numbered 0 and going to point numbered k-1. In order to draw a polygon we connect each point numbered j with a point numbered j+1, that is, we connect adjacent points around the circle for all k points in the circle. So point 0 would connect to point 1 and 1 to 2 and 2 to 3 and... For a star you might connect point j to point j+2. So connect 0 to 2, 1 to 3, 2 to 4, etc... We call the amount added to j the connect number. If we skip 1 point then this is the way would normally draw a 5 pointed star for example. In class we built a function called poly. poly was defined:

void poly(float x, float y, float r, int numSides)

For this assignment you must create a routine called star:

void star(float x, float y, float r, int numSides, int connectNumber, color c, int weight)

The Changes you need to Make

  1. ( 20 pts ) Make a window that is 1000 by 800 with black background. Set the frame rate to 2 frames per second.
  2. ( 40 pts ) Create a star routine that uses a connectNumber to create polygons or stars depending on what the connectNumber is. Note as described above if connectNumber=1 then you will get a polygon. If connectNumber=2 then you will get traditional looking stars if connectNumber is larger it will make other types of stars.
  3. ( 20 pts ) When the star or polygon is drawn be sure x and y represent the center of the star or polygon and that the radius (as done in class) is the value r. Of course, the number of sides is numSides.
  4. ( 10 pts ) Allow the routine as described above to take a color. The color will be the color of the lines drawn.
  5. ( 10 pts ) Allow the routine as described above to take an integer weight that is the weight of the lines drawn.
  6. ( 20 pts ) Every frame draw a star at a random location (center in the window), random color with full saturation and brightness, random size between 20 and up to 200, random number of sides between 3 and up to and including 10, and random weight of line between 1 and up to and including 5. Hint: remember the int function to convert things to an integer!!
  7. ( 20 pts ) The connectNumber should be between 1 and (number of sides - 1)/2 points!
  8. ( 20 pts ) Use a semi-transparent black wash (fade) the screen to black with each frame of the movie. An alpha of 35 works well.
  9. (warning) If you do not indent properly or if I change the size of the window in the size function and your program doesn't adapt I will take off 40 points. I mean it. Please indent by 3 spaces each level.
  10. (+30 extra credit) If the number of sides is less than 3 set the number of sides to 3. If the connectNumber is greater than (number of sides - 1)/2 then make it (number of sides - 1)/2.
  11. (+30 extra credit) If the connectNumber equals 0 then instead of drawing a star or polygon, draw the lines from the center to the points around the outside. For example a square will look like a plus sign with the lines draw from the center to the corners instead. We did this in class so this should be easy. Then allow the connector number to be a random between 0 and (number of sides - 1)/2 points!
  12. (+30 extra credit) Make the color of the polygons be red if they are at the top of the window and go through the color spectrum to hue 200 at the bottom of the window.

Here is a movie of the program running.

Submission

Save your results as a .pde file and submit the file to the bblearn page.