04.04.2013 Views

Processing: Creative Coding and Computational Art

Processing: Creative Coding and Computational Art

Processing: Creative Coding and Computational Art

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

PROCESSING: CREATIVE CODING AND COMPUTATIONAL ART<br />

588<br />

r<strong>and</strong>om(255), r<strong>and</strong>om(255));<br />

}<br />

else if (xbtn1X-btn1W/2 && mouseX< btn1X+btn1W/2 && ➥<br />

mouseY>btn1Y-btn1H/2 && mouseY< btn1Y+btn1H/2){<br />

xSpeed-=.2;<br />

btn1Background = btnDownState;<br />

}<br />

if (mouseX>btn2X-btn2W/2 && mouseX< btn2X+btn2W/2 && ➥<br />

mouseY>btn2Y-btn2H/2 && mouseY< btn2Y+btn2H/2){<br />

xSpeed+=.2;<br />

btn2Background = btnDownState;<br />

}<br />

if (mouseX>btn3X-btn3W/2 && mouseX< btn3X+btn3W/2 && ➥<br />

mouseY>btn3Y-btn3H/2 && mouseY< btn3Y+btn3H/2){<br />

if (isTrailsSelected) {<br />

isTrailsSelected = false;<br />

isTrailable = false;<br />

}<br />

else {<br />

isTrailsSelected = true;<br />

isTrailable = true;<br />

}<br />

}<br />

}<br />

When the mouse is pressed, the code checks if the mouse is over one of the buttons by<br />

comparing the button’s coordinates to the mouse position. To keep things simple, I used a<br />

bunch of redundant code in the three conditional statements. When either of the speed<br />

buttons are pressed, I set the fill color of the buttons with the lines:<br />

or<br />

btn1Background = btnDownState;<br />

btn2Background = btnDownState;<br />

These buttons also obviously increment/decrement the xSpeed of the moving square.<br />

When the check box is pressed, it is toggled either on or off depending upon its current<br />

state, setting the Boolean variable isTrailsSelected. When isTrailsSelected is true, an<br />

x fills the box. I also set the Boolean variable isTrailable to the same value as

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

Saved successfully!

Ooh no, something went wrong!