In this section, you’ll look at a number of drawing functions.
Begin a new sketch (File > New) and then save it as “drawing” (File > Save As…). Add some code to set things setup before proceeding:
When you run the sketch, an empty blue display window appears. What follows below are descriptions for several drawing functions, along with some code to add to your working sketch. Feel free to experiment with the arguments to see how things respond. Each example builds on the code before it, so you’ll need to work through all of them, entering each line as you progress.
Draws a point, the width of which is determined by the
strokeWeight(). The arguments represent the x- and y-coordinates respectively.
Draws a triangle. The six arguments represent three x/y-coordinate pairs.
Draws an ellipse. The first pair of arguments represent an x/y coordinate that marks the centre of the ellipse; the second pair of arguments represent its width and height.
Ellipse and Rect Modes
You’ve seen how rectangles are drawn from the top-left corner, and ellipses are centred on the x/y coordinate. If you wish to change this behaviour – for example, have the
rect function draw from the center – refer to the following functions:
Draws a quadrilateral (a four-sided polygon). The eight arguments represent four x/y-coordinate pairs.
Draws a straight line between two points. The first pair of arguments represent the starting x/y coordinates; and the second pair, the ending x/y coordinates.
Time for a challenge!
Begin a new sketch (File > New) and then save it as “rainbow” (File > Save As…).
Add some code to get started:
Using what you’ve learnt thus far, complete the rainbow below:
Clue: you can overlap shapes to mask-off others.