: AyaanScript+ — SMOOTH 3D scene with native pipeline:
:   - Z-buffered triangle rasterization (proper depth occlusion)
:   - Lambertian lighting baked in (faces darker when angled away from light)
:   - Native shape: gui_3d_cube does all 12 triangles + shading per frame
:   - 800x800 @ 60fps — all the heavy math runs in Rust, not interpreted
: ESC quits.

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

: configure 3D pipeline once
gui_3d_setup 800 400 400
gui_3d_camera 6
gui_3d_light -0.4 -0.6 -0.7
gui_3d_ambient 0.45

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

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

    : sky gradient + clear z-buffer
    gui_3d_clear "#0a0a1f"
    gui_gradient_rect 0 0 W 200 "#0a0a1f" "#1a1f4a"

    : update rotation in script, push to engine
    set ay = {ay + 0.013}
    set ax = {ax + 0.009}
    set az = {az + 0.005}
    gui_3d_rotate ax ay az

    : render TWO cubes side by side, different colors
    gui_3d_cube -1.5 0 0 1.6 "#ff5599"
    gui_3d_cube 1.5 0 0 1.6 "#55ccff"

    : render a sphere above them
    gui_3d_cube 0 -1.6 0 1.0 "#ffcc44"

    : HUD on top (rendered AFTER 3D so it overlays)
    gui_text_big 20 20 "SMOOTH 3D" "white" 3
    gui_text 20 70 "Lambertian shading + z-buffer" "lightgray"
    gui_text 20 88 "ESC quits  |  ARROWS rotate" "lightgray"

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

    : input
    gui_key_down "esc" -> esc
    if esc == 1
        set running = 0
    endif
    gui_key_down "left" -> kl
    gui_key_down "right" -> kr
    gui_key_down "up" -> ku
    gui_key_down "down" -> kd
    if kl == 1
        set ay = {ay - 0.06}
    endif
    if kr == 1
        set ay = {ay + 0.06}
    endif
    if ku == 1
        set ax = {ax - 0.06}
    endif
    if kd == 1
        set ax = {ax + 0.06}
    endif

    gui_update
endwhile

gui_close
psyska -/ "Goodbye."
