How to add mouse functions to a class?
in
Programming Questions
•
1 year ago
Hi there,
I'm just starting to learn processing and now I think I could need your help, guys.
I defined a class called Circles and now I try to add some mouse functions.
For example all Circles of the class chance the color when the mouse is over.
But unfortunately i don't know how??? It is possible to do some mouse function on a whole class, at all?
I hope someone could please help me. I'm grateful for all replys and notes.
Thats my code now:
I'm just starting to learn processing and now I think I could need your help, guys.
I defined a class called Circles and now I try to add some mouse functions.
For example all Circles of the class chance the color when the mouse is over.
But unfortunately i don't know how??? It is possible to do some mouse function on a whole class, at all?
I hope someone could please help me. I'm grateful for all replys and notes.
Thats my code now:
- class Circles{
float x,y;
float groesse;
float alph;
float vx;
float vy;
float id;
float ellColor;
float gradient;
float R, G, B;
//constructor
Circles(float _x, float _y, float _groesse, float _alph, float _vx, float _vy, int _id, float Rot, float Gruen, float Blau){
x = _x;
y = _y;
groesse = _groesse;
alph = _alph;
vx = _vx;
vy = _vy;
id = _id;
R = Rot; G = Gruen; B = Blau;
}
//methods
void update(){
int n = (height-100);
int n2 = (width+600);
x+=vx;
y+=vy;
if(x>n){
vx--;
}
if(x<-5){
vx++;
}
if(y>n){
vy--;
}
if(y<-5){
vy++;
}
}
void ellColor(){
fill(255,0,0);
for(int i = 0; i < circles.length; i++){
if(dist(x,y,circles[i].x, circles[i].y) < groesse*1.5 + circles[i].groesse*1.5){
gradient = map(dist(x,y,circles[i].x, circles[i].y),groesse,groesse*2,250,150);
fill(255,gradient);
}
}
}
void display(){
fill(R,G,B, alph);
noStroke();
ellipse(x,y,groesse,groesse);
}
void cLines(){
stroke(255,50);
strokeWeight(.9);
for(int i = 0; i < circles.length; i++){
if(dist(x,y,circles[i].x, circles[i].y) < groesse*4 + circles[i].groesse*4){
line(x,y,circles[i].x, circles[i].y);
}
}
}
}
- /* OpenProcessing Tweak of *@*http://www.openprocessing.org/sketch/45926*@* */
/* !do not delete the line above, required for linking your tweak if you re-upload */
Circles[] circles;
Circles[] circles2;
Circles[] circles3;
void setup(){
size(800,800);
smooth();
frameRate(24);
circles = new Circles[5];
circles2 = new Circles[5];
circles3 = new Circles[5];
for(int i = 0; i < circles.length; i++){
circles[i] = new Circles(random(width),random(height),(150),random(100,70),random(-1,5),random(-1,5),i, 255, 120, 255);
circles2[i] = new Circles(random(width),random(height),(50),random(100,70),random(-1,5),random(-4,5),i, 255, 255, 120);
circles3[i] = new Circles(random(width),random(height),(200),random(100,70),random(-1,5),random(-1,5),i, 150, 255, 255);
}
}
void draw(){
background(0);
for(int i = 0; i < circles.length; i++){
circles[i].cLines();
circles[i].update();
circles[i].display();
circles2[i].cLines();
circles2[i].update();
circles2[i].display();
circles3[i].cLines();
circles3[i].update();
circles3[i].display();
}
}
1