//this sketch introduces classes //the class allows us to have variables that persist and are seperate for each object we create, //in this case the orbs. because of this they can animate their scaling over time int numOrbs = 400; //here we state that orbs will be a new type of Makeorbs, an array numOrbs in size (400) Makeorbs[] orbs = new Makeorbs[numOrbs]; int currentOrb = 0; void setup() { size(400, 400); smooth(); background(255); frameRate(30); //noCursor removes the cursor arrow noCursor(); //setup some variables for use as we make our orbs int x = 10; int y = 10; float scaler = 1; float colR = 0, colG = 0, colB = 0; //this for loop makes our 400 orb instances and sends with them a position, scale, and random color for (int i = 0; i < numOrbs; i++){ orbs[i] = new Makeorbs(x, y, scaler, colR, colG, colB); x += 20; colR = random(255); colG = random(255); colB = random(255); if (x > 400) { x = 10; y += 20; } } } void draw() { fill(255); rect(0, 0, width, height); //this for loop goes thru each orb instance and updates the scale accoring to the animation rules and then displays the orb for (int i = 0; i < numOrbs; i++) { orbs[i].update(mouseX, mouseY); orbs[i].display(); } } //here is our custom class class Makeorbs { int Ox, Oy; float scaler, R, G, B ; Makeorbs(int x, int y, float Oscale, float OR, float OG, float OB) { Ox = x; Oy = y; scaler = Oscale; R = OR; G = OG; B = OB; } void update(int mx, int my) { if(dist(mx, my, Ox, Oy) < 15 && scaler < 100) { //test for rollover of each orb scaler += 5; //make it bigger if hit } else if(scaler > 1) { scaler -= .1; //make it shrink if it is not hit } else { scaler = 1; } } void display() { //display the finished orb fill(R, G, B); ellipse(Ox, Oy, scaler, scaler); } }