Monday, 1 December 2008


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);
stroke(204, 102, 0);//colour red

void draw(){

void changeColour(){

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

//create ellipse
void drawCircle(int diameter){
// 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; }


  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.

  2. PS: I should have specified October poat.

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