xxxxxxxxxx
void setup(){
size( 600, 600 );
background( 255 );
noStroke();
// We declare these variables outside the looping scope
// so that they are remembered while looping.
int circleCount = 32;
float circleRadius = 10;
float dotSize = 0;
// Repeat 'circleCount' times while increasing i staring at 0.
for( int i=0; i<circleCount; i++ ){
// Increase the circle radius by half the dot previous size.
circleRadius += dotSize * 0.5;
// Compute a new dot size for the current circle.
dotSize = random( 5, 50 );
// Also increase the circle radius by the current dot size. This way circles will layer like onion rings.
circleRadius += dotSize * 0.5;
// Compute how many dots of 'dotSize' we need to fill the circle.
float circumference = circleRadius * TWO_PI;
int dotCount = round( circumference / dotSize );
// Apply a semi random color.
int red = round( random( 20, 200 ) );
int blue = round( random( 100, 200 ) );
fill( red, 130, blue );
// Call the draw function passing the arguments to it.
drawCircle( dotCount, circleRadius, dotSize );
}
saveFrame( "CirclesMyName.jpg" );
}
void drawCircle( int dotCount, float circleRadius, float dotSize ){
// Repeat 'dotCount' times while increasing i starting at 0.
for( int i=0; i<dotCount; i++ ){
// Compute circle angle going from 0 to two pi while i goes from o to 'dotCount'.
float circleAngle = map( i, 0, dotCount, 0, TWO_PI );
// Compute point on the unit circle and scale it to radius.
float circleOffX = cos( circleAngle ) * circleRadius;
float circleOffY = sin( circleAngle ) * circleRadius;
// Compute position at center of canvas plus the circle offset.
float x = width/2 + circleOffX;
float y = height/2 + circleOffY;
// Draw!
ellipse( x, y, dotSize, dotSize);
}
}