09.04.2016 Views

www.ebook777.com

Make_Getting_Started_with_Processing_Second_Edition

Make_Getting_Started_with_Processing_Second_Edition

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

1. Variables declared outside of setup() and draw() are created.<br />

2. Code inside setup() is run once.<br />

3. Code inside draw() is run continuously.<br />

Example 5-3: Global Variable<br />

The following example puts it all together:<br />

int x = 280;<br />

int y = -100;<br />

int diameter = 380;<br />

void setup() {<br />

size(480, 120);<br />

fill(102);<br />

}<br />

void draw() {<br />

background(204);<br />

ellipse(x, y, diameter, diameter);<br />

}<br />

Follow<br />

Now that we have code running continuously, we can track the<br />

mouse position and use those numbers to move elements on<br />

screen.<br />

Example 5-4: Track the Mouse<br />

The mouseX variable stores the x coordinate, and the mouseY variable<br />

stores the y coordinate:<br />

Response 51

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!