Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Accretion Disk
#11
Quote:
Quote:pset might be slow. but this program is quite good enough! i have a 15-year-old laptop which originally came with windows8. running this under linux/debian.
Nice, ive got a 2004 xp IBM i still use too and happily advocate using old tech for new purposes! However i dont agree that for this program PSet "is good enough" heck when i get my gl 3.3 iteration of this done it'll handle 10 MILLION objects just as fast as Qb64 handles 10 thousand and as such allow for much more detail, realism and in NO way will detract from or impact the original code that has inspired it. Heck i made a version already that had a sun in orbit of the black hole that got eaten and added to the mass and angular momentum...Heck even making this _GL sub and using a 1*1 texture and scaling would not only add the Perspective view it lacks but also allow for vastly more particles and realism such as culling etc...

I dont try to be offensive but have a internal "It can be better" thing that i cannot ignore. Declare Library is there for this very reason, to allow people like ME to still contribute without feeling that we/I am hacking the language I grew up on so please dont criticise me for taking an admittedly AMAZING bit of code and trying to do my best to improve it. 

John

Final Pset version : Now with basically everything i know about gravity, local clusters, the blackhole grows and gains angular momentum etc...only thing i havent added is Hawking Radiation

Code: (Select All)
' QB64 - 45-DEGREE ISOMETRIC GALAXY (3D CINEMATIC)
' ---------------------------------------------------------------------------
wd = 1024
ht = 768
SCREEN _NEWIMAGE(wd, ht, 32)
_TITLE "Sagittarius A* - 45 Degree Isometric Projection"

' --- CONSTANTS ---
G = 4.0: M_SagA = 9000: RS = 40
tilt = 0.707 ' Sine of 45 degrees for the isometric tilt
vecs = 22000

DIM Px(vecs), Py(vecs), Pz(vecs), Vx(vecs), Vy(vecs), Vz(vecs), PType(vecs)

' --- INITIALIZE 3D GALAXY ---
FOR i = 0 TO vecs
  GOSUB ResetParticle
NEXT i

DO
  ' Starfield background persistence
  LINE (0, 0)-(wd, ht), _RGBA32(0, 0, 0, 45), BF

  FOR i = 0 TO vecs
    ' --- 3D PHYSICS (X, Y, Z) ---
    r_3d = SQR(Px(i) * Px(i) + Py(i) * Py(i) + Pz(i) * Pz(i))

    IF r_3d < RS THEN
      GOSUB ResetParticle

    END IF

    ' Gravity pull toward 0,0,0
    mag = (G * M_SagA) / (r_3d * r_3d)
    Vx(i) = Vx(i) - (Px(i) / r_3d) * mag
    Vy(i) = Vy(i) - (Py(i) / r_3d) * mag
    Vz(i) = Vz(i) - (Pz(i) / r_3d) * mag

    Px(i) = Px(i) + Vx(i)
    Py(i) = Py(i) + Vy(i)
    Pz(i) = Pz(i) + Vz(i)

    ' --- 45 DEGREE ISOMETRIC PROJECTION ---
    ' We project X and Y, but use Z and Tilt to create the 3D look
    sX = (wd / 2) + Px(i)
    sY = (ht / 2) + (Py(i) * tilt) - (Pz(i) * tilt)

    ' --- DEPTH COLORING ---
    ' Farther stars (negative Py) are dimmer, Closer stars are brighter
    depth_fade = 150 + (Py(i) / 4)
    IF depth_fade > 255 THEN depth_fade = 255
    IF depth_fade < 50 THEN depth_fade = 50

    IF sX > 0 AND sX < wd AND sY > 0 AND sY < ht THEN
      IF PType(i) = 1 THEN ' Core Stars
        PSET (sX, sY), _RGBA32(255, 220, 150, depth_fade)
      ELSE ' Spiral Arm Dust
        PSET (sX, sY), _RGBA32(100, 150, 255, depth_fade / 2)
      END IF
    END IF
  NEXT i

  ' --- RENDER THE CORE (SAGITTARIUS A*) ---
  ' Tilt the event horizon to match the galaxy
  FOR r_l = RS TO 0 STEP -2
    ' Ellipse instead of Circle to simulate the 45-degree tilt
    FOR a = 0 TO 6.28 STEP 0.2
      ex = (wd / 2) + COS(a) * r_l
      ey = (ht / 2) + SIN(a) * r_l * tilt
      PSET (ex, ey), _RGB32(0, 0, 0)
    NEXT a
  NEXT r_l

  _DISPLAY
  _LIMIT 60
LOOP UNTIL _KEYDOWN(27)
END

ResetParticle:
' Spiral Math with 3D "Bulge"
angle = RND * 6.283
dist = RS + 40 + (RND * 450)
spiral = dist * 0.04
Px(i) = COS(angle + spiral) * dist
Py(i) = SIN(angle + spiral) * dist
' Pz creates the "vertical" thickness of the galaxy (thicker in middle)
Pz(i) = (RND - 0.5) * (RS * 4) * (1 - dist / 500)

v_orb = SQR((G * M_SagA) / dist)
Vx(i) = -SIN(angle + spiral) * v_orb
Vy(i) = COS(angle + spiral) * v_orb
Vz(i) = (RND - 0.5) * 0.1 ' Slight vertical drift
IF dist < RS * 3 THEN PType(i) = 1 ELSE PType(i) = 0
RETURN
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)