Monday 1 December 2008

drawCircles


I started working on the program for chunk 16.
Functions to change colour randomly, draw a circle and draw a set of circles were written.
I have run into an unexpected problem:
When drawing the circles I wanted a slight pause between each iteration.
This would acheive a hypnotic affect as each circle changes colour.
Instead the circles are all changing colour at the same time.
I even tried using threads but this was unsuccessful too.
I tried redrawing the circles and found what Greenberg terms as a "happy accident". By changing one of the diameters an interesting variation on plain circles was discovered.
I also played with changing the stroke weight but again there is no pause between each change.
I think I will need to read a little more of the book to find a solution to this problem.


By using the 'pre' tag, it is easy to cut and paste the code from processing into the blog, but lesser/greater than needs to be changed to '& noSpaces lt/&noSpaces gt' and some spurious errors must be edited.





// define Global variable values
//set centre for circles
int sizeWindow=300;
int max=1000;
int centre=sizeWindow/2;
int xpos = centre;
int ypos = centre;
int maxDiameter=sizeWindow;
int interval=30;

// set the sketch window size and background
void setup(){
size(sizeWindow, sizeWindow);
background(0);
stroke(204, 102, 0);//colour red
noFill();
frameRate(.3);
draw();}

void draw(){
changeColour();
drawCircles(interval);}

void changeColour(){
stroke(random(255),random(255),random(255));
}

void drawCircles(int gap){
for(int n=0;n< maxdiameter;n+=gap){
drawCircle(n);}}

//create ellipse
void drawCircle(int diameter){
sw="1;
// while(sw<=10){
// strokeWeight(sw);
ellipse(xpos, ypos, diameter, diameter);
ellipse(xpos, ypos, diameter-interval, diameter);
ellipse(xpos, ypos, diameter, diameter-interval);
ellipse(xpos, ypos, diameter, diameter);
// sw+=1; }
}


3 comments:

  1. You could try using a code2html program to convert your code before publishing it. I use jEdit as an external editor which has a code2html plugin. See my blog for more info.

    ReplyDelete
  2. PS: I should have specified October poat.

    ReplyDelete
  3. Thanks Martin!
    I will have a look for it as it sounds ideal.

    ReplyDelete