Stuck on code!
Still working on combining the two codes...I need to fix the transition and incorporate fading.
What I want to do: when the ultrasonic rangefinder is activated (a2_0 < 50), the class Walkers fades in, runs until y = bottom of screen (910), then fades back to the boxes, even if there is still a person standing in front of the ultrasonic rangefinder. Maybe I need a second boolean?
I tried tying the Walker class fade-in to the y position of the ellipses:
if (y < 210) {
background (0+y);
if (y > 210) {
background (45);
but this slowed the processing down to a crawl.
I modified the size + variables to suit testing at my desk (hence mousePressed instead of the ultrasonic rangefinder trigger).
///walker class modified from code by ninoscript, //http://codetree.org/artwork/art.php?id=176
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];
boolean first_time = true;
void setup() {
if (mousePressed) {
frameRate (camx1/8);
}
else {
frameRate(30);
}
link.declareInlet("a0_0");
link.declareInlet("a1_0");
link.declareInlet("a1_5");
link.declareInlet("a2_0");
link.declareInlet("a2_5");
link.declareInlet("camx1");
link.declareInlet("camy1");
link.declareInlet("camx2");
link.declareInlet("camy2");
size(410, 960, P3D);
noStroke();
for(int i=0; i walkers[i] = new Walker(i);
}
}
void draw() {
if (mousePressed) {
if (first_time) {
background(45);
float fov = PI/3.0;
float cameraZ = (height/2.0) / tan(PI * fov / 360.0);
perspective(fov, float(width)/float(height), cameraZ/10.0, cameraZ*10.0);
for(int i=0; i walkers[i] = new Walker(i);
}
first_time = false;
}
else {
for(int i=0; i walkers[i].walk();
walkers[i].render();
}
}
}
else {
first_time = true;
//lights();
background(0);
float cameraY = height/2.0;
float fov = camy1/float(width) * PI/2.5; //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
noStroke();
box1 = 5;
box2 = 50;
box3 = 1000;
translate(width/2, 800, 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);
box(box1,box2,box3);
//TOP BOX
///SIDE BOXES
translate(-box3/2, 0, box3*.5);
fill(255);
box(box3,box2, 5);
translate(0, 0, -box3);
box(box3,box2,5);
}
}
class Walker {
int x, y, _color;
Walker(int color_) {
x = int(random(width));
y = 1;
_color = color_;
}
void render() {
float rcolor = random(20, 50);
stroke (rcolor*2,0,0);
fill(camx1/3, 0, 0);
ellipse (x,y,camx1/18,camx1/18);
if (y > 955) {
y = 0;
}
}
void walk() {
float vx = random(6)-2.5;
float vy = random(6)-.5;
x += vx;
y += vy;
x = constrain(x,0,width-1);
y = constrain(y,0,height-1);
}
}
What I want to do: when the ultrasonic rangefinder is activated (a2_0 < 50), the class Walkers fades in, runs until y = bottom of screen (910), then fades back to the boxes, even if there is still a person standing in front of the ultrasonic rangefinder. Maybe I need a second boolean?
I tried tying the Walker class fade-in to the y position of the ellipses:
if (y < 210) {
background (0+y);
if (y > 210) {
background (45);
but this slowed the processing down to a crawl.
I modified the size + variables to suit testing at my desk (hence mousePressed instead of the ultrasonic rangefinder trigger).
///walker class modified from code by ninoscript, //http://codetree.org/artwork/art.php?id=176
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];
boolean first_time = true;
void setup() {
if (mousePressed) {
frameRate (camx1/8);
}
else {
frameRate(30);
}
link.declareInlet("a0_0");
link.declareInlet("a1_0");
link.declareInlet("a1_5");
link.declareInlet("a2_0");
link.declareInlet("a2_5");
link.declareInlet("camx1");
link.declareInlet("camy1");
link.declareInlet("camx2");
link.declareInlet("camy2");
size(410, 960, P3D);
noStroke();
for(int i=0; i
}
}
void draw() {
if (mousePressed) {
if (first_time) {
background(45);
float fov = PI/3.0;
float cameraZ = (height/2.0) / tan(PI * fov / 360.0);
perspective(fov, float(width)/float(height), cameraZ/10.0, cameraZ*10.0);
for(int i=0; i
}
first_time = false;
}
else {
for(int i=0; i
walkers[i].render();
}
}
}
else {
first_time = true;
//lights();
background(0);
float cameraY = height/2.0;
float fov = camy1/float(width) * PI/2.5; //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
noStroke();
box1 = 5;
box2 = 50;
box3 = 1000;
translate(width/2, 800, 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);
box(box1,box2,box3);
//TOP BOX
///SIDE BOXES
translate(-box3/2, 0, box3*.5);
fill(255);
box(box3,box2, 5);
translate(0, 0, -box3);
box(box3,box2,5);
}
}
class Walker {
int x, y, _color;
Walker(int color_) {
x = int(random(width));
y = 1;
_color = color_;
}
void render() {
float rcolor = random(20, 50);
stroke (rcolor*2,0,0);
fill(camx1/3, 0, 0);
ellipse (x,y,camx1/18,camx1/18);
if (y > 955) {
y = 0;
}
}
void walk() {
float vx = random(6)-2.5;
float vy = random(6)-.5;
x += vx;
y += vy;
x = constrain(x,0,width-1);
y = constrain(y,0,height-1);
}
}
0 Comments:
Post a Comment
<< Home