How to remember where the cursor went.....
in
Programming Questions
•
2 years ago
Dear all
I've been trying to this for a few days but I'm ashamed to say I'm stuck....
The code I'm doing is meant to visualize a project I'm working on. Basically it's a bunch of lamps that reacts to the user interaction by dimming on and off...Pretty straightforward....
On the screen you have two light sources ( two ellipses) and the mouse cursor is playing as the visitor: the closest the visitor/cursor the more the light dim; and this is what I called first behavior. Now I'd like to add a new behavior that is triggered whenever the visitor/cursor stands still; I'd like to make Processing understand that the cursor is still for, let's say 3 seconds, and start a new behavior, like changing color to the light (I haven't figure out exactly what but let's stick to that now).
Here is the code;
Lamp myLamp;
Lamp myLamp2;
void setup(){
size(800,600);
background(0);
smooth();
myLamp = new Lamp(200,150);
myLamp2 = new Lamp (500,300);
}
void draw() {
myLamp.display();
myLamp2.display();
println(" c value is " + myLamp.c + " and mouse X is " + mouseX);
}
/*
This is the class used to define the Lamp Object attributes
*/
class Lamp {
//data
float posX;
float posY;
int ellipseWidthHeight;
float c; // the color of the speheres (will change with mouse positioning)*/
/*
constructors assign values to the attributes.
*/
Lamp(float tempPosX, float tempPosY) {
posX = tempPosX;
posY = tempPosY;
ellipseWidthHeight = 50;
}
/*
methods determine what to do with the constructors
*/
void display() {
ellipseMode(CENTER);
//color c is set by calculating distance beteween mouse pointer and center of te circles
c = dist(posX, posY, mouseX, mouseY);
fill (c);
ellipse(posX, posY, ellipseWidthHeight, ellipseWidthHeight);
}
}
So the dimming effect is done by assigning to the fill() a value (C) that is the Distance between MouseX and Y and the center of the ellipses.
What I tried to do without success is reading the Mouse XandY: if the value stays the same for 3 seconds ( = the cursor is still ) then do something.....
Any idea on how to do this?
1