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.

In the next example, I use beginRecord() <strong>and</strong> endRecord() as part of a simple drawing<br />

program (see Figure A-11). When you want to output your drawing, simply press any key<br />

on the keyboard; this will cause your sketch to close <strong>and</strong> your drawing to be saved to your<br />

sketch directory in PDF format.<br />

/*<br />

Hairy Brush Drawing<br />

Ira Greenberg, October 9, 2006<br />

outputs to PDF<br />

*/<br />

import processing.pdf.*;<br />

void setup() {<br />

size(400, 400);<br />

background(255);<br />

smooth();<br />

String id = str(hour())+"_"+str(minute())+"_"+str(second());<br />

beginRecord(PDF, "img"+id+".pdf");<br />

}<br />

void draw() {<br />

stroke(0);<br />

strokeWeight(4);<br />

if (mousePressed){<br />

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

bleed(pmouseX, pmouseY);<br />

}<br />

}<br />

void bleed(float x, float y){<br />

float px = 0, py = 0, angle = 0, radius=10;<br />

float brushDetail = 36;<br />

stroke(0, 100);<br />

strokeWeight(.5);<br />

for (int i=0; i

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

Saved successfully!

Ooh no, something went wrong!