Help with Ripple effect
in
Programming Questions
•
2 years ago
Hi,
I am working on getting this code to simulate a ripple effect. I am extremely new to Processing so please bare with me.
Objective:
1.When the mouse is pressed the ellipses appear, complete their transformation and then finally dissapear.
2.The ellipses should appear anywhere on the screen and vary in size
3.Stroke Colour randomized
I can not get any of the following requirments to work. I would really appreciate some help.
Thank you so much,
Nicole
Code:
int a = 0;
int b = 0;
int b = 0;
void setup() {
size(400, 400);
stroke(255, 0, 0);
noFill();
smooth();
}
void draw() {
background(0);
if (mousePressed==true) {
if (a > 200) {
a = 0;
}
ellipse(200,200,a,200);
ellipse(200,200,a,100);
ellipse(200,200,a,50);
tint(255, 0);
a++;
if (b > 200){
b=0;
}
ellipse(200,200,200,b);
ellipse(200,200,100,b);
ellipse(200,200,50,b);
b++;
}
}
This is the desired outcome. I found this code while browsing this forum, but I do not understand how to apply it to my code:
// Left mouse button creates growing circle with fixed transparency
// Right mouse button creates growing circle with fading transparency (removed when invisible)
// Space bar removes all the circles
// Right mouse button creates growing circle with fading transparency (removed when invisible)
// Space bar removes all the circles
ArrayList circles = new ArrayList();
void setup() {
size(500,500);
smooth();
}
size(500,500);
smooth();
}
void draw() {
background(0);
for (int i=0; i<circles.size(); i++) {
ExpandingCircle ec = (ExpandingCircle) circles.get(i);
ec.update();
ec.display();
if (ec.transparency <= 0) { circles.remove(i); } // remove invisible circles
}
}
class ExpandingCircle {
int x,y;
float radius;
color c;
boolean transparencyOn;
int transparency;
ExpandingCircle(int x, int y, boolean transparencyOn) {
this.x = x;
this.y = y;
this.transparencyOn = transparencyOn;
c = color(random(255),random(255),random(255));
transparency = 255;
}
void update() {
radius++;
if (transparencyOn && radius >= 50 && transparency > 0) { transparency--; }
}
void display() {
stroke(255);
noFill();
ellipse(x,y,radius,radius);
}
}
void mousePressed() {
if (mouseButton == LEFT) { circles.add(new ExpandingCircle(mouseX,mouseY,false));
} else { circles.add(new ExpandingCircle(mouseX,mouseY,true)); }
}
void keyPressed() {
if (key == ' ') { circles.clear(); }
}
[Moderator's note: made a more sober thread title...]
1