// create square sprites // edited from shiffman's Thing import noc.*; class Squares { //*using private now to encapsulate data*// private Vector3D loc; private Vector3D vel; private Vector3D acc; private float maxvel; float r; float g; float b; float x; //The Constructor (called when the object is first created) Squares(Vector3D a, Vector3D v, Vector3D l) { acc = a; vel = v; loc = l; maxvel = 8; } /*Add functions to our thing object to access the location, velocity and acceleration from outside the class*/ Vector3D getVel() { return vel.copy(); } Vector3D getAcc() { return acc.copy(); } Vector3D getLoc() { return loc.copy(); } void setLoc(Vector3D v) { loc = v.copy(); } void setVel(Vector3D v) { vel = v.copy(); } void setAcc(Vector3D v) { acc = v.copy(); } //main function to operate object) void go() { update(); borders(); render(); } //function to update location void update() { vel.add(acc); loc.add(vel); //limit speed to max if (vel.magnitude() > maxvel) { vel.normalize(); vel.mult(maxvel); } } void borders() { if ((loc.y > height) || (loc.y < 0)) { vel.y *= -1; } if ((loc.x < 0) || (loc.x > width)) { vel.x *= -1; } } //function to display void render() { rectMode(CENTER); /* //random r = random(255); g = random(255); b = random(255); */ //gaussian //get gaussian random Random generator = new Random(); //following code adapted from DanShiffman's RandomGenerator code //get 3 gaussian random numbers w/ mean of 0 and standard deviation of 1.0 float r = (float) generator.nextGaussian(); float g = (float) generator.nextGaussian(); float b = (float) generator.nextGaussian(); //define standard deviation and mean float sd =100; float mean = 100; //scale by standard deviation and mean //also constrain to between (0,255) since we are dealing with color r = constrain((r * sd) + mean,0,255); //repeat for g & b sd = 100; mean = 200; g = constrain((g * sd) + mean,0,255); sd = 100; mean = 150; b = constrain((b * sd) + mean,0,255); stroke(r, g, b); strokeWeight(3); x = random(15); rect(loc.x,loc.y,x,x); } }