x-post Processing Forum
I'm trying to make a super simple sketch where the user inputs a point with mousePressed, then (after a delay), processing plots a point at a random place on the screen back at you, and the points slowly fade into a semitransparent background. Here's my code, I've tried a bunch of different ideas but nothing seems to have worked, and now I'm at a point where nothing is working at all. Any pointers?
void setup() {
size(600, 600);
background(0);
stroke(color(168, 168, 168));
strokeWeight(2);
frameRate(60);
smooth();
}
void draw() {
if (mousePressed) {
ellipse(mouseX,mouseY,20,20);
}
else if (mousePressed) {
delay(10);
ellipse(random(mouseX), random(mouseY),20,20);
}
else {
fill(0,55,0, 2);
rect(0, 0, width, height, 2);
}
}
I would split the problem in two easier ones:
random()
function)To slowly fade the point there are at least a couple of options I can think of:
(Quick tip on
stroke()
: if you pass a single value it will be used as a grayscale value. Be sure read the reference and see what options are available for you to play with)Option 1:
Demo:
Option 2:
Demo:
With the first option, transparency affects a single dot at a time. With the first option, transparency affects a multiple dots at a time (in fact, everything that's drawn). There is no right/wrong, it's all up to what's closest to what your concept is about. Have fun and explore!
You shouldn't use the
delay()
function to change the timings of animations. It just causes your program to become unresponsive.Instead, use the
frameCount
variable or themillis()
function to record timing information, then perform your animations based on that value.Here's an example that displays a circle for 60 frames whenever you click the mouse: