import java.applet.*; 
import java.awt.*; 
import java.awt.image.*; 
import java.awt.event.*; 
import java.io.*; 
import java.net.*; 
import java.text.*; 
import java.util.*; 
import java.util.zip.*; 

public class spyro_study extends BApplet {
// A study on double spiral.
// by Alessandro Capozzo 
// 27th August 2003.

float rotation;
float coef;
float step,ang,r,x,y,l;
int xx,yy,zz;
star[] galaxy;
int index;
void setup() 
{
  size(400,400);
  background(0xff999999);
  
  coef=0;
  galaxy=new star[9501];
  rotation=PI/600;
  index=1;
   for(int s=0;s<2;s++){
    for (int step=0;step<600;step++){
      r=step*0.4f;
      ang=step*0.025f+(0.0001f/random(20))+PI*s;
      x = cos(ang)*r;
      y = sin(ang)*r;
      l=18-(step/25)+1;
      //l=10;
      for (int p=0;p<l;p++){
      xx =(int)( x + (random((l*2))-(l*2)));
      zz =(int)(y + (random(l*2)-(l*2)));
        yy =0+(int)(random(l*2)-(l));
        int rr=(int)(l*5+random(30));
        int gg=(int)(l*5-random(5));
        int bb=(int)(l*5-random(5));
        galaxy [index] = new star(xx,yy,zz,150+rr,200+gg,200+bb);
        index=index+1;
         }
      }
      
 
 }
 
 
}

void loop() {
 
    rotateZ(PI/5);
     rotateX(PI/-6);
// 
    coef=coef+rotation;
    if (coef>PI){
        coef=0;
       }
   pop();
    translate(280,20);

     pop();
      rotateY(rotation);
         rotation=PI/((mouseX/2)+10);
         int count=galaxy.length;
          for (int i=1;i<count;i++){
          galaxy[i].update();
          }
        push();
     push();
 }
 
class star {
   int _x,_y,_z,_r,_g,_b;
   star(int x,int y, int z, int r,int g, int b){
    _x=x;
    _y=y;
    _z=z;
    _r=r;
    _g=g;
    _b=b;
   }
   void update () {
   stroke(_r,_g,_b);
    point(_x,_y,_z);
   }
}

}