Getting Started with Processing by Casey Reas and Ben Fry

Getting Started with Processing by Casey Reas and Ben Fry

Author:Casey Reas and Ben Fry
Language: eng
Format: mobi
Publisher: O'Reilly Media, Inc.
Published: 2015-09-22T04:00:00+00:00


Make a Function

In this section, we’ll draw an owl to explain the steps involved in making a function.

Example 9-3: Draw the Owl

First, we’ll draw the owl without using a function:

void setup() { size(480, 120); } void draw() { background(176, 204, 226); translate(110, 110); stroke(138, 138, 125); strokeWeight(70); line(0, -35, 0, -65); // Body noStroke(); fill(255); ellipse(-17.5, -65, 35, 35); // Left eye dome ellipse(17.5, -65, 35, 35); // Right eye dome arc(0, -65, 70, 70, 0, PI); // Chin fill(51, 51, 30); ellipse(-14, -65, 8, 8); // Left eye ellipse(14, -65, 8, 8); // Right eye quad(0, -58, 4, -51, 0, -44, -4, -51); // Beak }

Notice that translate() is used to move the origin (0,0) to 110 pixels over and 110 pixels down. Then the owl is drawn relative to (0,0), with its coordinates sometimes positive and negative as it’s centered around the new 0,0 point. See Figure 9-1.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.