mousePressed is working, but only for a second?
in
Programming Questions
•
11 months ago
So when I run my program, the mousePressed function works when I press the mouse, but it only works for one second before it does back to the normal background.
Here's my code:
- Fish [] f;
- int N = 1000;
- void setup() {
- size(500, 500);
- smooth();
- background(0,0,255);
- f = new Fish [N];
- for (int i=0; i<N; i++) {
- f[i] = new Fish(random(20,30), color(random(255), random(255), random(255)));
- }
- }
- void draw() {
- background(0,0,255);
- }
- void mousePressed() {
- background(0,0,255);
- for(int i=0; i<N; i++) {
- f[i].display();
- f[i].move();
- }
- }
- class Fish {
- float x, y, w;
- float m;
- color c;
- float speed;
- float delta;
- Fish (float ww, color cc) {
- x = random(width);
- y = random(height);
- w = ww;
- m = 1;
- delta = random(0.1, 2.0);
- c = cc;
- speed = random(0.5, 2.5);
- }
- void move() {
- x = x + m;
- y = y + speed;
- speed = speed;
- }
- void stepAnimation() {
- if (y > (height-w/2)) {
- speed = speed * -delta;
- y = height-w/2;
- }
- if ((x > (width-w/2)) || (x < w/2))
- m = m * -1;
- }
- void display() {
- fill(c);
- noStroke();
- ellipse(x, y, w, w);
- }
- }// end of class Fish
1