07.01.2013 Views

Fractal.Invaders, Substrate (Interview with Jared Tarbell) - Processing

Fractal.Invaders, Substrate (Interview with Jared Tarbell) - Processing

Fractal.Invaders, Substrate (Interview with Jared Tarbell) - Processing

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.

15 Using <strong>Processing</strong><br />

}<br />

}<br />

diagonals(dx[i], dy[i]);<br />

void diagonals(int x, int y) {<br />

line(x, y, x+20, y-40);<br />

line(x+10, y, x+30, y-40);<br />

line(x+20, y, x+40, y-40);<br />

}<br />

Object-oriented programming is a way of structuring code into objects, units of code that<br />

contain both data and functions. This style of programming makes a strong connection<br />

between groups of data and the functions that act on this data. The diagonals()<br />

function can be expanded by making it part of a class defi nition. Objects are created using<br />

the class as a template. The variables for positioning the lines and setting their drawing<br />

attributes then move inside the class defi nition to be more closely associated <strong>with</strong><br />

drawing the lines. Object-oriented programming is discussed further on pages 395–411.<br />

Diagonals da, db;<br />

void setup() {<br />

size(100, 100);<br />

smooth();<br />

// Inputs: x, y, speed, thick, gray<br />

da = new Diagonals(0, 80, 1, 2, 0);<br />

db = new Diagonals(0, 55, 2, 6, 255);<br />

}<br />

void draw() {<br />

background(204);<br />

da.update();<br />

db.update();<br />

}<br />

class Diagonals {<br />

int x, y, speed, thick, gray;<br />

Diagonals(int xpos, int ypos, int s, int t, int g) {<br />

x = xpos;<br />

y = ypos;<br />

speed = s;<br />

thick = t;<br />

gray = g;<br />

}<br />

0-07<br />

cont.<br />

0-08

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

Saved successfully!

Ooh no, something went wrong!