Friday 5 December 2008

chunk 16 source code


I tried adding lines and triangles to the application but it was not an improvement. If the lines occurred on the last frame then it just spoiled the patterns underneath. Without using trigonometry to calculate the points on the outer circle the triangles just looked like scribbles. This would also have meant more lines of code.
The code as it stands comes to 101 lines. This is after cramping up some code so it fits on one line e.g.
if(condition){statement}
instead of:
if(condition){
statement}
When I write code, I tend not to spread out brackets, so they line up. I try to ensure that statements line up properly, in blocks and if there is a problem with loops, it is easy to line up the brackets to trace errors. This is just my personal preference and the code could be ammended for other formatting tastes...
Here is the uncommented source code as it stands at the moment. It may be changed a little over the coming weeks but I dont see there being any major changes. My next post will contain the commented code and then I will begin the text for chunk 16.


int sizeWindow=600;
int centre=sizeWindow/2;
int xpos = centre;
int ypos = centre;
int interval=30;
void setup(){
size(sizeWindow, sizeWindow);
background(0);
stroke(204, 102, 0);//colour red
noFill();
frameRate(.2);
draw();}
void draw(){
int count=0;
int design=0;
for(count=0;count < round(random(10,width));count++){
if(count%100==0)background(0);
println(design);
interval=round(random(5,70));
changeColour();
design=round(random(1,9));
switch(design){
case 1:
while(interval < width){
drawCircle2(interval-round(random(40,width/2)));//500/400
interval+=round(random(3,70)); }
break;
case 2:drawCircles(round(random(20,round(random(1,50)))));
break;
case 3:
strokeWeight(getSW());
while(interval < width){
drawCircle2(interval-round(random(1,width/2)));
interval+=round(random(1,width/2));}
break;
case 4:
strokeWeight(getSW());
while(interval < width){
drawCircle2(interval-round(random(2,width/4)));
interval+=round(random(1,30));}
break;
case 5:
case 6:
while(interval < width){
fill(random(255),random(255),random(255));
drawCircle2(interval);
interval+=20;}
noFill();
break;
case 7:
while(interval < width){
drawCircle2(interval);
interval+=random(1,40);}
break;
case 8:
changeColour();
while(interval < width){
drawSquares(interval-(width+round(random(1,10))));
interval+=round(random(1,50));}
break;
case 9:
while(interval < width){
changeColour();
drawSquares(interval-round(random(1,width/2)));
interval+=20;}
changeColour();
drawSquares(interval-width+(round(random(1,10))));
break;}}}
void changeColour(){
stroke(random(255),random(255),random(255));}
void drawCircles(int gap){
for(int n=0;n < sizeWindow;n+=gap){ drawCircle(n);}}
void drawCircle2(int diameter){
ellipse(xpos, ypos, diameter-random(5,diameter), diameter-random(5,diameter));}
void drawCircle3(int diameter){
ellipse(xpos, ypos, diameter-interval, diameter+interval);}
void drawSquares(int diameter){
int r= round(random(1,4));
if(r==1){rectMode(CENTER);}
else if(r==2){rectMode(RADIUS);}
else if(r==3){changeColour();}
else{stroke(round(random(255)),round(random(255)),round(random(255)),round random(255)));}
rect(xpos,ypos,diameter,diameter);}
int getSW(){
int fc=round(random(frameRate*500)/5);
switch(fc){
case 1:return 1;
case 2:return 2;
case 3:return 3;
case 4:return 4;
case 5:return 5;
case 6:return 6;
case 7:return 7;
case 8:return 8;
case 9:return 9;
default :return round(random(1,4));}}
void drawCircle(int diameter){
ellipse(xpos, ypos, diameter, diameter);
ellipse(xpos, ypos, diameter-interval, diameter);
ellipse(xpos, ypos, diameter, diameter-interval);
ellipse(xpos, ypos, diameter, diameter);}

1 comment:

  1. I have changed the main for loop to use a random number between 2 and 50, as I cant see there being much reason to use more patterns than this in one picture!
    Dont know how I missed that!

    ReplyDelete