Ass­e­s­s­m­e­n­t 1

by Giselle Gray
  • Show Sketch
/** @peep sketchcode */
 
//please read comments on assignment submission for background research & links! :) 
// Global variables, accessible from all functions
int NUMBER_RINGS = 14;
int NUMBER_CIRCLES = 100;
int CIRCLE_RADIUS_SMALL = 8;
int CIRCLE_RADIUS_MED = 15;
int CIRCLE_RADIUS_LARGE = 20;
 
 
void setup() {
  // Set size and color of canvas
  size(400, 400);
  background(239, 0, 255);
 
  // Move all elements to the center of canvas
  translate(width/2, height/2);
  noStroke();
 
  // Loop through all circles
  for (int i = 1; i < NUMBER_CIRCLES; i++) {
    // Creates a smoother transition
    if (i == 1) {
      // First iteraton created larger circles close to middle
      drawRingOfCircles(15, i * CIRCLE_RADIUS_LARGE);
    } else if (i == 2) {
      // Second iteration creates medium circles further from middle
      drawRingOfCircles(35 + random(5), i * CIRCLE_RADIUS_MED);
    } else {
      // Subsequent iterations increase radius and circle size based on number of iterations
      // Radius in multiples of 27 with slight randomisation
      drawRingOfCircles((i-1) * 27 + random(10), i * CIRCLE_RADIUS_SMALL);
    }
  }
}
 
/* Draws the ring of circles by creating circles of slight variation in size 
and position, each one being placed slightly to the right of the center
and then rotated around before placing the next.*/
void drawRingOfCircles(float radius, float size) {
  // Choosing random base value for ring colour
  float ringColour = random(255);
  for (int i = 0; i < NUMBER_CIRCLES; i++) {
    // Small variation for each circle in the ring
    float circleColour = ringColour + random(20);
 
    // Set fill colour of the circle
    // colour code inspired from http://www.openprocessing.org/sketch/154952
    fill(128+127*cos(circleColour%128*TWO_PI/128),
      128+127*cos(circleColour%128*TWO_PI/128+TWO_PI/3),
      128+127*cos(circleColour%128*TWO_PI/128+2*TWO_PI/3));
 
    // Draw circle with randomised position (calculated from the center of the canvas)
    ellipse(radius + random(10), 0, size, size);
 
    // Rotate canvas to place circle in a ring-like fashion
    rotate(random(360)*(PI/180));
  }
}

Comments

    Sarah Shultz a few years ago

    this is really fun to click through each iteration, really well done :)