Monday 8 December 2008

Revised Code


  1:int sizeWindow=600;
2:int centre=sizeWindow/2;
3:int xpos = centre;
4:int ypos = centre;
5:int patternsPerPicture=round(random(2,50));
6:
7:int interval=30;
8:int count;
9:void setup(){
10: size(sizeWindow, sizeWindow);
11: background(0);
12: stroke(204, 102, 0);//colour red
13: noFill();
14: frameRate(.2);
15: draw();}
16:
17:void draw(){
18: count=0;
19: int design=0;
20: background(0);
21: for(count=0;count<patternsPerPicture;count++){
22: strokeWeight(getSW());//set the strokewright to the number returned by the getSW function
23: noFill();
24: interval=round(random(5,70));//increment by interval in while loops
25: changeColour();
26: design=round(random(1,9)); //a random numver for which design to use in the switch
27: switch(design){
28: case 1:
29: repeatShapes(round(random(3,70)),'2');
30: break;
31: case 2:
32: drawCircles(round(random(20,round(random(1,50))))); //call the drawCircles function
33: break;
34: case 3:
35: repeatShapes(round(random(1,width/2)),'2');//use the drawCircle2 function
36: break;
37: case 4:
38: repeatShapes(width-round(random(2,width/4)),'3');
39: break;
40: case 5:
41: doLines();
42: case 6:
43: repeatShapes(interval,'5');
44: break;
45: case 7:
46: repeatShapes(round(random(1,40)),'2');
47: break;
48: case 8:
49: default:
50: repeatShapes(width-round(random(1,width/2)),'4');//draws unfilled squares
51: }}
52: patternsPerPicture=round(random(2,50));}
53:
54:void changeColour(){
55: stroke(random(255),random(255),random(255));
56:}
57:
58:void drawCircles(int gap){
59: for(int n=0;n<round(random(width/2,width));n+=gap){
60: drawCircle(n);}}
61:
62:void drawCircle2(int diameter){
63: ellipse(xpos, ypos, diameter-random(5,diameter), diameter-random(5,diameter)); }
64:
65:void drawCircle3(int diameter){
66: ellipse(xpos, ypos, (diameter*random(5,diameter))/(random(5,diameter)*19), (diameter*random(5,diameter))/(random(5,diameter)*19) );
67:}
68:
69:void drawSquares(int diameter){
70: int r= round(random(1,4));
71: rectMode(RADIUS);
72: if(r==1){
73: noStroke();
74: rectMode(CENTER);}
75: else if(r==2){
76: diameter=diameter/20;}
77: else if(r==3){
78: changeColour();}
79: else{
80: diameter=diameter/20;
81: stroke(round(random(255)),round(random(255)),round(random(255)),round(random(255)));}
82: rect(xpos,ypos,diameter,diameter);}
83:
84:int getSW(){
85: int fc=round(random(frameRate*500)/5);
86: return fc%10;
87: }
88:
89:void repeatShapes(int gap, char c){
90: char shape=c;
91: int interval=gap;
92: while(interval<width){//while intervel is less than the width of the window
93: if(shape=='1')drawCircles(interval);
94: else if(shape=='2'){
95: drawCircle2(interval);
96: }//call function drawCircle2 with a random parameter
97: else if(shape=='3'){
98: drawCircle3(interval);}
99: else if(shape=='4'){
100: int r=round(random(1,5));
101: if(r==1){
102: noStroke();
103: changeColour();
104: fill(random(255),random(255),random(255));}
105: drawSquares(round(interval));}
106: else{
107: int r=round(random(1,5));
108: if(r==1){
109: noStroke();
110: fill(random(255),random(255),random(255));}
111: drawCircle2(interval/4); }
112: interval+=gap;}}
113:
114:void doLines(){
115: strokeWeight(getSW());
116: for(int b=1;b<width;b=b+round(random(1,20))){
117: int down=round(random(width/2));
118: int across=round(random(width/2));
119: line(xpos,ypos,across-b,down-b);
120: line(xpos,ypos,across+b+xpos,down-b);
121: line(xpos,ypos,across-b,width-down+b);
122: line(xpos,ypos,across+b+xpos,width-down+b);}}
123:
124:void drawCircle(int diameter){
125: ellipse(xpos, ypos, diameter-interval, diameter);
126: ellipse(xpos, ypos, diameter, diameter-interval);
127: ellipse(xpos, ypos, diameter, diameter);
128:}

No comments:

Post a Comment