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 › how to get previous x and y value
Page Index Toggle Pages: 1
how to get previous x and y value? (Read 1077 times)
how to get previous x and y value?
Jul 23rd, 2009, 3:17pm
 
hi there,  I guess I have a beginner`s question.

Here is comes:

how to store the previous value (like to draw a line), if I use x and y values I get from a webcam.
I know pmouseX and pmouseY, is there an similar way to treat x and y without mouse?

Thanks a lot for helping!

kat
Re: how to get previous x and y value?
Reply #1 - Jul 23rd, 2009, 11:41pm
 
if you have a way to get x and y from a webcam, then this is an easy way to do what you want;

int pX, pY, x = 0, y = 0;

void draw()
{
 pX = x;
 pY = y;
 x = getXfromWebcam(); // make this function
 y = getYfromWebcam(); // make this function
}
Re: how to get previous x and y value?
Reply #2 - Jul 27th, 2009, 12:00pm
 
Thanks for advice!
Unfortunately I cannot make it work.
One coordinate of the line stays 0 /0.
Maybe too many definitions for x and y mixed up??
What I want is a line that follows the bright pixels.

This is the code I`m tinkering with:

import processing.video.*;

Capture video;
float valRed= 0;
float valGreen= 0;
float valBlue= 0;

int pX,pY, x =0, y=0;

void setup() {
 size(640, 480);
 background (0);
 
 video = new Capture(this, width, height, 30);
 stroke(15);
 smooth();
}

void draw() {
 valRed = random (255);
 valGreen = random (255);
 valBlue = random (255);
 
 pX = x;
 pY = y;
 
 if (video.available()) {
   video.read();
 
  int brightestX = 0;
  int brightestY = 0;
   float brightestValue = 0;
   video.loadPixels();
   int index = 0;
   for (int y = 0; y < video.height; y++) {
     for (int x = 0; x < video.width; x++) {
     
       int pixelValue = video.pixels[index];
   
       float pixelBrightness = brightness(pixelValue);
     

       if (pixelBrightness > brightestValue) {
         brightestValue = pixelBrightness;
         brightestY = y;
         brightestX = x;
       
       }
       index++;
     }
   }
 
 stroke(valRed, valGreen, valBlue);
  // rect(brightestX, brightestY, 20, 20);
   line (brightestX, brightestY, pX, pY);
 }
}


Can you tell me where the mistake is?
Thank you!

kat
Re: how to get previous x and y value?
Reply #3 - Jul 27th, 2009, 12:19pm
 
maybe this is a more simple sketch to show :

int pX, pY, x =50, y = 80;

float redValue = 0;
float greenValue = 0;
float blueValue = 0;

void setup () {
 size(400, 400);
 randomSeed (0);
 background(0);
 noStroke();
 
}


void draw() {
 
 redValue = random (255);
 greenValue = random (255);
 blueValue = random (255);
   fill (redValue, greenValue, blueValue);
 
 pX =x;
 pY = y;
 
 x+=random (-2, 2);
 y+=random(-2, 2);
 

 line(pX, pY, x, y);

}


But it is not working..


from
kat
Re: how to get previous x and y value?
Reply #4 - Jul 27th, 2009, 12:33pm
 
I was perplex a few seconds. They I saw noStroke(), which is strange for a line() command. Then I saw you used fill() instead of stroke()...
Re: how to get previous x and y value?
Reply #5 - Jul 27th, 2009, 9:20pm
 
Try this.

Code:
import processing.video.*;

Capture video;
float valRed= 0;
float valGreen= 0;
float valBlue= 0;
int brightestX =0;
int brightestY =0;
int x = 0, y = 0, pX = 0, pY = 0;

void setup() {
size(640, 480);
background (0);

video = new Capture(this, width, height, 30);
stroke(15);
smooth();
}

void draw() {
valRed = random (255);
valGreen = random (255);
valBlue = random (255);
 
pX = brightestX;
pY = brightestY;

if (video.available()) {
  video.read();


  float brightestValue = 0;
  video.loadPixels();
  int index = 0;
  for (int y = 0; y < video.height; y++) {
    for (int x = 0; x < video.width; x++) {
   
int pixelValue = video.pixels[index];
   
float pixelBrightness = brightness(pixelValue);
   

if (pixelBrightness > brightestValue) {
  brightestValue = pixelBrightness;
  brightestY = y;
  brightestX = x;
 
}
index++;

    }
  }

stroke(valRed, valGreen, valBlue);
 // rect(brightestX, brightestY, 20, 20);
  line (brightestX, brightestY, pX, pY);
}
}


Re: how to get previous x and y value?
Reply #6 - Jul 29th, 2009, 2:15am
 
yes, that`s what I wanted! Thanks a lot!
It is the where and what in value declaration that troubles me.
Thanks again!

kat
Page Index Toggle Pages: 1