Hi All. I wrote the following codes to follow my mouse when I pressed the left button with red and when I pressed the right button with green colors but color of all the shapes changes when I changed the mouse buttons.
It must start new shapes with new color and must not change the rest/left ones when I change the mouse buttons but it changes the color of all.
I need your guide. Thanks.
Here is the code
ArrayList <PVector> points= new ArrayList <PVector>();
float x, y;
float easing = 0.2;
float diameter = 12;
int distance=100;
int a;
void setup() {
size(1200, 1000);
background(0);
smooth();
surface.setResizable(true);
colorMode(RGB);
}
void draw() {
float targetX = mouseX;
float targetY=mouseY;
y += (targetY - y) * easing;
x += (targetX - x) * easing;
if (mousePressed&&mouseButton==LEFT) {
points.add(new PVector(x, y));
for (int i=0; i<points.size(); i++) {
float k= points.get(i).x;
float l = points.get(i).y;
stroke(255, 0, 0);
fill(255, 0, 0);
ellipse(k, l, 12, 12);
println(targetX + " : " + x);
if (points.size()>distance) {
points.remove(0);
clear();
}
}
}
if (mousePressed&&mouseButton==RIGHT) {
points.add(new PVector(x, y));
for (int i=0; i<points.size(); i++) {
float m= points.get(i).x;
float n = points.get(i).y;
stroke(0, 255, 0);
fill(0, 255, 0);
ellipse(m, n, 12, 12);
println(targetX + " : " + x);
if (points.size()>distance) {
points.remove(0);
clear();
}
}
}
}