Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Things falling down
#1
I don't know, things falling down.

Code:
set window "Falling things", 480*screenw()/screenh(), 480, true
set redraw off
thing = createimage(63, 63)
set image thing
set color 0, 0, 0
cls
set color 255, 255, 255
draw ellipse 31, 31, 20, 20, true
set image primary
BoxBlur(thing, 8, 8)
set image thing
for y = 0 to height(thing) - 1  for x = 0 to width(thing) - 1
    set color 255, 255, 255, pixel(x, y)[0]
    set pixel x, y
next
set image primary
particles = []
for i = 1 to 256  particles[sizeof(particles)] = Particle(thing)
set color 32, 32, 96
cls
blura = rnd(2*PI)
while not keydown(KEY_ESCAPE)
    blura = blura + 0.01
    foreach p in particles  p.Update()
    set color 32, 32, 96, 64 + sin(blura)*32
    cls
    set additive true
    foreach p in particles  p.Draw()
    set additive false
    redraw
    fwait 60
wend

function Particle(img)
    return [
        img: img,
        x: rnd(width(primary)), y: rnd(height(primary)),
        alpha: 16 + rnd(16),
        scale: 0.25 + rnd()*1.75,
        spd: 0.25 + rnd()*2.75,
        rota: rnd(PI*2), rotspd: rnd()*0.1 - 0.05,
        offsa: rnd(PI*2), offse: rnd(128), offsspd: rnd()*0.1 - 0.05,
        Update: function()
            .y = .y + .spd
            if .y > height(primary) + height(.img)*0.5 then .y = .y - height(primary) - height(.img)
            .rota = (.rota + .rotspd)%(2*PI)
            .offsa = (.offsa + .offsspd)%(2*PI)
        endfunc,
        Draw: function()
            set color 255, 255, 255, .alpha
            draw image xform .img, .x + sin(.offsa)*.offse, .y,
                    .scale*(0.6 + sin(.rota)*0.4), .scale, .offsa, 0.5*width(.img), 0.5*height(.img)
        endfunc
        ]
endfunc

' BoxBlur
' -------
function BoxBlur(img, rx, ry)
    rx = max(int(rx), 0); ry = max(int(ry), 0)
    set image img
    w = width(img); h = height(img)
    data = dim(w, h)

    ' Blur vertically
    for y = 0 to h - 1  for x = 0 to w - 1  data[x][y] = pixeli(img, x, y)
    count = ry*2 + 1
    for x = 0 to w - 1
        sr = 0; sg = 0; sb = 0; sa = 0
        for y = -ry to ry
            p = data[x][y%h];
            sr = sr + Red(p); sg = sg + Green(p); sb = sb + Blue(p); sa = sa + Alpha(p)
        next
        for y = 0 to h - 1
            set color sr/count, sg/count, sb/count, sa/count
            set pixel x, y
            p = data[x][(y - ry)%h]
            sr = sr - Red(p); sg = sg - Green(p); sb = sb - Blue(p); sa = sa - Alpha(p)
            p = data[x][(y + ry + 1)%h]
            sr = sr + Red(p); sg = sg + Green(p); sb = sb + Blue(p); sa = sa + Alpha(p)
        next
    next
    ' Blur horizontally.
    for y = 0 to h - 1  for x = 0 to w - 1  data[x][y] = pixeli(img, x, y)
    count = rx*2 + 1
    for y = 0 to h - 1
        sr = 0; sg = 0; sb = 0; sa = 0
        for x = -rx to rx
            p = data[x%w][y]
            sr = sr + Red(p); sg = sg + Green(p); sb = sb + Blue(p); sa = sa + Alpha(p)
        next
        for x = 0 to w - 1
            set color sr/count, sg/count, sb/count, sa/count
            set pixel x, y
            p = data[(x - rx)%w][y]
            sr = sr - Red(p); sg = sg - Green(p); sb = sb - Blue(p); sa = sa - Alpha(p)
            p = data[(x + rx + 1)%w][y]
            sr = sr + Red(p); sg = sg + Green(p); sb = sb + Blue(p); sa = sa + Alpha(p)
        next
    next
    set image primary

    ' Pixeli helpers.
    function Alpha(c); return int(c/16777216); endfunc
    function Red(c); return int((c/65536))%256; endfunc
    function Green(c); return int((c/256))%256; endfunc
    function Blue(c); return c%256; endfunc
endfunc
Reply


Messages In This Thread
Things falling down - by Marcus - 01-04-2025, 09:51 AM
RE: Things falling down - by johnno56 - 01-04-2025, 01:35 PM
RE: Things falling down - by 1micha.elok - 01-05-2025, 01:50 PM
RE: Things falling down - by johnno56 - 01-05-2025, 07:00 PM
RE: Things falling down - by 1micha.elok - 01-06-2025, 01:51 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)