ITERATIVE DESIGN (II)_##2nd round##____ STAGE 3 (CONSTRUCTION)

INDEX

I have been building an L-system based branch:

import toxi.geom.*;
import peasy.*;
import controlP5.*;

PeasyCam cam;

Stick bob;

ControlP5 controlP5;
ControlWindow controlWindow;

ArrayList <Stick> allBobs;

void setup(){
 size(800,400,P3D);
 smooth();

 allBobs = new ArrayList <Stick> ();

 cam = new PeasyCam(this, 100);

 Vec3D v = new Vec3D (0,0,0);
 Vec3D iniVel = new Vec3D (100,0,0);
 bob = new Stick(v, iniVel, 8, "A");

 allBobs.add(bob);
}

void draw(){
 background(0);

 stroke(255);
 noFill();
 strokeWeight(1);
 //box(400);

 for(Stick b : allBobs){
 b.run();
 }
}


class Stick{

 Vec3D loc;
 Vec3D oriLoc;
 Vec3D vel;

 int generations;
 String type;

 Stick(Vec3D _loc, Vec3D _vel, int _generations, String _type){
 loc = _loc;
 oriLoc = _loc.copy();
 vel = _vel;
 generations = _generations;

 type = _type;

 //stack of functions that get executed only once
 updateDir();
 updateLoc();
 spawn();

 }

 void run(){
 display();
 }

 void spawn(){

 if(generations > 0){

 if(type == "A"){
 Vec3D v = loc.copy();
 Vec3D iniVel = vel.copy();
 Stick newBob = new Stick(v, iniVel, generations-1, "A");

 allBobs.add(newBob);

 Vec3D v2 = loc.copy();
 Vec3D iniVel2 = vel.copy();
 Stick newBob2 = new Stick(v2, iniVel2, generations-1, "B");

 allBobs.add(newBob2);
 }

 if(type == "B"){
 Vec3D v = loc.copy();
 Vec3D iniVel = vel.copy();
 Stick newBob = new Stick(v, iniVel, generations-1, "C");

 allBobs.add(newBob);

 }

 if(type == "C"){
 Vec3D v = loc.copy();
 Vec3D iniVel = vel.copy();
 Stick newBob = new Stick(v, iniVel, generations-1, "A");

 allBobs.add(newBob);

 }

 }

 }

 void updateDir(){
 if (type == "A"){
 float angle1 = radians(0);
 float angle2 = radians(30);
 float angle3 = radians(0);

 vel.rotateX(angle1);
 vel.rotateY(angle2);
 vel.rotateZ(angle3);

 }
 if (type == "B"){
 float angle1 = radians(-30);
 float angle2 = radians(0);
 float angle3 = radians(0);

 vel.rotateX(angle1);
 vel.rotateY(angle2);
 vel.rotateZ(angle3);
 }
 if (type == "C"){
 float angle1 = radians(0);
 float angle2 = radians(0);
 float angle3 = radians(10);

 vel.rotateX(angle1);
 vel.rotateY(angle2);
 vel.rotateZ(angle3);
 }

 }

 void updateLoc(){
 loc.addSelf(vel);

 }

 void display(){
 stroke(255,0,0);
 strokeWeight(4);
 point(loc.x,loc.y,loc.z);

 stroke(255);
 strokeWeight(1);
 line(loc.x,loc.y,loc.z, oriLoc.x,oriLoc.y,oriLoc.z);

 }

}

To do it, I have used a tutorial by Jose Sanchez.

REFERENCES:

Sanchez, J., 2013. Processing Tutorial S02E02 – L-SYSTEMS. [on line]. Youtube. Available on: https://www.youtube.com/watch?v=qF8LGLVrwfo

INDEX

Advertisements

One comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s