// Flocking // Daniel Shiffman // Male class // Methods for Separation, Cohesion, Alignment added // Click mouse to add Males into the system // Created 2 May 2005 class Male extends Boid { float mass; Male(Vector3D l, float ms, float mf, float mr) { super(l, ms, mf); mass = mr; } void render() { super.render(); // Draw a triangle rotated in the direction of velocity float theta = vel.heading2D() + radians(135); stroke(50,50,200); fill(100,100,255); pushMatrix(); translate(loc.x,loc.y); rotate(theta); beginShape(); vertex(0, 0); vertex(mass, 0); vertex(mass/4, mass/4); vertex(mass, mass); vertex(mass/4, mass/4); vertex(0, mass); vertex(0, 0); endShape(); ellipse(mass*1.1,mass*1.1,mass*1.1,mass*1.1); popMatrix(); } // We accumulate a new acceleration each time based on three rules void flock(ArrayList boids) { super.flock(boids); swt = 100; //sep.mult(25.0f); awt = 0; //ali.mult(4.0f); cwt = 0; //coh.mult(5.0f); Vector3D sep = separate(boids); // Separation Vector3D ali = align(boids); // Alignment Vector3D coh = cohesion(boids); // Cohesion // Arbitrarily weight these forces sep.mult(swt); ali.mult(awt); coh.mult(cwt); // Add the force vectors to acceleration acc.add(sep); acc.add(ali); acc.add(coh); } String getSex(){ super.getSex(); String s = "Male"; return s; } }