## Starfield with trails

angros47
Posts: 1890
Joined: Jun 21, 2005 19:04

### Starfield with trails

Very simple starfield effect, made using the old school trick of color cycling. Use PgUp and PgDown to set the speed.

Code: Select all

`const w=800: const h=600screenres w, h, 8Dim pal(0 To 255) As Integerdim as single x, y, c, sx, sy, scc=1.0for i as integer=1 to 300   x=w/2: y=h/2   sx=(rnd()*2.0)-1.0   sy=(rnd()*2.0)-1.0   sc=rnd()   do      x+=sx: y+=sy: c+=sc      if c>255.0 then c-=254.0      pset (x,y), c   loop until x<0 orelse x>w orelse y<0 orelse y>hnextdim t as singledim speed as single=.01do   palette using pal   dim d as integer=&hFF0000-(speed *100)   for i as integer=1 to 255      if pal(i) then pal(i)=pal(i)/20*19 and &hFF0000   next   t= (t+speed)    if t>=255.0 then t-=254.0   pal (t+.5)=&hFFFFFF   if multikey(&h49) andalso speed <1 then speed+=.001   if multikey(&h51) andalso speed >0.001 then speed-=.001   'screensync   sleep 1loop until multikey(1)`
dafhi
Posts: 1400
Joined: Jun 04, 2005 9:51

### Re: Starfield with trails

neat! had to tweak. also looks cool with the lines uncommented

Code: Select all

`   var rad = .01 + 250 * rnd   var ang = rnd * tau   sx = cos(ang)   sy = sin(ang)   x=w/2 + rad * sx   y=h/2 + rad * sy   rad = rnd + .1   sx *= rad   sy *= rad   'sx = (rnd()*2.0)-1.0   'sy = (rnd()*2.0)-1.0`
integer
Posts: 394
Joined: Feb 01, 2007 16:54
Location: usa

### Re: Starfield with trails

dafhi wrote:neat! had to tweak. also looks cool with the lines uncommented

Code: Select all

`   var rad = .01 + 250 * rnd   var ang = rnd * tau   sx = cos(ang)   sy = sin(ang)   x=w/2 + rad * sx   y=h/2 + rad * sy   rad = rnd + .1   sx *= rad   sy *= rad   'sx = (rnd()*2.0)-1.0   'sy = (rnd()*2.0)-1.0`

Just curious.
What is your initial value for "tau"?
angros47
Posts: 1890
Joined: Jun 21, 2005 19:04

### Re: Starfield with trails

tau is a math constant: it is equal to 2*pi, or 6.28318530718