topical media & game development
graphic-processing-algorithm-Ch06-p139-p139.pde / pde
PGraphics pg; //define a buffer
int dim = 200; //screen dimension
void setup() {
size(dim, dim); //size up the screen
background(102); //set the background
pg = createGraphics(dim, dim, P3D); //create a buffer
}
void draw() {
image(pg, 0, 0); //draw the buffer
}
int x1,y1,x2,y2; //coordinates of a line
void mouseDragged(){
pg.beginDraw(); //start writing to the buffer
pg.background(102);
pg.stroke(255);
for(int i=0; i<1000; i++){ //draw 1000 lines
x1 = int(random(dim));
y1 = int(random(dim));
x2 = int(random(dim));
y2 = int(random(dim));
pg.line(x1, y1, x2, y2);
}
pg.endDraw(); //end writing to the buffer
}
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.