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.

stroke(200);<br />

rect(eraserBtn[0], eraserBtn[1], eraserBtn[2], eraserBtn[3]);<br />

image(eraser, eraserBtn[0]+eraserBtn[2]/2-eraser.width/2, ➥<br />

eraserBtn[1]+eraserBtn[3]/2-eraser.height/2);<br />

The code to draw all the interface elements, although verbose, is very straightforward,<br />

with the elements positioned in the display window in reference to other existing elements.<br />

Notice the numerous calls to the fill() <strong>and</strong> stroke() functions. As you’ll remember,<br />

these calls set the rendering state of the program; if I call fill(255, 0, 0) until I call<br />

fill() again with different values, all future shapes will be filled with red. Also notice that<br />

I did not include any interactive code (the code that makes the buttons work) directly with<br />

the GUI elements.<br />

// draw palette<br />

int paletteCounter=0;<br />

for (float i=0; imenu[1]+menu[3]) {<br />

smooth();<br />

//pencil<br />

if (isPencilSelected){<br />

stroke(paintColor);<br />

strokeWeight(sliderValue);<br />

line(mouseX, mouseY, pmouseX, pmouseY);<br />

}<br />

//brush<br />

else if (isBrushSelected){<br />

strokeWeight(.25);<br />

float nozzleRadius = sliderValue;<br />

float sprayFeather = sliderValue*4;<br />

float strokeAngle = 0;<br />

float px = 0, py = 0, px2 = 0, py2 = 0;<br />

stroke(paintColor);<br />

for (int i=0; i

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

Saved successfully!

Ooh no, something went wrong!