> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://studio.sketchpad.cc/sp/pad/view/ro.92BawChCBu9/rev.1098
 * 
 * authors: 
 *   
 *   
 *   
 *   
 *   
 *   
 *   
 *   
 *   
 *   
 *   
 *   
 *   
 *   
 *   
 *   
 *   
 *   
 *   
 *   
 *   
 *   Wally Glutton

 * license (unless otherwise specified): 
 *   creative commons attribution-share alike 3.0 license.
 *   https://creativecommons.org/licenses/by-sa/3.0/ 
 */ 



// A quick coding / translation experiment for Processing practice.
// Based on https://gist.github.com/glucero/6269876
// Which was in turn based on: http://i.imgur.com/GfXcswv.gif
// Click and hold mouse over the image to see how it works.

class Ring {
    int arc, x, y;
    float interval, bulb_diameter, diameter;
    
    Ring(int x, int y, float diameter) {
        this.x = x;
        this.y = y;
        this.diameter = diameter;
        
        bulb_diameter = 3;
        arc = (x + y) / 1;
    }
    
    void rotate(int speed) {
        arc = (arc + speed) % 360;
    }
    
    void draw() {
        noFill();
        if (mousePressed) {
          stroke(50);
          ellipse(x, y, diameter, diameter);
          stroke(0);
        }
        
        float radius = diameter / 2;
        fill(0);
        ellipse(x + cos(radians(arc)) * radius,
                y + sin(radians(arc)) * radius,
                bulb_diameter, bulb_diameter);
    }
}

Ring[] rings;
int interval = 25;
int speed = 5;
int allocated_rings = 0;

void setup() {  // this is run once.   
    
    size(600, 600); 
    frameRate(10);
    stroke(0);
    
    rings = new Ring[width * height];
    int k = 0;
    
    for(int i = 0; i < width + interval; i += interval) {
        for (int j = 0; j < height + interval; j += interval) {
            rings[k] = new Ring(i, j, interval * 1.8);
            k++;
        }
    }
    allocated_rings = k - 1;
} 

void draw() { 
    background(255);
    for(int i = 0; i < allocated_rings; i++) {
        rings[i].rotate(speed);
        rings[i].draw();
    }
}