Hello there, i have a code here that i am making for my first installation. What i am attempting to do is make a realtime simulation of a system growing. I have this code so far but it is just static. Is there any way to adapt this code so it grows in realtime?
i would love anyone that could help me with this
p.s i would ideally like it to grow with in a sphere to, but thats for later
thanks
sean
import toxi.geom.*;
import peasy.*;
PeasyCam cam;
branch arm;
ArrayList <branch> allArms;
void setup (){
size (600,600, P3D);
smooth();
allArms = new ArrayList <branch>();
cam = new PeasyCam(this, 100);
Vec3D v = new Vec3D (0,0,0);
Vec3D inivel = new Vec3D (100,0,0);
arm = new branch(v, inivel, 5,"A");
allArms. add(arm);
}
void draw() {
background(0);
noFill();
stroke(80);
box(600);
for (branch b: allArms){
b.run();
}
}
class branch {
Vec3D loc;
Vec3D oriLoc;
Vec3D vel;
int generations;
String type;
branch(Vec3D _loc, Vec3D _vel, int _generations, String _type){
loc =_loc;
oriLoc = loc.copy();
vel = _vel;
generations = _generations;
type= _type;
updateDir();
updateLoc();
spawn();
}
void run (){
Display();
}
void spawn(){
if (generations > 0) {
Vec3D v = loc. copy();
Vec3D inivel = vel. copy();
branch newArm = new branch(v, inivel,generations -1,"A");
allArms. add(newArm);
Vec3D v2 = loc. copy();
Vec3D inivel2 = vel. copy();
branch newArm2 = new branch(v2, inivel2,generations -1,"B");
allArms. add(newArm2);
}
}
void updateLoc(){
loc. addSelf(vel);
}
void updateDir(){
if (type =="A"){
float angle1 = radians(30);
vel. rotateZ (angle1);
}
if (type =="B"){
float angle1 = radians(-30);
vel. rotateZ (angle1);
}
}
void Display(){
stroke(250,0,0);
strokeWeight(4);
point (loc.x, loc.y, loc.z);
stroke(250);
strokeWeight(1);
line (loc.x, loc.y, loc.z, oriLoc.x, oriLoc.y, oriLoc.z);
}
}
1