: AyaanScript+ — Native particle system demo.
: gui_particle_* runs entirely in Rust — handle 5000+ particles smoothly.
: Click to spawn a burst of particles at cursor position.

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

set running = 1
set last_mouse = 0
set frame = 0
set autoframe = 0

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

    gui_gradient_rect 0 0 W H "#000010" "#1a0033"

    : auto-burst at random spot every 30 frames
    set autoframe = {autoframe + 1}
    if autoframe > 30
        rand ax 100 700
        rand ay 100 500
        rand colidx 0 4
        if colidx == 0
            gui_particle_burst ax ay 60 "#ff5577" 5 80
        endif
        if colidx == 1
            gui_particle_burst ax ay 60 "#55ccff" 5 80
        endif
        if colidx == 2
            gui_particle_burst ax ay 60 "#ffcc44" 5 80
        endif
        if colidx == 3
            gui_particle_burst ax ay 60 "#88ff77" 5 80
        endif
        if colidx == 4
            gui_particle_burst ax ay 60 "#cc77ff" 5 80
        endif
        set autoframe = 0
    endif

    : mouse click bursts
    gui_mouse_down lmb
    if lmb == 1
        if last_mouse == 0
            gui_mouse_x mx
            gui_mouse_y my
            gui_particle_burst mx my 80 "#ffffff" 7 100
        endif
        set last_mouse = 1
    else
        set last_mouse = 0
    endif

    gui_particle_update
    gui_particle_draw

    : HUD
    gui_text_big 20 20 "PARTICLES" "white" 2
    gui_text 20 55 "CLICK to spawn  |  ESC quits" "lightgray"
    gui_particle_count n
    gui_text 20 75 "particles:" "white"
    gui_text 110 75 n "yellow"

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

    set frame = {frame + 1}
    gui_update
endwhile

gui_close
