//---E4C-----Richard Ngo----- 11/29/04----------
//------FIREFLIES-------------------------------
int flies = 10;
Fly[] o = new Fly[flies];
float x = 0.0;
void setup()
{
ellipseMode(CENTER);
rectMode(CENTER);
smooth();
size(300, 300);
for (int i = 0; i < flies; i++)
{
o[i] = new Fly(x,x,random(1),random(1), random(8,15),width/2,height/2);
}
}
void draw()
{
float lightran = random (5,10);
background(0);
noStroke();
smooth();
fill(181,215,216);
ellipse(width/2,height/2, 30+lightran, 30+lightran);
for (int i = 0; i < flies; i++)
{
o[i].Angle();
o[i].Location();
o[i].Fireflies();
}
fill(255,20+(lightran * 10));
ellipse(width/2,height/2, 90+lightran*3, 90+lightran *3);
fill(149,184,236,20+lightran);
ellipse(width/2,height/2, 70+lightran, 70+lightran);
}
class Fly
{
float ang1;
float ang2;
float angSpeed1;
float angSpeed2;
float radius;
float xloc;
float yloc;
float factor1;
float factor2;
boolean attract,buzz;
int alpha1;
int alpha2;
int alpha3;
//------------Constructor-----------
Fly( float a1, float a2, float as1, float as2, float r, float f1, float f2)
{
ang1 = a1;
ang2 = a2;
angSpeed1 = as1;
angSpeed2 = as2;
radius = r;
xloc = 0;
yloc = 0;
factor1 = f1;
factor2 = f2;
}
void Angle()
{
//
ang1 += angSpeed1;
ang2 += angSpeed2;
if (ang1 > 360)
{ ang1 = 0; }
if (ang2 > 360)
{ ang2 = 0; }
}
void Location()
{
//------sin and cos movements--------------
float temp1 = radians(ang1);
float temp2 = radians(ang2);
xloc = sin(temp1) * factor1;
yloc = cos(temp2) * factor2;
//-----attraction around the light--------
if (attract == true)
{
xloc = sin(temp1) * factor1--;
yloc = cos(temp2) * factor2--;
}
//------buzz position around light---------
float randlightx = random(-25,20);
float randlighty = random(-30,30);
if (buzz == true)
{
xloc= 0+randlightx;
yloc= 0+randlighty;
}
}
void Fireflies()
{
float randd1 = random(1,5);
float randd2 = random(1,14);
float randc = random(-1,2);
//-------firefly glow----
push();
noStroke();
fill(255,197,72,140);
ellipse((width/2 + xloc),(height/2 + yloc),radius+randd2,radius+randd1);
fill(255,100);
ellipse((width/2 + xloc),(height/2 + yloc),radius+randd2+6,radius+randd1+6);
pop();
//------fire fly---------
push();
noStroke();
fill(255,210,0,200);
ellipse((width/2 + xloc),(height/2 + yloc),radius-randd1,radius-randd2);
fill(63,48,17,170);
ellipse((width/2 + xloc)+randc,(height/2 + yloc)+5,5,8);
pop();
//---Atrract to light----
if((width/2 + xloc) > 100 && (width/2 + xloc) < 200 &&
(height/2 + yloc)>100 && (height/2 + yloc)< 200)
{attract = true;}
//---Buzz around light---
if((width/2 + xloc) > 130 && (width/2 + xloc) < 165 &&
(height/2 + yloc)>130 && (height/2 + yloc)< 165)
{buzz = true;}
}
}