Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import toxi.geom.*;
- import peasy.*;
- import controlP5.*;
- ControlFrame cf;
- PeasyCam cam;
- Stick bob;
- ArrayList <Stick> allBobs;
- void settings() {
- size(800,600,P3D);
- }
- void setup(){
- cf = new ControlFrame(this, 300, 400, "Controls");
- smooth();
- allBobs = new ArrayList <Stick> ();
- cam = new PeasyCam(this,100);
- }
- void draw(){
- background(0);
- allBobs.clear();
- Vec3D v = new Vec3D (0,0,0);
- Vec3D iniVel = new Vec3D (10,0,0);
- bob = new Stick(v,iniVel,ITE,"A");
- allBobs.add(bob);
- stroke(255);
- noFill();
- strokeWeight(1);
- // box(600);
- 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(ANGLE1);
- float angle3 = radians(0);
- vel.rotateX(angle1);
- vel.rotateY(angle2);
- vel.rotateZ(angle3);
- vel.normalize();
- vel.scaleSelf(100);
- }
- if(type == "B"){
- float angle1 = radians(0);
- float angle2 = radians(0);
- float angle3 = radians(ANGLE2);
- vel.rotateX(angle1);
- vel.rotateY(angle2);
- vel.rotateZ(angle3);
- vel.normalize();
- vel.scaleSelf(20);
- }
- if(type == "C"){
- float angle1 = radians(ANGLE3);
- float angle2 = radians(0);
- float angle3 = radians(0);
- vel.rotateX(angle1);
- vel.rotateY(angle2);
- vel.rotateZ(angle3);
- vel.normalize();
- vel.scaleSelf(40);
- }
- }
- 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);
- }
- }
- //
- float ANGLE1 = 0, ANGLE2 = 0, ANGLE3 = 0;
- int ITE=0;
- //void ui(){
- //controlP5 = new ControlP5(this);
- // controlWindow = controlP5.begin("controlP5window",100,100,400,200);
- //Slider s01 = controlP5.addSlider("ANGLE1", 0, 90, 20, 20, 100, 10);
- //s01.setWindow(controlWindow);
- //}
- class ControlFrame extends PApplet {
- int w, h;
- String name;
- PApplet parent;
- ControlP5 cp5;
- public ControlFrame(PApplet _parent, int _w, int _h, String _name) {
- super();
- parent = _parent;
- w=_w;
- h=_h;
- name=_name;
- PApplet.runSketch(new String[]{this.getClass().getName()}, this);
- }
- public void settings() {
- size(w, h);
- }
- public void setup() {
- surface.setLocation(10, 10);
- cp5 = new ControlP5(this);
- cp5.addSlider("ANGLE1")
- .plugTo(parent, "ANGLE1")
- .setRange(-180, 180)
- .setValue(90)
- .setPosition(50, 50)
- .setSize(200, 30);
- cp5.addSlider("ANGLE2")
- .plugTo(parent, "ANGLE2")
- .setRange(-180, 180)
- .setValue(90)
- .setPosition(50, 100)
- .setSize(200, 30);
- cp5.addSlider("ANGLE3")
- .plugTo(parent, "ANGLE3")
- .setRange(-180, 180)
- .setValue(90)
- .setPosition(50, 150)
- .setSize(200, 30);
- cp5.addSlider("ITE")
- .plugTo(parent, "ITE")
- .setRange(0, 30)
- .setValue(10)
- .setPosition(50, 200)
- .setSize(200, 30);
- }
- void draw() {
- background(190);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment