: AyaanScript+ — Spinning lit sphere demo.
: ESC quits.

const W = 800
const H = 800
gui_native "AyaanScript+ — 3D Sphere" W H
gui_fps 60

gui_3d_setup 900 400 400
gui_3d_camera 5
gui_3d_light -0.3 -0.4 -0.7
gui_3d_ambient 0.25

set ay = 0
set ax = 0.3
set az = 0
set running = 1
set frame = 0
set tstart = {time()}

while running == 1
    gui_open running
    if running == 0
        break
    endif

    gui_3d_clear "#04040f"
    gui_gradient_rect 0 0 W H "#04040f" "#0d0d2e"

    set ay = {ay + 0.014}
    gui_3d_rotate ax ay az

    : 3 lit spheres at different positions/colors
    gui_3d_sphere 0 0 0 1.4 20 "#ff6644"
    gui_3d_sphere -1.8 1.2 -0.5 0.7 14 "#44ddff"
    gui_3d_sphere 1.8 -1.0 0.3 0.6 14 "#aaff44"

    gui_text_big 20 20 "3D SPHERES" "white" 3
    gui_text 20 70 "Lit + z-buffered  |  ESC quits" "lightgray"

    set frame = {frame + 1}
    set now = {time()}
    set elapsed = {now - tstart}
    if elapsed > 0
        set fps = {int(frame / elapsed)}
        gui_text 20 92 "fps:" "white"
        gui_text 70 92 fps "yellow"
    endif

    gui_key_down "esc" -> esc
    if esc == 1
        set running = 0
    endif

    gui_update
endwhile

gui_close
