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.

56 Getting Started with Processing<br />

<strong>www</strong>.<strong>ebook777.com</strong><br />

float x;<br />

float y;<br />

float px;<br />

float py;<br />

float easing = 0.05;<br />

void setup() {<br />

size(480, 120);<br />

stroke(0, 102);<br />

}<br />

void draw() {<br />

float targetX = mouseX;<br />

x += (targetX - x) * easing;<br />

float targetY = mouseY;<br />

y += (targetY - y) * easing;<br />

float weight = dist(x, y, px, py);<br />

strokeWeight(weight);<br />

line(x, y, px, py);<br />

py = y;<br />

px = x;<br />

}<br />

Click<br />

In addition to the location of the mouse, Processing also keeps<br />

track of whether the mouse button is pressed. The mousePressed<br />

variable has a different value when the mouse button is pressed<br />

and when it is not. The mousePressed variable is a data type<br />

called boolean, which means that it has only two possible values:<br />

true and false. The value of mousePressed is true when a button<br />

is pressed.

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

Saved successfully!

Ooh no, something went wrong!