icm: squares with for() loops

prompt: The idea this week is to explore re-organizing your code. It is 100% legitimate to turn in a version of a previous assignment where nothing changes for the end user, but the code has been restructured. You may, however, choose to try a new experiment from scratch. Aim to keep setup() and draw() as clean as possible, and do everything (all calculations, drawing, etc.) in functions that you create yourself. Possibilities (choose one or more):

  • Reorganize “groups of variables” into objects.
  • Break code out of setup() and draw() into functions.
  • Use a function to draw a complex design multiple times with different arguments.
  • If you are feeling ambitious, try embedding a function into an object.

after looking at my hexagosh code last week, dan said it’d be useful for me to try the same exercise with squares since the math would be easier than with hexagons.

i started with vars for each set of squares. it looked kinda like:

but i couldn’t figure out where push(), translate(), and pop() would fit in.

i moved to the format below after looking at lauren’s owl code. i got the canvas to fill with squares using nested loops (!) and started creating different functions for different quadrants of the canvas, even though it seems like i should be able to just use the same function and tell it to fill(blue) when x and y are between # and #, fill(orange) when x and y are between other #s, etc. i’m still having a hard time knowing what goes into a var, what goes into a function, and how to set parameters that let me change the color/angle/whatever of one chunk of squares without affecting all the squares ;(

i’ll update this post as i make adjustments.


Leave a Reply