public class Bling{ Vector3D loc; Vector3D vel; Vector3D acc; float ballSize = 8f; float friction = .85f; int type; int r = 127; int g = 127; int b = 127; //The Constructor (called when the object is first created) Bling(Vector3D l, Vector3D v, Vector3D a, int _type) { loc = l.copy(); vel = v.copy(); acc = a.copy(); type = _type; if(type == 0) { r = 200; g = 25; b = 25; } else { r = 50; g = 50; b = 200; } } //main function to operate object) void go() { update(); borders(); //loc.x = loc.y = loc.z = 0f; render(); } //function to update location void update() { vel.mult(friction); vel.add(acc); vel.limit(15f); loc.add(vel); } void borders() { /* int maxExtent = 158; //if (loc.x > width ) loc.x = 0; //if (loc.x < 0 ) loc.x = width; if (loc.x > maxExtent || loc.x < -maxExtent) { vel.x = vel.x * -1; if(loc.x > 0) { loc.x = maxExtent-(loc.x-maxExtent); } else { loc.x = -maxExtent - (loc.x + maxExtent); } //acc.x = acc.x * -1; } //if (loc.y > height) loc.y = 0; //if (loc.x < 0 ) loc.y = height; if (loc.y > maxExtent || loc.y < -maxExtent) { vel.y = vel.y * -1; if(loc.y > 0) { loc.y = maxExtent-(loc.y-maxExtent); } else { loc.y = -maxExtent - (loc.y + maxExtent); } //acc.y = acc.y * -1; } if (loc.z > maxExtent || loc.z < -maxExtent) { vel.z = vel.z * -1; if(loc.z > 0) { loc.z = maxExtent-(loc.z-maxExtent); } else { loc.z = -maxExtent - (loc.z + maxExtent); } //acc.z = acc.z * -1; } */ if(loc.magnitude() > 316f-ballSize) { float mag = loc.magnitude(); loc.normalize(); loc.mult((316-ballSize)-(mag-(316-ballSize))); vel.mult(-1f); } } void setColor(int r_, int g_, int b_){ r = r_; g = g_; b = b_; } //function to display void render() { pushMatrix(); //rectMode(CENTER); noStroke(); fill(r,g,b); translate(loc.x,loc.y,loc.z); sphere(ballSize); //ellipse(loc.x,loc.y,16,16); if (showVectors) { drawVector(vel,loc,10.0f); } popMatrix(); } }