class firefly{ float x,y; int line_length = 1; int level = 100; float i=0; float j=0; float angle = 0; float theta = 0.0; float rand_col; color blink = 255; boolean on = false; float dia = 5; // CONSTRUCTOR firefly(float xpos, float ypos) { x = xpos; y = ypos; } // main function to operate object void go() { stroke(255); angle = random(angle-.1*PI, angle+.1*PI); i = line_length*cos(angle); j = line_length*sin(angle); x += i; y += j; borders(); rand_col = random(0,100); if(rand_col > 98 && !on){ blink = 255; on = true; } fill(blink, blink, 0); noStroke(); ellipse(x,y,dia,dia); theta += .01*PI; blink *= 0.8; dia -= 0.5; reset(); } void reset(){ if(blink <= 0){ blink = 0; on = false; dia = 5; } } void borders(){ if(x > width){ x = 0; } if(x < 0){ x = width; } if(y > height){ y = 0; } if(y < 0){ y = height; } } }