Hello!
This is my first time using processing and I can’t work my problem out. Hopefully someone can help!
I am trying to display an image that follows the cursor of the mouse, and when the mouse is clicked I want a flower to appear, stay visible and remain in the same spot of the moment it was clicked. I want to be able to do this repeatedly, such that the vines(the image mouseCursor) that appear and follow my mouse has flowers added to it whenever I click. Such that eventually vines with a lot of flowers can be visible.
At the moment the flower disappears when the mouse is not clicked. To my understanding this is because draw is a loop and the functionality of mousepressed is a temporary function. However I can’t figure out how else I am supposed to achieve this.
float x;
float y;
float easing = 0.05;
float offset = 0;
int num = 50;
float mx = new float[num];
float my = new float[num];
PImage mouseCursor;
PImage flower;
void setup() {
size(1920, 1080);
noStroke();
smooth();
fill(255, 153);
mouseCursor = loadImage(“MouseCursor3.png”);
flower = loadImage(“flower.png”);
}
void draw() {
background(255);
int which = (frameCount/3) % num;
mx[which] = mouseX;
my[which] = mouseY;
for (int i = 0; i < num; i++) {
// which+1 is the smallest (the oldest in the array)
float targetX = mouseX;
float dx = targetX - x;
x += dx * easing;
float targetY = mouseY;
float dy = targetY - y;
y += dy * easing;
int index = (which+1 + i) % num;
image(mouseCursor,mx[index], my[index], 181, 126);
}
if (mousePressed) {
image(flower,x, y, 40, 40);
}
}