NaaLaa
Fireworks - Printable Version

+- NaaLaa (https://www.naalaa.com/forum)
+-- Forum: NaaLaa (https://www.naalaa.com/forum/forum-1.html)
+--- Forum: NaaLaa 7 Code (https://www.naalaa.com/forum/forum-4.html)
+--- Thread: Fireworks (/thread-182.html)



Fireworks - Marcus - 01-02-2025

Happy new year, a bit late!

Code:
#win32
set window "2025", 640, 480
set redraw off
particles = []; t = 60
while not keydown(KEY_ESCAPE, true)
    t = t - 1
    if t <= 0
        particles[sizeof(particles)] = Firework(true, particles,
                rnd(width(primary)), height(primary))
        t = 30 + rnd(4)*30
    endif
    i = 0
    while i < sizeof(particles)
        if particles[i].Update()  i = i + 1
        else  free key particles, i
    wend
    set color 0, 0, 0, 16; cls
    foreach p in particles  p.Draw()
    redraw
    fwait 60
wend

function Firework(goingUp, list, x, y)
    if goingUp  a = 225 + rnd(90)
    else  a = rnd(360)
    p = [
        goingUp: goingUp, list: list,
        x: x, y: y,
        dx: cos(rad(a)), dy: sin(rad(a)),
        r: 128 + rnd(128), g: 128 + rnd(128), b: 128 + rnd(128), a: 255, spd: 0.5 + rnd()*0.5,
        Update: function()
            if .goingUp
                .x = .x + .dx*0.5; .y = .y + .dy*4; .dy = .dy + 0.005
                if .dy >= 0.25
                    for i = 1 to 100
                        .list[sizeof(.list)] = Firework(false, .list, .x, .y)
                    next
                    return false
                else
                    return true
                endif
            else
                .x = .x + .dx*.spd; .y = .y + .dy*.spd; .dy = .dy + 0.005
                .a = .a - 1.5*.spd
                return .a > 0
            endif
        endfunc,
        Draw: function()
            set color .r, .g, .b, .a
            draw pixel .x, .y
        endfunc]
    return p
endfunc

Some sound effects would be nice ...


RE: Fireworks - johnno56 - 01-02-2025

No. Never too late for an excellent firework display!! Well done!!

Found this sound file on OpenGameArt.org. The site user is "Rubberduck"

https://opengameart.org/content/25-cc0-bang-firework-sfx

Converted the fw_loop.ogg to .wav


.zip   fw_loop.wav.zip (Size: 1.75 MB / Downloads: 2)

Hope this is ok...

J


RE: Fireworks - 1micha.elok - 01-02-2025

The fireworks were so amazing, I’m pretty sure NASA called to ask who launched them!
They were so spectacular,  even the stars were jealous and took a coffee break!

Big Grin


RE: Fireworks - johnno56 - 01-02-2025

Mmmm... Coffee...