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.

Working in Java, creating even the simplest animation is a little complicated, as you need<br />

to explicitly create a separate thread. In contrast, animation in <strong>Processing</strong> couldn’t be simpler.<br />

To illustrate this difference, I’ve coded a simple animation using Java, followed by the<br />

same animation using <strong>Processing</strong>’s draw() function (which encapsulates the thread creation<br />

process for us). The Java version is written to be run within <strong>Processing</strong>.<br />

// Animation in Java using a thread<br />

// This code should run ok in <strong>Processing</strong><br />

void setup(){<br />

size(400, 400);<br />

new SimpleAnimation();<br />

}<br />

class SimpleAnimation implements Runnable{<br />

int x, xspd = 3;<br />

//constructor<br />

SimpleAnimation(){<br />

Thread t = new Thread(this);<br />

t.start();<br />

}<br />

void run() {<br />

while (x

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

Saved successfully!

Ooh no, something went wrong!