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.

*<br />

title: Bouncing Ball<br />

description: ball deflects off sketch window edges<br />

created: August 9, 2005<br />

by: Ira Greenberg<br />

*/<br />

// declare global variables<br />

int xspeed, yspeed;<br />

int xpos, ypos, wdth, ht;<br />

//initialize sketch<br />

void setup(){<br />

//set sketch window size <strong>and</strong> background color<br />

size(400, 400);<br />

background(0);<br />

//ball speed<br />

xspeed = 3;<br />

yspeed = 6;<br />

//ball size<br />

wdth = 10;<br />

ht = 10;<br />

// turn off shape stroke rendering<br />

noStroke();<br />

//initial ball placement<br />

xpos = width/2;<br />

ypos = height/2;<br />

frameRate(30);<br />

}<br />

// begin animation loop<br />

void draw(){<br />

//update background<br />

background(0);<br />

//draw ball<br />

ellipse(xpos, ypos, wdth, ht);<br />

//upgrade position values<br />

xpos+=xspeed;<br />

ypos+=yspeed;<br />

CODE GRAMMAR 101<br />

77<br />

3

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

Saved successfully!

Ooh no, something went wrong!