Dark Bit Factory & Gravity

PROGRAMMING => Other languages => Yabasic => Topic started by: bikemadness on May 06, 2026

Title: 3D Starfield
Post by: bikemadness on May 06, 2026
Done to death, but this is my first.

I finally figuured something out.

Code: [Select]
star=200
dim r(star)
dim x(star)
dim y(star)
dim l(star)
dim d(star)
dim s(star)
dim m(star)

for a=1 to star
r(a)=int(ran(360))*(pi/180)
l(a)=int(ran(400))+160
d(a)=ran(1)-int(ran(2)) rem height
s(a)=ran(2)+2 rem couples with l(a) s(a)/l(a)
m(a)=.005
next a

x=320
y=256

open window 640,512
repeat
setdrawbuf vm
vm=1-vm
setdispbuf vm
clear window

for a=1 to star
x(a)=cos(r(a))/(sin(r(a))+s(a))*l(a)+x
y(a)=d(a)/(sin(r(a))+s(a))*l(a)+y
next a

for a=1 to star
r(a)=r(a)+m(a)
if m(a)>360 m(a)=0
next a

for a=1 to star
dot x(a),y(a)
next a

until (1=0)
Title: Re: 3D Starfield
Post by: Shockwave on May 08, 2026
Well done, that's great  :)

This is rotating around the Z axis, if you move dots whilst also rotating it gives a nice variation of the effect.
This one is doing a Y rotation whilst moving the plots around:

https://www.youtube.com/watch?v=onO0gKbtGuU


Title: Re: 3D Starfield
Post by: bikemadness on May 08, 2026
Thanks. Its taken me years to get head around it.

The first one I saw was on the PS2 demo disc.

The code just blew me away.

I still have a number of those disks.