Dark Bit Factory & Gravity

GENERAL => Challenges & Competitions => Topic started by: Shockwave on June 11, 2006

Title: Short Intro Challenge 3D Starfield.
Post by: Shockwave on June 11, 2006
I have one line spare here.  O0

A 3D starfield in 19 lines in freebasic..

Code: [Select]
#Include Once "tinyptc.bi"
 If( ptc_open( "DBF SCREEN", 800, 600 ) = 0 ) Then End
 dim shared strx(25000) as integer  , stry(25000) as integer , strz(25000) as double
 FOR A=1 TO 25000
     STRX(A)=-8000+RND*(16000)
     STRY(A)=-8000+RND*(16000)
     STRZ(A)=RND*(32)
 NEXT
 do     
     redim shared buffer(800*600) as integer
     FOR A=1 TO 25000
         TX=(STRX(A)/STRZ(A))+400
         TY=(STRY(A)/STRZ(A))+300
         IF TX>0 AND TX<800 AND TY>0 AND TY<600 THEN BUFFER((TY*800)+TX) = rgb (int(-STRZ(A)+30) shl 3,int(-STRZ(A)+30) shl 3,int(-STRZ(A)+30) shl 2)
         STRZ(A)=STRZ(A)-.05
         IF STRZ(A)<0 THEN STRZ(A)=STRZ(A)+30
     NEXT
 ptc_update@buffer(0)
 loop until inkey$<>""

And the exe is attached.
Title: Re: Short Intro Challenge 3D Starfield.
Post by: Optimus on June 11, 2006
I really love this one. Simple yet nicely shaded, smooth and 3d!
Title: Re: Short Intro Challenge 3D Starfield.
Post by: Tetra on June 11, 2006
Good one, I've always enjoyed the classic starfield, I was hoping it would get done  :)
Title: Re: Short Intro Challenge 3D Starfield.
Post by: Rbz on June 11, 2006
Yeah, pretty cool, congratulations for doing it in FB    8)
Title: Re: Short Intro Challenge 3D Starfield.
Post by: Shockwave on June 11, 2006
Thanks guys :)
Title: Re: Short Intro Challenge 3D Starfield.
Post by: Shockwave on June 16, 2006
Managed to squish this down to just 12 lines.
Code: [Select]
#Include Once "tinyptc.bi"
If( ptc_open( "DBF SCREEN", 800, 600 ) = 1 ) Then dim shared strx(15000) as integer  , stry(15000) as integer , strz(15000) as double
0 redim shared buffer(800*600) as integer
FOR A=1 TO 15000
     if set<15000 then STRX(A)=-8000+RND*(16000)
     if set<15000 then STRY(A)=-8000+RND*(16000)
     if set<15000 then STRZ(A)=RND*(32)         
         if set>=15000 then IF (STRX(A)/STRZ(A))+400>0 AND (STRX(A)/STRZ(A))+400<800 AND (STRY(A)/STRZ(A))+300>0 AND (STRY(A)/STRZ(A))+300<600 THEN BUFFER((int((STRY(A)/STRZ(A))+300)*800)+(int(STRX(A)/STRZ(A))+400)) = rgb (int(-STRZ(A)+30) shl 2,int(-STRZ(A)+30) shl 3,int(-STRZ(A)+30) shl 2)         
         if set>=15000 then IF STRZ(A)<0 THEN STRZ(A)=STRZ(A)+30  else STRZ(A)=STRZ(A)-.05 end if   
         if set<15000 then set=set+1 NEXT
         ptc_update@buffer(0)
if inkey$="" then 0

It can be gotten down to 10 lines by combining the generation lines but it gets really messy then and it's bad enough as it is!!