tabreturn.github.io

Processing.py in Ten Lessons – 1.3: Drawing

2018-06-14

Drawing

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.

`point()`

Draws a point, the width of which is determined by the `strokeWeight()`. The arguments represent the x- and y-coordinates respectively.
Reference link: `point()`

`triangle()`

Draws a triangle. The six arguments represent three x/y-coordinate pairs.
Reference link: `triangle()`

`ellipse()`

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.
Reference link: `ellipse()`

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:
`ellipseMode()`
`rectMode()`

`quad()`

Draws a quadrilateral (a four-sided polygon). The eight arguments represent four x/y-coordinate pairs.
Reference link: `quad()`

`line()`

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.
Reference link: `line()`