Author Topic: messing around with dot tunnel code  (Read 778 times)

0 Members and 1 Guest are viewing this topic.

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1307
  • Karma: 96
    • View Profile
messing around with dot tunnel code
« on: November 22, 2016 »
what started out as meant to be some sort of tunnel code but with some modification. No idea what it is.

Code: [Select]
const pi2=3.141592*2.0

type star
as single x,y,z
as ulong colour(0 to 100),shade
as single radius
as single num_points
end type

type starfield
as integer num_stars
as star ptr star_list
as single max_z,min_z,z_speed
as ulong colourmap(0 to 255)
as ulong colourindex(0 to 100)
as ulong colourdelta(0 to 100)
end type

function create_starfield(byval num_stars as integer,_
byval radius as single,_
byval num_points as single,_
byval max_z as single,_
byval min_z as single,_
byval z_speed as single)as starfield ptr
dim as starfield ptr starfield=new starfield
starfield->star_list=new star[num_stars]
for star as integer=0 to num_stars-1
starfield->star_list[star].radius=radius+radius*sin(star/num_stars*pi2)
starfield->star_list[star].num_points=num_points
starfield->star_list[star].z=min_z+((max_z-min_z)/num_stars)*star
next
starfield->max_z=max_z
starfield->min_z=min_z
starfield->z_speed=z_speed
starfield->num_stars=num_stars
for i as integer=0 to 255
    dim as ulong red,gre,blu
    red=128+127*sin(i/256.0*3.141592*4)
    gre=128+127*sin(i/256.0*3.141592*2)
    blu=128+127*cos(i/256.0*3.141592*2)
    starfield->colourmap(i)=(red shl 16)or(gre shl 8) or blu
next
for i as integer=0 to 100
    starfield->colourindex(i)=rnd*&hffff
    starfield->colourdelta(i)=rnd*&hfff
next
return starfield
end function

sub process_starfield(byval starfield as starfield ptr)
static as single angle=0
static as single amplitude_angle=0
static as single horizontal_angle=0
static as single vertical_angle=0
for star_count as integer=0 to starfield->num_stars-1
dim as star pointer star=@starfield->star_list[star_count]
star->z-=starfield->z_speed
star->x+=(rnd-.5)*10.0
star->y+=(rnd-.5)*10.0
star->shade=(star->shade*&hfa)shr 8
if star->z<starfield->min_z then
    for i as integer=0 to star->num_points-1
        star->colour(i)=starfield->colourmap(starfield->colourindex(i) shr 8)
        'starfield->colourindex(i)=(starfield->colourindex(i)+starfield->colourdelta(i))and &hffff
    next
   
star->shade=&hffff
star->z+=starfield->max_z-starfield->min_z
star->x=(100+300*sin(amplitude_angle))*sin(angle)+300*sin(horizontal_angle)
star->y=(100+300*sin(amplitude_angle))*cos(angle)+300*sin(vertical_angle)

angle+=0.01
amplitude_angle+=.0086
horizontal_angle+=.013
vertical_angle+=0.0043

end if
next

    for i as integer=0 to 100
        'star->colour(i)=starfield->colourmap(starfield->colourindex(i) shr 8)
        starfield->colourindex(i)=(starfield->colourindex(i)+starfield->colourdelta(i))and &hffff
    next
   
end sub

sub draw_starfield(byval starfield as starfield pointer)
dim as integer w=any,h=any
screeninfo (w,h)
for star_count as integer=0 to starfield->num_stars-1
dim as star pointer star=@starfield->star_list[star_count]
for p as single=0 to star->num_points-1
dim as single x=(w shr 1)+w*(star->x+star->radius*sin(p*pi2/star->num_points))/star->z
dim as single y=(h shr 1)-w*(star->y+star->radius*cos(p*pi2/star->num_points))/star->z
dim as ulong c=star->shade shr 8
dim as ulong col=star->colour(p)
pset (x,y),((((col and &hff00ff)*c)and &hff00ff00)or(((col and &hff00)*c)and &hff0000))shr 8
next
next
end sub

sub main
screenres 640,480,32,2
screenset 0,1
dim as starfield ptr starfield=create_starfield(300,400,7,2000,10,50)
for i as integer=0 to 1000
process_starfield(starfield)
next
dim as single t=timer
while inkey<>chr(27)
    while t<timer
        process_starfield(starfield)
        t+=0.02
        wend
draw_starfield(starfield)
flip
cls
wend
end sub

main

or

Code: [Select]
const pi2=3.141592*2.0

type star
as single x,y,z,rotation
as ulong colour(0 to 100),shade
as single radius
as single num_points
end type

type starfield
as integer num_stars
as star ptr star_list
as single max_z,min_z,z_speed
as ulong colourmap(0 to 255)
as ulong colourindex(0 to 100)
as ulong colourdelta(0 to 100)
end type

function create_starfield(byval num_stars as integer,_
byval radius as single,_
byval num_points as single,_
byval max_z as single,_
byval min_z as single,_
byval z_speed as single)as starfield ptr
dim as starfield ptr starfield=new starfield
starfield->star_list=new star[num_stars]
for star as integer=0 to num_stars-1
starfield->star_list[star].radius=radius+radius*sin(star*pi2/num_stars)
starfield->star_list[star].rotation=star*pi2/num_stars*2
starfield->star_list[star].num_points=num_points
starfield->star_list[star].z=min_z+((max_z-min_z)/num_stars)*star
next
starfield->max_z=max_z
starfield->min_z=min_z
starfield->z_speed=z_speed
starfield->num_stars=num_stars
for i as integer=0 to 255
    dim as ulong red,gre,blu
    red=128+127*sin(i/256.0*3.141592*4)
    gre=128+127*sin(i/256.0*3.141592*2)
    blu=128+127*cos(i/256.0*3.141592*2)
    starfield->colourmap(i)=(red shl 16)or(gre shl 8) or blu
next
for i as integer=0 to 100
    starfield->colourindex(i)=rnd*&hffff
    starfield->colourdelta(i)=rnd*&hfff
next
return starfield
end function

sub process_starfield(byval starfield as starfield ptr)

static as single angle=0
static as single amplitude_angle=0
static as single horizontal_angle=0
static as single vertical_angle=0
for star_count as integer=0 to starfield->num_stars-1
dim as star pointer star=@starfield->star_list[star_count]
star->z-=starfield->z_speed
star->x+=(rnd-.5)*10.0
star->y+=(rnd-.5)*10.0
star->shade=(star->shade*&hf0)shr 8
if star->z<starfield->min_z then
    for i as integer=0 to star->num_points-1
        star->colour(i)=starfield->colourmap(starfield->colourindex(i) shr 8)
        'starfield->colourindex(i)=(starfield->colourindex(i)+starfield->colourdelta(i))and &hffff
    next
   
star->shade=&hffff
star->z+=starfield->max_z-starfield->min_z
star->x=(100+300*sin(amplitude_angle))*sin(angle)+300*sin(horizontal_angle)
star->y=(100+300*sin(amplitude_angle))*cos(angle)+300*sin(vertical_angle)

angle+=0.01
amplitude_angle+=.0086
horizontal_angle+=.013
vertical_angle+=0.0043

end if
next

    for i as integer=0 to 100
        'star->colour(i)=starfield->colourmap(starfield->colourindex(i) shr 8)
        starfield->colourindex(i)=(starfield->colourindex(i)+starfield->colourdelta(i))and &hffff
    next
   
end sub

sub draw_starfield(byval starfield as starfield pointer)
dim as integer w=any,h=any
screeninfo (w,h)
for star_count as integer=0 to starfield->num_stars-1
dim as star pointer star=@starfield->star_list[star_count]
for p as single=0 to star->num_points-1
dim as single x=(w shr 1)+w*(star->x+star->radius*sin(star->rotation+p*pi2/star->num_points))/star->z
dim as single y=(h shr 1)-w*(star->y+star->radius*cos(star->rotation+p*pi2/star->num_points))/star->z
dim as ulong c=star->shade shr 8
dim as ulong col=star->colour(p)
pset (x,y),((((col and &hff00ff)*c)and &hff00ff00)or(((col and &hff00)*c)and &hff0000))shr 8
next
next
end sub

sub main
screenres 640,480,32,2
screenset 0,1
dim as starfield ptr starfield=create_starfield(800,180,12,1000,10,10)
for i as integer=0 to 1000
process_starfield(starfield)
next
dim as single t=timer
while inkey<>chr(27)
    while t<timer
        process_starfield(starfield)
        t+=0.02
        wend
draw_starfield(starfield)
flip
cls
wend
end sub

main

« Last Edit: November 22, 2016 by Stonemonkey »