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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

PROCESSING: CREATIVE CODING AND COMPUTATIONAL ART<br />

160<br />

//setup structure runs once<br />

void setup(){<br />

size(400, 400);<br />

background(130, 130, 240);<br />

noFill();<br />

}<br />

/*draw function begins loop<br />

required by mouseMoved <strong>and</strong> mouseDragged<br />

functions later in the code*/<br />

void draw(){<br />

}<br />

/*custom function incrementally<br />

paints the screen–called when<br />

the mouse is pressed*/<br />

void fadeScreen(){<br />

fill(130, 130, 240, screenFadeValue);<br />

noStroke();<br />

rect(0, 0, width, height);<br />

}<br />

/*custom function paints shapes,<br />

boolean argument 'isDragged' controls<br />

shape style*/<br />

void paintShapes(boolean isDragged){<br />

if (isDragged){<br />

noStroke();<br />

ellipse(mouseX, mouseY, radiusX, radiusY);<br />

}<br />

else {<br />

noFill();<br />

stroke(r<strong>and</strong>om(255));<br />

rect(mouseX, mouseY, r<strong>and</strong>om(sizeMax), r<strong>and</strong>om(sizeMax));<br />

}<br />

}<br />

/* set shape size <strong>and</strong><br />

fill color on press*/<br />

void mousePressed(){<br />

// call custom function to clear screen<br />

fadeScreen();<br />

radiusX = r<strong>and</strong>om(sizeMax);<br />

radiusY = r<strong>and</strong>om(sizeMax);<br />

// set fill color for drawing<br />

fill(r<strong>and</strong>om(255), r<strong>and</strong>om(255), r<strong>and</strong>om(255), 100);<br />

}

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

Saved successfully!

Ooh no, something went wrong!