import toxi.geom.*; class Worm { ///////////////////////////////////////////////////////////////////////////////////// //Class Variables-------------------------------------------------------------------- ///////////////////////////////////////////////////////////////////////////////////// float rad = 15; //Radius of the ellipse float noiseScale = 75;// random(0.02, 10.02); //Noise ScaleValue float noiseStrength = 8.5; ArrayList<Vec3D>wormTrail; Vec3D headPos = new Vec3D (0, 0, 0); //Create a new vector Vec3D newVecloc = new Vec3D (0, 0, 0); //Create a new vector //Vec3D speedVec = new Vec3D (random(10, 50), 0, 0); //Create self.vec Vec3D speedVec = new Vec3D (2, 0, 0); //Create self.vec ///////////////////////////////////////////////////////////////////////////////////// //Class Constructors----------------------------------------------------------------- ///////////////////////////////////////////////////////////////////////////////////// Worm(Vec3D _newVecloc) { //Initialize wormTrail = new ArrayList<Vec3D>(); newVecloc = _newVecloc; headPos = _newVecloc; } ///////////////////////////////////////////////////////////////////////////////////// //Class Primary Methods (Update)----------------------------------------------------- ///////////////////////////////////////////////////////////////////////////////////// void update() { move(); drawTrail(); render(); } ///////////////////////////////////////////////////////////////////////////////////// ////Class Secondary Methods---------------------------------------------------------- ///////////////////////////////////////////////////////////////////////////////////// void move() { float noiseVal = noise(newVecloc.x/noiseScale,newVecloc.y/noiseScale)*noiseStrength; //NOISE IN THE X VALUE FOR THE Y POSITION float angle = noiseVal;//*TWO_PI; //Vec3D dir = speedVec.rotateAroundAxis(new Vec3D(0, 0, 1), angle); Vec3D dir = new Vec3D(cos(angle),sin(angle),0); dir.scaleSelf(speedVec.magnitude()); //angle = noise(newVecloc.x/noiseScale,newVecloc.y/noiseScale) * noiseStrength; newVecloc.addSelf(dir); //use toxic lib vec library to add vector to current location headPos = new Vec3D(newVecloc.x, newVecloc.y, 0); //WORM HEAD POSITION wormTrail.add(new Vec3D(newVecloc.x, newVecloc.y, 0)); //TRAIL POSITION WITH NOISE INCLUDED } void render() { stroke(255); strokeWeight(5); point(headPos.x, headPos.y); //ADD PIXEL ON WORM HEAD } void drawTrail() { noFill(); strokeWeight(1); stroke(125,255,0,150); beginShape(); for (int i = 0; i<wormTrail.size (); i++) { Vec3D pos = new Vec3D (wormTrail.get(i)); if (i == 0 || i == wormTrail.size()-1) { curveVertex(pos.x, pos.y); } curveVertex(pos.x, pos.y); } endShape(); //ArrayList<Vec3D>wormTrail; //wormTrail.clear(); } } Update