Change transparency over time
in
Programming Questions
•
2 years ago
I wrote a super basic code for drawing circles with greyscale coloring. The keys that are used are the middle row of a qwerty keyboard so 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l'. I am really new to Processing and was wondering how to create a time event that after the key is released the circle fades away within 5 seconds. Here is my code so far :
- float x;
- float y;
- float b = 0; //start black
- float g = 100; //start grey
- float w = 200; //start white
- float diam; //diameter
- void setup () {
- size(900,300);
- background(255);
- }
- void draw() {
- x = random(width);
- y = random(height);
- diam = 200;
- }
- void keyPressed() {
- if (key == 'a') { //darkblack
- stroke(0);
- fill(b);
- ellipseMode(CENTER);
- ellipse(x,y,diam,diam);
- }
- if (key == 's') { //mediumblack
- stroke(0);
- fill(b + 50);
- ellipseMode(CENTER);
- ellipse(x,y,diam,diam);
- }
- if (key == 'd') { //lightblack
- stroke(0);
- fill(b + 90);
- ellipseMode(CENTER);
- ellipse(x,y,diam,diam);
- }
- if (key == 'f') { //darkgrey
- stroke(0);
- fill(g);
- ellipseMode(CENTER);
- ellipse(x,y,diam,diam);
- }
- if (key == 'g') { //mediumgrey
- stroke(0);
- fill(g + 50);
- ellipseMode(CENTER);
- ellipse(x,y,diam,diam);
- }
- if (key == 'h') { //lightgrey
- stroke(0);
- fill(g + 90);
- ellipseMode(CENTER);
- ellipse(x,y,diam,diam);
- }
- if (key == 'j') { //darkwhite
- stroke(0);
- fill(w);
- ellipseMode(CENTER);
- ellipse(x,y,diam,diam);
- }
- if (key == 'j') { //mediumwhite
- stroke(0);
- fill(w + 25);
- ellipseMode(CENTER);
- ellipse(x,y,diam,diam);
- }
- if (key == 'j') { //lightwhite
- stroke(0);
- fill(w + 50);
- ellipseMode(CENTER);
- ellipse(x,y,diam,diam);
- }
- }
2