Sunday, May 31, 2009
Changing shapes
// Reload the page to see the picture change.
// Inspired by http://levitated.net/daily/lev9block.html
int whichShape;
int whichCentreShape;
int oneOfFour;
void setup(){
size(103,103);
//scale(0.5);
background(0);
//line(34,0,34,102);
//line(68,0,68,102);
//line(0,34,102,34);
//line(0,68,102,68);
oneOfFour = int(random(0,4));
whichCentreShape = int(random(0,3));
//original
//triangle(102/2-102/2,34-102/2,34-102/2,68-102/2,68-102/2,68-102/2);
////////////////////////////////////////////////////////////////
// centre
////////////////////////////////////////////////////////////////
//centre shape
pushMatrix();
translate(102/2,102/2);
drawCentreShape();
popMatrix();
////////////////////////////////////////////////////////////////
// top, bottom, left, right
////////////////////////////////////////////////////////////////
whichShape = int(random(0,5));
//middle top
pushMatrix();
translate(102/2,34/2);
rotate(PI/2 + PI/2*oneOfFour);
drawShape();
popMatrix();
//middle right
pushMatrix();
translate(68+34/2,102/2);
rotate(PI+ PI/2*oneOfFour);
drawShape();
popMatrix();
//middle bottom
pushMatrix();
translate(102/2,68+34/2);
rotate(PI+PI/2+ PI/2*oneOfFour);
drawShape();
popMatrix();
//middle left
pushMatrix();
translate(34/2,102/2);
rotate(0+ PI/2*oneOfFour);
drawShape();
popMatrix();
////////////////////////////////////////////////////////////////
// corners
////////////////////////////////////////////////////////////////
oneOfFour = int(random(0,4));
whichShape = int(random(0,3));
//top left
pushMatrix();
translate(34/2,34/2);
rotate(PI/2 + PI/2*oneOfFour);
drawShape();
popMatrix();
//top right
pushMatrix();
translate(68+34/2,34/2);
rotate(PI+ PI/2*oneOfFour);
drawShape();
popMatrix();
//bottom right
pushMatrix();
translate(68+34/2,68+34/2);
rotate(PI+PI/2+ PI/2*oneOfFour);
drawShape();
popMatrix();
//bottom left
pushMatrix();
translate(34/2,68+34/2);
rotate(0+ PI/2*oneOfFour);
drawShape();
popMatrix();
}
void drawShape(){
//rect(0-34/2,0-34/2,34,34);
smooth();
//noStroke();
if (whichShape==0) rect(0-20/2,0-20/2,20,20);
if (whichShape==1) rect(0-34/2,0-34/2,34,34);
if (whichShape==2) ellipse(0,0,30,30);
if (whichShape==3) triangle(102/2-102/2,34-102/2,34-102/2,68-102/2,68-102/2,68-102/2);
if (whichShape==4) triangle(0-34/2,0-34/2,-34/2,34-34/2,34-34/2,0-34/2);
}
void drawCentreShape(){
whichShape = whichCentreShape % 3;
drawShape();
}
// Inspired by http://levitated.net/daily/lev9block.html
int whichShape;
int whichCentreShape;
int oneOfFour;
void setup(){
size(103,103);
//scale(0.5);
background(0);
//line(34,0,34,102);
//line(68,0,68,102);
//line(0,34,102,34);
//line(0,68,102,68);
oneOfFour = int(random(0,4));
whichCentreShape = int(random(0,3));
//original
//triangle(102/2-102/2,34-102/2,34-102/2,68-102/2,68-102/2,68-102/2);
////////////////////////////////////////////////////////////////
// centre
////////////////////////////////////////////////////////////////
//centre shape
pushMatrix();
translate(102/2,102/2);
drawCentreShape();
popMatrix();
////////////////////////////////////////////////////////////////
// top, bottom, left, right
////////////////////////////////////////////////////////////////
whichShape = int(random(0,5));
//middle top
pushMatrix();
translate(102/2,34/2);
rotate(PI/2 + PI/2*oneOfFour);
drawShape();
popMatrix();
//middle right
pushMatrix();
translate(68+34/2,102/2);
rotate(PI+ PI/2*oneOfFour);
drawShape();
popMatrix();
//middle bottom
pushMatrix();
translate(102/2,68+34/2);
rotate(PI+PI/2+ PI/2*oneOfFour);
drawShape();
popMatrix();
//middle left
pushMatrix();
translate(34/2,102/2);
rotate(0+ PI/2*oneOfFour);
drawShape();
popMatrix();
////////////////////////////////////////////////////////////////
// corners
////////////////////////////////////////////////////////////////
oneOfFour = int(random(0,4));
whichShape = int(random(0,3));
//top left
pushMatrix();
translate(34/2,34/2);
rotate(PI/2 + PI/2*oneOfFour);
drawShape();
popMatrix();
//top right
pushMatrix();
translate(68+34/2,34/2);
rotate(PI+ PI/2*oneOfFour);
drawShape();
popMatrix();
//bottom right
pushMatrix();
translate(68+34/2,68+34/2);
rotate(PI+PI/2+ PI/2*oneOfFour);
drawShape();
popMatrix();
//bottom left
pushMatrix();
translate(34/2,68+34/2);
rotate(0+ PI/2*oneOfFour);
drawShape();
popMatrix();
}
void drawShape(){
//rect(0-34/2,0-34/2,34,34);
smooth();
//noStroke();
if (whichShape==0) rect(0-20/2,0-20/2,20,20);
if (whichShape==1) rect(0-34/2,0-34/2,34,34);
if (whichShape==2) ellipse(0,0,30,30);
if (whichShape==3) triangle(102/2-102/2,34-102/2,34-102/2,68-102/2,68-102/2,68-102/2);
if (whichShape==4) triangle(0-34/2,0-34/2,-34/2,34-34/2,34-34/2,0-34/2);
}
void drawCentreShape(){
whichShape = whichCentreShape % 3;
drawShape();
}
info
submitted by: davidedcReload the page to see the picture change. Inspired by http://levitated.net/daily/lev9block.html
comments

sign in to Add a comment: