Sketch 04: Refactoring an Early Project

This week I focused on revising my first sketch to make better use of objects and functions. I maintained the original premise of drawing a number of different shapes with different colour and size properties, but changed how variation was determined and how the shapes were organized on the canvas.

Two simple functions make up the code: one which determines the shape’s visual attributes and a second function that actually draws the shape. The first function (configureShape) uses a series of restricted random calls for the properties and then reassigns these values to the shape object. The second function (drawShape) plugs these values into either ellipse, rect, or line functions and draws them to the screen.


Press “R” to restart the sketch and produce new confetti

code

Beyond this, I was interested in storing the shapes and then revealing them in different ways. Although not ideal, each shape is drawn individually, sequentially, and then added to an array. Pressing “c” shows all the circles, “s” reveals the squares, “a” shows all shapes, “r” resets what’s shown as well as the background colour. Lastly, pressing and dragging the mouse up and down on the canvas reveals individual rows.


Press “c”, “s”, “a”, “r” or click and drag up and down

code

With this second iteration, I couldn’t get it to work with the crosses. I’m not quite sure why they were behaving differently but hope to dig into it.