Processing=102=swarmattractor

Page 1

A102

SWARM [Sliders & Attractors]


Plethora Swarm Agent Based Library


Try to play with the

SLIDERS


***Open the file we built in 101

Use the GUI we have to set up the “scale” Slider for “Cohesion” “Alignment” & “Separation”& “MaxSpeed” At this point, you should all know how to do it.


In the void draw

In the initGUI()

float coh = 1.5; float ali = 0.5; float sep = 1.5

void initGUI(){

void draw(){ background(0); buildBox(DIMX, DIMY,DIMZ); if (controlP5.isMouseOver()) { cam.setActive(false); } else { cam.setActive(true); }

controlP5 = new ControlP5(this); controlP5.addToggle("showSwarm",showSwarm,20,50,14,14).setLabel("show Swarm"); ………………. ………… controlP5.addSlider("coh", 0, 3, 20,20,100,10).setLabel("cohesion"); controlP5.addSlider("ali", 0, 3, 200,20,100,10).setLabel("alignment"); controlP5.addSlider("sep", 0, 3, 380,20,100,10).setLabel("separation"); controlP5.addSlider("maxSpeed", 0, 10, 20,65,100,10).setLabel("maxSpeed"); …………… ………… ……..} gui(); }

for(Ple_Agent pa : boids){

pa.flock(boids, 80,40,30, coh,ali,sep); pa.setMaxspeed(maxSpeed); pa.wrapSpace(DIMZ/2, DIMY/2, DIMZ/2); …. .. .. …………….. .. …………. ……… ………………. ………… …………… ………… ……..} gui(); }



Try to play with the

Attractors Base on the Swarm file


Arrive(target); Seek(target,force);


In the void draw void draw(){ background(205); buildBox(DIMX, DIMY,DIMZ); if (controlP5.isMouseOver()) { cam.setActive(false); } else { cam.setActive(true); } for(Ple_Agent pa : boids){ pa.flock(boids, 80,40,30, coh,ali,sep); pa.setMaxspeed(maxSpeed); pa.wrapSpace(DIMZ/2, DIMY/2, DIMZ/2);

Vec3D target = new Vec3D(50,100,60); pa.arrive(target); } gui(); }



Let’s play some GAME


Using the Slider to define the attractor point void draw(){

background(205); buildBox(DIMX, DIMY,DIMZ); if (controlP5.window(this).isMouseOver()) { cam.setActive(false); } else { cam.setActive(true); } for(Ple_Agent pa : boids){ pa.flock(boids, 80,40,30, coh,ali,sep); pa.setMaxspeed(maxSpeed); pa.wrapSpace(DIMZ/2, DIMY/2, DIMZ/2);

Vec3D target = new Vec3D(aX,aY,aZ); pa.arrive(target); stroke(10); point(aX,aY,aZ); } gui(); }

void initGUI() { controlP5 = new ControlP5(this); controlP5.addSlider("coh", 0, 3, 20,20,100,10).setLabel("cohesion"); controlP5.addSlider("ali", 0, 3, 20,35,100,10).setLabel("alignment"); controlP5.addSlider("sep", 0, 3, 20,50,100,10).setLabel("separation"); controlP5.addSlider("maxSpeed", 0, 10, 20,65,100,10).setLabel("maxSpeed");

controlP5.addSlider("aX", -300, 300, 200,20,100,10).setLabel("att X"); controlP5.addSlider("aY", -300, 300, 340,20,100,10).setLabel("att Y"); controlP5.addSlider("aZ", -300, 300, 480,20,100,10).setLabel("att Z"); controlP5.addToggle("showSwarm",showSwarm,20,80,14,14).setLabel("show Swarm"); controlP5.addToggle("showTails",showTails,20,110,14,14).setLabel("show Tails"); controlP5.addToggle("showTrails",showTrails,20,140,14,14).setLabel("show Trails"); controlP5.addToggle("showLinesBetween",showLinesBetween,20,170,14,14).setLab el("show LinesBetween"); controlP5.addToggle("run",run,20,200,20,20).setLabel("RUN!!!"); }



Change the “Arrive();” to “Seek();”


void draw(){ if (controlP5.window(this).isMouseOver()) { cam.setActive(false); } else { cam.setActive(true); }

background(235); noFill(); stroke(0,90); strokeWeight(1); box(DIMX, DIMY, DIMZ); for(Ple_Agent pa : boids){ pa.flock(boids, 80,40,30, coh,ali,sep); pa.setMaxspeed(maxSpeed); pa.wrapSpace(DIMZ/2, DIMY/2, DIMZ/2);

Vec3D target = new Vec3D(aX,aY,aZ); The number can be “-” pa.seek(target,5); stroke(10); point(aX,aY,aZ); } gui(); }


It’s your turn 1. to Add a SLIDER For the FORCE 2. to Add a TOGGLE For Turn On&Off the Attraction


void draw(){

float factor = 2 boolean Attract = false; if (controlP5.window(this).isMouseOver()) { cam.setActive(false); } else { cam.setActive(true); } background(235); noFill(); stroke(0,90); strokeWeight(1); box(DIMX, DIMY, DIMZ); for(Ple_Agent pa : boids){ pa.flock(boids, 80,40,30, coh,ali,sep); pa.setMaxspeed(maxSpeed); pa.wrapSpace(DIMZ/2, DIMY/2, DIMZ/2);

Vec3D target = new Vec3D(aX,aY,aZ); if(attract){ pa.seek(target,factor); } stroke(10); point(aX,aY,aZ); } gui(); }

void initGUI() { controlP5 = new ControlP5(this); controlP5.addSlider("coh", 0, 3, 20,20,100,10).setLabel("cohesion"); controlP5.addSlider("ali", 0, 3, 20,35,100,10).setLabel("alignment"); controlP5.addSlider("sep", 0, 3, 20,50,100,10).setLabel("separation"); controlP5.addSlider("maxSpeed", 0, 10, 20,65,100,10).setLabel("maxSpeed");

controlP5.addSlider("aX", -300, 300, 200,20,100,10).setLabel("att X"); controlP5.addSlider("aY", -300, 300, 340,20,100,10).setLabel("att Y"); controlP5.addSlider("aZ", -300, 300, 480,20,100,10).setLabel("att Z"); controlP5.addSlider(“factor”,-5,5,200,50,50,10 ).setLabel(“Attract!!”); controlP5.addToggle(“Attract",Attract,20,240,20,20).setLabel(“Attract"); controlP5.addToggle("showSwarm",showSwarm,20,80,14,14).setLabel("show Swarm"); controlP5.addToggle("showTails",showTails,20,110,14,14).setLabel("show Tails"); controlP5.addToggle("showTrails",showTrails,20,140,14,14).setLabel("show Trails"); controlP5.addToggle("showLinesBetween",showLinesBetween,20,170,14,14).setLabel( "show LinesBetween"); controlP5.addToggle("run",run,20,200,20,20).setLabel("RUN!!!");

}



Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.