|
Post by Carl Gundel on Feb 17, 2020 9:56:42 GMT -5
This is already less than 1K, but how small can it be? 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
|
|
|
Post by Rod on Feb 17, 2020 14:56:47 GMT -5
440 bytes
dim s(99,3) open "" for graphics_fs_nsb as #s #s "home;posxy x y;down;fill black;backcolor black;trapclose [q]" [l] scan for i=0 to 99 s(i,2)=s(i,0):s(i,3)=s(i,1):s(i,0)=s(i,0)*1.23+.01:s(i,1)=s(i,1)*1.23 if abs(s(i,0))>DisplayWidth/2 then s(i,0)=(rnd(0)-0.5)*3 : s(i,1)=(rnd(0)-0.5)*3 #s "color black;place ";x+s(i,2);" ";y+s(i,3);" ;\." #s "color white;place ";x+s(i,0);" ";y+s(i,1);" ;\." next goto [l]
[q] close #s end
|
|
|
Post by tsh73 on Feb 18, 2020 2:51:23 GMT -5
385
dim s(99,3):open "" for graphics_fs_nsb as #s #s "home;posxy x y;down;fill black;trapclose [q];size 2;rule xor" [l]scan:for i=0 to 99 s(i,2)=s(i,0):s(i,3)=s(i,1):s(i,0)=s(i,0)*1.23+.01:s(i,1)=s(i,1)*1.23 if abs(s(i,0))>DisplayWidth/2 then s(i,0)=(rnd(0)-0.5)*3:s(i,1)=(rnd(0)-0.5)*3 #s "set ";x+s(i,2);" ";y+s(i,3);";set ";x+s(i,0);" ";y+s(i,1) next goto [l] [q] close #s:end
|
|
|
Post by Rod on Feb 18, 2020 3:40:46 GMT -5
|
|
|
Post by David Drake on Feb 18, 2020 7:22:03 GMT -5
I agree. tsh73 did a fine job with this.
|
|
|
Post by Carl Gundel on Feb 18, 2020 13:47:15 GMT -5
385 dim s(99,3):open "" for graphics_fs_nsb as #s #s "home;posxy x y;down;fill black;trapclose [q];size 2;rule xor" [l]scan:for i=0 to 99 s(i,2)=s(i,0):s(i,3)=s(i,1):s(i,0)=s(i,0)*1.23+.01:s(i,1)=s(i,1)*1.23 if abs(s(i,0))>DisplayWidth/2 then s(i,0)=(rnd(0)-0.5)*3:s(i,1)=(rnd(0)-0.5)*3 #s "set ";x+s(i,2);" ";y+s(i,3);";set ";x+s(i,0);" ";y+s(i,1) next goto [l] [q] close #s:end
Nice. Slightly smaller still at 374 bytes. Who needs END? Standing on the shoulders of giants. dim s(99,3):open "" for graphics_fs_nsb as #s #s "home;posxy x y;down;fill black;trapclose [q];size 2;rule xor" while 1:scan s(i,2)=s(i,0):s(i,3)=s(i,1):s(i,0)=s(i,0)*1.2+.01:s(i,1)=s(i,1)*1.2 if abs(s(i,0))>DisplayWidth/2 then s(i,0)=(rnd(0)-.5)*3:s(i,1)=(rnd(0)-.5)*3 #s "set ";x+s(i,2);" ";y+s(i,3);";set ";x+s(i,0);" ";y+s(i,1) i=(i+1)mod 100 wend [q] close #s
|
|
|
Post by Rod on Feb 18, 2020 14:08:52 GMT -5
330/326 Slight cheat down from 99 to 9 stars, sans dim, but faster! 326 without end.
open "" for graphics_fs_nsb as #s #s "home;posxy x y;down;fill black;trapclose [q];rule xor" [l] scan:z(i)=x(i):w(i)=y(i):x(i)=x(i)*1.2+.01:y(i)=y(i)*1.2 if abs(x(i))>DisplayWidth/2 then x(i)=(rnd(0)-.5)*3:y(i)=(rnd(0)-.5)*3 #s "set ";x+z(i);" ";y+w(i);";set ";x+x(i);" ";y+y(i) i=(i+1)mod 10 goto [l] [q] close #s:end
|
|
|
Post by David Drake on Feb 18, 2020 14:27:41 GMT -5
Eliminating the _fs_nsb and a little housekeeping gets the LOF down to 318.
open "" for graphics as #s:#s "home;posxy x y;down;fill black;trapclose [q];rule xor" [l] scan:z(i)=x(i):w(i)=y(i):x(i)=x(i)*1.2+.01:y(i)=y(i)*1.2:if abs(x(i))>DisplayWidth/2 then x(i)=(rnd(0)-.5)*3:y(i)=(rnd(0)-.5)*3 #s "set ";x+z(i);" ";y+w(i);";set ";x+x(i);" ";y+y(i):i=(i+1)mod 10:goto [l] [q] close #s:end
|
|
|
Post by Carl Gundel on Feb 18, 2020 14:35:18 GMT -5
330/326 Slight cheat down from 99 to 9 stars, sans dim, but faster! 326 without end. open "" for graphics_fs_nsb as #s #s "home;posxy x y;down;fill black;trapclose [q];rule xor" [l] scan:z(i)=x(i):w(i)=y(i):x(i)=x(i)*1.2+.01:y(i)=y(i)*1.2 if abs(x(i))>DisplayWidth/2 then x(i)=(rnd(0)-.5)*3:y(i)=(rnd(0)-.5)*3 #s "set ";x+z(i);" ";y+w(i);";set ";x+x(i);" ";y+y(i) i=(i+1)mod 10 goto [l] [q] close #s:end
Clever, but it's so fast now that it doesn't look like a starfield simulation.
|
|
|
Post by Rod on Feb 18, 2020 14:39:02 GMT -5
You will never get anywhere in this universe unless you are travelling really really fast!
|
|
|
Post by Carl Gundel on Feb 18, 2020 15:05:56 GMT -5
318 bytes. The loop is too fast so I moved a bunch of graphics command inside the loop to slow it down.
dim s(99,3):open "" for graphics_fs_nsb as #s [l] #s "discard;fill black" for i=0 to 99:scan:s(i,0)=s(i,0)*1.2+.01:s(i,1)=s(i,1)*1.2 if abs(s(i,0))>1000 then s(i,0)=(rnd(0)-.5)*3:s(i,1)=(rnd(0)-.5)*3 #s "home;posxy x y;down;trapclose [q];size 2;color white;set ";x+s(i,0);" ";y+s(i,1) next:goto [l] [q]close #s
This approach doesn't look as nice as the rule xor way, but it is smaller.
|
|
|
Post by Carl Gundel on Feb 18, 2020 15:09:23 GMT -5
Adding two bytes to make it three times as many stars makes a huge improvement in how it looks. 320 bytes
dim s(299,3):open "" for graphics_fs_nsb as #s [l] #s "discard;fill black" for i=0 to 299:scan:s(i,0)=s(i,0)*1.2+.01:s(i,1)=s(i,1)*1.2 if abs(s(i,0))>1000 then s(i,0)=(rnd(0)-.5)*3:s(i,1)=(rnd(0)-.5)*3 #s "home;posxy x y;down;trapclose [q];size 2;color white;set ";x+s(i,0);" ";y+s(i,1) next:goto [l] [q]close #s
|
|
|
Post by Carl Gundel on Feb 18, 2020 15:21:26 GMT -5
Thanks for all the interesting starfield simulation submissions guys. Nice work!
|
|
|
Post by tsh73 on Feb 18, 2020 15:31:24 GMT -5
312. With XOR we don't need other array for points.
dim x(99),y(99):open "" for graphics_fs as #s:#s "home;posxy x y;down;fill black;trapclose [q];rule xor" [l] scan:#s "set ";x+x(i);" ";y+y(i):x(i)=x(i)*1.2+.01:y(i)=y(i)*1.2:if abs(x(i))>DisplayWidth/2 then x(i)=(rnd(0)-.5)*3:y(i)=(rnd(0)-.5)*3 #s "set ";x+x(i);" ";y+y(i):i=(i+1)mod 100:goto [l] [q] close #s
|
|
|
Post by Carl Gundel on Feb 18, 2020 15:37:41 GMT -5
301 dim x(99),y(99):open "" for graphics_fs as #s:#s "home;posxy x y;down;fill black;trapclose [q];rule xor" [l] scan:#s "set ";x+x(i);" ";y+y(i):x(i)=x(i)*1.2+.01:y(i)=y(i)*1.2:if abs(x(i))>999 then x(i)=(rnd(0)-.5)*3:y(i)=(rnd(0)-.5)*3 #s "set ";x+x(i);" ";y+y(i):i=(i+1)mod 100:goto [l] [q] close #s
|
|