/** Copyright 2007 by Joshua Thorp */ float l = 77; float w = 16; color c1 = color(150); color c2 = color(255,153,0); //color(200); color c3 = color(100); color bc = color(255); boolean drawfill = true; void setup() { size(400,600); background(255); setDim(); } void setDim() { w = int(max(random((width-20)/6),3)); l = int(max(random(height-5*w),10)); println("L: "+l+ " W: " + w); } void keyPressed() { switch(key) { case 'f': drawfill = !drawfill; break; case CODED: switch(keyCode) { case UP: l += 1; break; case DOWN: l -= 1; break; case LEFT: w -= 1; break; case RIGHT: w += 1; break; } break; default: setDim(); } loop(); } void lines() { stroke(c1); float x0 = width/2, y0 = height/2; line(x0-w/2,y0-l/2,x0-w/2,y0+l/2); line(x0+w/2,y0+l/2,x0+w/2,y0-l/2); line(x0-w/2,y0-l/2-w,x0-w/2,y0-l/2); line(x0+w/2,y0-l/2,x0+w/2+w,y0-l/2-w); line(x0+w/2,y0-l/2,x0-w/2,y0-l/2); line(x0-w/2,y0-l/2-w,x0+w/2+w,y0-l/2-w); line(x0+w/2,y0+l/2+w,x0+w/2,y0+l/2); line(x0+w/2,y0+l/2,x0-w/2,y0+l/2); line(x0-w/2,y0+l/2,x0-w/2-w,y0+l/2+w); line(x0+w/2,y0+l/2+w,x0-w/2-w,y0+l/2+w); stroke(c2); line(x0-w/2,y0+l/2,x0-w/2-w,y0+l/2+w); line(x0-w/2-w,y0+l/2+w,x0-w/2-w,y0-l/2-2*w); line(x0+w/2+w,y0-l/2-w,x0+w/2+w,y0+l/2+2*w); line(x0-w/2,y0+l/2,x0-w/2,y0-l/2-w); line(x0-w/2-w,y0-l/2-2*w,x0+w/2+2*w,y0-l/2-2*w); line(x0+w/2+2*w,y0-l/2-2*w,x0+w/2+2*w,y0+l/2+w); line(x0+w/2+2*w,y0+l/2+w,x0+w/2+w,y0+l/2+2*w); line(x0-w/2,y0-l/2-w,x0+w/2+w,y0-l/2-w); stroke(c3); line(x0+w/2,y0+l/2+w,x0-w/2-w,y0+l/2+w); line(x0+w/2,y0-l/2,x0+w/2,y0+l/2+w); line(x0+w/2+w,y0+l/2+2*w,x0-w/2-2*w,y0+l/2+2*w); line(x0-w/2-2*w,y0+l/2+2*w,x0-w/2-2*w,y0-l/2-w); line(x0-w/2-2*w,y0-l/2-w,x0-w/2-w,y0-l/2-2*w); line(x0-w/2-w,y0-l/2-2*w,x0-w/2-w,y0+l/2+w); line(x0+w/2,y0-l/2,x0+w/2+w,y0-l/2-w); line(x0+w/2+w,y0-l/2-w,x0+w/2+w,y0+l/2+2*w); } void filledFigure() { float x0 = width/2, y0 = height/2; noStroke(); fill(c1); beginShape(); vertex(x0-w/2,y0-l/2-w); vertex(x0-w/2,y0-l/2); vertex(x0+w/2,y0-l/2); vertex(x0+w/2+w,y0-l/2-w); vertex(x0-w/2,y0-l/2-w); endShape(); beginShape(); vertex(x0+w/2,y0+l/2+w); vertex(x0+w/2,y0+l/2); vertex(x0-w/2,y0+l/2); vertex(x0-w/2-w,y0+l/2+w); vertex(x0+w/2,y0+l/2+w); endShape(); fill(c2); beginShape(); vertex(x0-w/2,y0+l/2); vertex(x0-w/2-w,y0+l/2+w); vertex(x0-w/2-w,y0-l/2-2*w); vertex(x0+w/2+2*w,y0-l/2-2*w); vertex(x0+w/2+2*w,y0+l/2+w); vertex(x0+w/2+w,y0+l/2+2*w); vertex(x0+w/2+w,y0-l/2-w); vertex(x0-w/2,y0-l/2-w); vertex(x0-w/2,y0+l/2); endShape(); fill(c3); beginShape(); vertex(x0+w/2,y0-l/2); vertex(x0+w/2+w,y0-l/2-w); vertex(x0+w/2+w,y0+l/2+2*w); vertex(x0-w/2-2*w,y0+l/2+2*w); vertex(x0-w/2-2*w,y0-l/2-w); vertex(x0-w/2-w,y0-l/2-2*w); vertex(x0-w/2-w,y0+l/2+w); vertex(x0+w/2,y0+l/2+w); vertex(x0+w/2,y0-l/2); endShape(); } void draw() { background(bc); if (drawfill) filledFigure(); else lines(); noLoop(); }