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 />

584<br />

fill(btn1Background);<br />

rect(btn1X, btn1Y, btn1W, btn1H);<br />

fill(75);<br />

text("speed -", btn1X-17, btn1Y+btn1H/4);<br />

//btn2 - increases speed<br />

fill(btn2Background);<br />

rect(btn2X, btn2Y, btn2W, btn2H);<br />

fill(75);<br />

text("speed +", btn2X-17, btn2Y+btn2H/4);<br />

//btn3 - check box controls mouse trails<br />

fill(255);<br />

rect(btn3X, btn3Y, btn3W, btn3H);<br />

fill(75);<br />

text("trails", btn3X+10, btn3Y+btn3H/4);<br />

if (isTrailsSelected){<br />

// draw x in box<br />

line(btn3X-btn3W/2, btn3Y-btn3H/2, btn3X+btn3W/2, btn3Y+btn3H/2);<br />

line(btn3X-btn3W/2, btn3Y+btn3H/2, btn3X+btn3W/2, btn3Y-btn3H/2);<br />

}<br />

//moving square<br />

fill(movingSquareBackground);<br />

noStroke();<br />

rect(x, y, w, h);<br />

x+=xSpeed;<br />

// show speed<br />

rect(x, y, w, h);<br />

fill(75);<br />

text(xSpeed, 10, height-10);<br />

// ensure square stays on screen<br />

if (x>width){<br />

x = 0;<br />

y = r<strong>and</strong>om(h/2, 70);<br />

movingSquareBackground = color(r<strong>and</strong>om(255), ➥<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){

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

Saved successfully!

Ooh no, something went wrong!