: AyaanScript+ — Bouncing Balls (clean version)
: 6 colorful balls with gravity, wall bouncing, damping, color trails.

const W = 800
const H = 600
gui_native "AyaanScript+ — Bouncing Balls" W H
gui_fps 60

set N = 6
list xs   = [120, 280, 440, 600, 200, 540]
list ys   = [80, 120, 60, 100, 200, 150]
list vxs  = [4.0, -3.5, 5.0, -4.2, 3.0, -5.5]
list vys  = [0, 0, 0, 0, 0, 0]
list rads = [28, 22, 30, 25, 20, 26]
list cols = ["#ff5577", "#55ccff", "#ffcc44", "#88ff77", "#cc77ff", "#ff9944"]

set gravity = 0.45
set damping = 0.88
set running = 1

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

    : sky gradient background
    gui_gradient_rect 0 0 W H "#0a0a25" "#1a1f40"

    : ground strip
    gui_fill_rect 0 580 800 20 "#0a0a14"

    : title
    gui_text_big 20 20 "BOUNCING BALLS" "white" 2
    gui_text 20 60 "ESC to quit" "lightgray"

    : draw + update each ball
    set i = 0
    repeat N i
        set k = {i - 1}
        list_at xs   k -> bx
        list_at ys   k -> by
        list_at vxs  k -> bvx
        list_at vys  k -> bvy
        list_at rads k -> br
        list_at cols k -> bc

        : physics
        set bvy = {bvy + gravity}
        set bx  = {bx + bvx}
        set by  = {by + bvy}

        : floor bounce w/ damping
        set floor = {580 - br}
        if by > floor
            set by  = floor
            set bvy = {0 - bvy * damping}
        endif
        : ceiling
        if by < br
            set by  = br
            set bvy = {0 - bvy}
        endif
        : walls
        if bx < br
            set bx  = br
            set bvx = {0 - bvx}
        endif
        set right = {W - br}
        if bx > right
            set bx  = right
            set bvx = {0 - bvx}
        endif

        : draw ball
        gui_fill_circle bx by br bc

        : white highlight (top-left of each ball)
        set hx = {bx - br / 3}
        set hy = {by - br / 3}
        set hr = {br / 4}
        gui_fill_circle hx hy hr "white"

        : persist
        lset xs  k bx
        lset ys  k by
        lset vxs k bvx
        lset vys k bvy
    endrepeat

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

    gui_update
endwhile

gui_close
psyska -/ "Done."
