We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › [NEWB] Switch between classes with trigger
Page Index Toggle Pages: 1
[NEWB] Switch between classes with trigger? (Read 338 times)
[NEWB] Switch between classes with trigger?
Apr 24th, 2007, 9:19am
 
Hi,

I'm new to scripting but trying to complete an interactive installation in a stairwell.
I have two .pde that work separately and I'm trying to combine them into one .pde.  I'd like the first code (boxes) to run until an ultrasonic rangefinder triggers a reset (max/msp output a2_0<50)...at which point the second code (class Walkers) will fade in quickly, play for 6 seconds and fade back to the boxes.  
Here's my awkward attempt that gives me only a background color.  Can you please tell me where to start looking for a solution?  Am I waaayyy off?
Thanks!

//walkers derived from "randomwalkers"original code: http://www.codetree.org/artwork/art.php?id=176.  Author: ninoscript
//boxes derived from processing.org "FOV" example
import com.cycling74.io.*;
import com.cycling74.net.*;
import com.cycling74.util.*;
import maxlink.*;
import com.cycling74.msp.*;
import com.cycling74.max.*;
import com.cycling74.mxjedit.*;
MaxLink link = new MaxLink(this,"maxlink");
public float a0_0, a1_0, a1_5, a2_0, a2_5, camx1, camy1, camx2, camy2;

float box1 = 0.0;
float box2 = 0.0;
float box3 = 0.0;

int walkersNumber = 100;
Walker[] walkers = new Walker[walkersNumber];

void setup() {
   link.declareInlet("a0_0"); //ardBT#1 vibration sensor
   link.declareInlet("a1_0"); //ardBT#2 photoresistor
   link.declareInlet("a1_5"); //RESERVED
   link.declareInlet("a2_0");  //USB Arduino rangefinder
   link.declareInlet("a2_5"); //USB Arduino photoresistor
   link.declareInlet("camx1");  //lower landing camera
   link.declareInlet("camy1");  //lower landing camera
    link.declareInlet("camx2");  //upper landing camera
   link.declareInlet("camy2");  //upper landing camera
   
 size(1030, 2550, P3D);
 frameRate(30);
    if (a2_0 < 50) {
     frameRate(camx1/10);
     }
noStroke();

      if (a2_0 < 50) {
         for(int i=0; i<walkersNumber; i++){
         walkers[i] = new Walker(i);
        }
      }
}

void draw()
{
//lights();
 background(a2_5);//photoresistor from arduino usb#1
     if (a2_0 < 50) {
     background(51);
     }
 float cameraY = height/2.0;
 float fov = camy1/float(width) * PI/2; //float fov = camy/float(width) * PI/2
 float cameraZ = cameraY / tan(fov / 1.0);
 float aspect = float(width)/float(height);
 perspective(fov, aspect, cameraZ/5.0, cameraZ*5.0);
 
//BACK BOX
 box1 = 5;
 box2 = 50;
 box3 = 1000;
translate(width/2, 1400, 0);
rotateX(-camy1/3000);// rotateX(-PI/3 + camx/float(height) * PI);
rotateY(camx1/float(height)+45);//(PI/1 + camy/float(height) * PI/2);
 fill(255);
   //if (a2_0 < 50) {
  // fill(232,0,0);
   //  }
 box(box1,box2,box3);

///SIDE BOXES
  translate(-box3/2, 0, box3*.5);
  fill(255);
    //  if (a2_0 < 50) {
    //  fill(232,0,0);}
  box(box3,box2, 5);
 translate(0, 0, -box3);
 box(box3,box2,5);


      if (a2_0 < 50) {
        for(int i=0; i<walkersNumber; i++){
        walkers[i].walk();
        walkers[i].render();
        }
      }
}    
       
class Walker {
   int x, y, _color;
 
   Walker(int color_) {
     x = int(random(width));
     y = 0;
     _color = color_;
     }
 
   void render() {
     float rcolor = random(20, 50);
     stroke(0);
     stroke (rcolor*2,0,0);
    fill(camx1/3, 0, 0);
    // strokeWeight(2);
     ellipse (x,y,camx1/18,camx1/18);
     }

   void walk() {
     float vx = random(5)-2;
     float vy = random(5)-.5;
     x += vx;
     y += vy;
     x = constrain(x,0,width-1);
     y = constrain(y,0,height-1);
     }
     
}

Page Index Toggle Pages: 1