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 & HelpPrograms › Help with camera to mouse activation
Page Index Toggle Pages: 1
Help with camera to mouse activation (Read 344 times)
Help with camera to mouse activation
Jul 25th, 2006, 2:53am
 
hi I am trying to change my sketch from being activated by camera to following the mouse. If anyone can help me out I'd greatly appreciate it, heres the code cheers:


import krister.Ess.*;

Channel myChannelA, myChannelB, myChannelC;

import JMyron.*;

JMyron m;//a camera object

//variables to maintain the floating green circle
float objx = 160;
float objy = 120;
float objdestx = 160;
float objdesty = 120;
////////////////
int VNUM = 9000;
int NUM = 3000;
int SIZE = 3000;

int[] gaps = {
 500,50,500,50,500,50,500};


float dial = 10000;
float lastdial = 0;
float dialCount = 0;

boolean dragging = true;



PImage img;  
void setup(){
 // start up Ess
 Ess.start(this);

 myChannelA=new Channel();
 myChannelA.loadSound("201pro3delays.aif");
 myChannelB=new Channel();
 myChannelB.loadSound("horrible.aif");
 
 myChannelC=new Channel();
 myChannelC.loadSound("cowmoo.aif");
 myChannelC.volume(.3);


 myChannelA.play(Ess.FOREVER);

 size(2048,748, P3D);


 framerate(24);
 img = loadImage("cat.jpg");

 
 m = new JMyron();
 m.start(width,height);
 m.trackColor(255,255,255,256*3-100);
 m.update();
 m.adaptivity(3);

 m.adapt();
 println("Myron " + m.version());
 rectMode(CENTER);
 noStroke();

 PFont font;


 font = loadFont("Kipp-No1-120.vlw");
 textFont(font, 47);
}
float xDiff = 0;
float yDiff = 0;




void draw(){
 background(0);



 m.update();
 drawCamera();
 
 

 int[][] centers = m.globCenters();
 
 float avX=0;
 float avY=0;

 for(int i=0;i<centers.length;i++){
   fill(80);

   avX += centers[i][0];
   avY += centers[i][1];
 }
 if(centers.length-1>0){
   avX/=centers.length-1;
   avY/=centers.length-1;
 }


 if(!(avX==0&&avY==0)&&centers.length>0){
   objdestx = avX;
   objdesty = avY;
 }

 objx += (objdestx-objx)/10.0f;
 objy += (objdesty-objy)/10.0f;


 float xSpeed = floor(sqrt(sq(objx - xDiff)));
 float ySpeed = floor(sqrt(sq(objy - yDiff)));





 if(xSpeed <=11  && xSpeed > 3)
 {
   background(237, 27, 53);

   fill(0, 0, 0);
   textSize(120);
   text("Come closer.", 800, 200);
 }


 if(xSpeed <=8  && xSpeed > 4)
 {
    textSize(47);
   fill(255, 255, 255);
   text("You are ugly.", 920, 400);
 }


 else if(xSpeed > 12 && xSpeed < 17)
 {
   image(img,0,0, 2048, 748);
   textSize(100);
  myChannelC.play(1);
 
 }

 if(xSpeed > 6 && xSpeed < 12)
 {
   textSize(47);
   fill(0, 188, 233);
   text("Please wait.", 373, 350);
 }

 else if(xSpeed > 8 && xSpeed < 17)
 {
   myChannelB.play(1);
 }

 else if(xSpeed > 50)  
 {
   myChannelB.stop();
 }


 else if (xSpeed <=8  && xSpeed > 5)
 {

   fill(255, 255, 255);
   textSize(47);
   text("Take a step back.", 885, 450);


 }
 
 fill(30,100,0);
 ellipseMode(CENTER);

 ellipse(objx,objy,30,30);

 xDiff = objx;
 yDiff = objy;

 
 if(objx>300){
   if(objx<330){
     textSize(47);
     fill(0, 188, 233);
     text("Follow the ball.", 1500, 350);
   }
 }

 if(objx>0){
   if(objx<300){
     textSize(47);
     fill(0, 188, 233);
     text("Move to", 200, 350);
   }
 }

 if(objx>0){
   if(objx<300){
     textSize(47);
     fill(0, 188, 233);
     text("centre to", 190, 400);
   }
 }
 
 if(objx>0){
   if(objx<300){
     textSize(47);
     fill(0, 188, 233);
     text("load programme.", 133, 450);
   }
 }
 //////////////////////
 
 if(objx>1700){
   if(objx<2048){
     textSize(47);
     fill(0, 188, 233);
     text("Move to", 1511, 350);
   }
 }

 if(objx>1700){
   if(objx<2048){
     textSize(47);
     fill(0, 188, 233);
     text("screen left", 1491, 400);
   }
 }
 
 if(objx>1700){
   if(objx<2048){
     textSize(47);
     fill(0, 188, 233);
     text("to update camera.", 1448, 450);
   }
 }
 

else if(xSpeed > 8 && xSpeed < 17)
 {
    fill(0, 0, 0, 30);
 rect(random(0,2048), random(0, 2048), random (0, 2048), random (0, 2048));

 }  
 
}

void drawCamera(){
 int[] img = m.differenceImage();
 loadPixels();
 for(int i=0;i<width*height;i++){
   pixels[i] = img[i];
 }
 updatePixels();
}

void mousePressed(){

}

public void stop(){
 m.stop();//stop the object
 super.stop();
}

Page Index Toggle Pages: 1