Saturday, August 25, 2018

Starfield Simulation in Liberty BASIC

Here is the starfield simulation that for the VIC-20 that I posted a few days ago, but ported as simply as possible to Windows using the Liberty BASIC language (http://www.libertybasic.com).  If you compare them side by side you can see that a lot of the original code is preserved across the translation.

Enjoy!

 dim st(9,1)  
 gosub [setup]  
 timer 20, [cycle]  
 [cycle]  
   for c=0 to n  
     xold=st(c,0)  
     yold=st(c,1)  
     st(c,0)=xold*1.23  
     st(c,1)=yold*1.23  
     x=int(st(c,0))  
     y=int(st(c,1))  
     if abs(x)<15 and abs(y)<15 then  
       gosub [clearStar]  
      else  
       if abs(x)>200 or abs(y)>200 then  
         st(c,0)=(rnd(1)-0.5)*3  
         st(c,1)=(rnd(1)-0.5)*3  
        else  
         gosub [drawStar]  
       end if  
     end if  
   next c  
   wait  
   goto [cycle]  
 [clearStar]  
   #starfield "color black ; place "; xCenter + xold; " "; yCenter + yold  
   #starfield "\."  
   return  
 [drawStar]  
   gosub [clearStar]  
   #starfield "color white ; place "; xCenter + x; " "; yCenter + y  
   #starfield "\."  
   return  
 [setup]  
   input"# stars (1-10)";n  
   n=n-1  
   for x=0 to n  
     st(x,0)=(rnd(1)-0.5)*200  
     st(x,1)=(rnd(1)-0.5)*200  
   next x  
   open "starfield" for graphics as #starfield  
   #starfield "home ; posxy xCenter yCenter"  
   #starfield "down ; fill black ; backcolor black"  
   #starfield "trapclose [quit]"  
   return  
 [quit]  
   close #starfield  
   end  

No comments: