- Code: Select all
int loop;
init();
for (loop=0;loop<LINES;loop++) run();
int loop;
init();
for (loop=0;loop<LINES;loop++) run();
#define STARS 1000
#define MAXDEPTH 50
#define SPEED .5
float X[STARS],Y[STARS],Z[STARS],OZ[STARS];
int i;
double midx,midy;
void init()
{
midx = 1.0*view.width/2;
midy = 1.0*view.height/2;
for (i=0;i<STARS;i++)
{
X[i] = rand(view.width*MAXDEPTH)-view.width*MAXDEPTH/2;
Y[i] = rand(view.height*MAXDEPTH)-view.height*MAXDEPTH/2;
Z[i] = rand(MAXDEPTH)+1;
OZ[i] = Z[i];
}
}
void run()
{
for (i=0;i<STARS;i++)
{
OZ[i] = Z[i];
Z[i]-=SPEED;
if (Z[i]<=0) Z[i] = MAXDEPTH;
}
for (i=0;i<STARS;i++)
{
//erase stars
setpen(0,0,0,0,1);
moveto(midx + X[i]/OZ[i], midy + Y[i]/OZ[i]);
lineto(midx + X[i]/(OZ[i]+SPEED),midy + Y[i]/(OZ[i]+SPEED));
//draw stars
setpen(255-Z[i]*5,255-Z[i]*5,255-Z[i]*5,0,1);
moveto(midx + X[i]/Z[i], midy + Y[i]/Z[i]);
lineto(midx + X[i]/(Z[i]+SPEED),midy + Y[i]/(Z[i]+SPEED));
}
}
void run()
{
erase(0, 0, 0, 1);
for (i=0;i<STARS;i++)
{
OZ[i] = Z[i];
Z[i]-=SPEED;
if (Z[i]<=0) Z[i] = MAXDEPTH;
}
for (i=0;i<STARS;i++)
{
//draw stars
setpen(255-Z[i]*5,255-Z[i]*5,255-Z[i]*5,0,1);
moveto(midx + X[i]/Z[i], midy + Y[i]/Z[i]);
lineto(midx + X[i]/(Z[i]+SPEED),midy + Y[i]/(Z[i]+SPEED));
}
}
Users browsing this forum: No registered users and 1 guest