Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Snowflakes
#1
Here are some spare snowflakes, plenty of them in Sweden!

Something very similar was written in n6 many years ago.

Code:
' Snowflakes
' ----------

include "list.n7"

#win32

constant BG_R = 16, BG_G = 24, BG_B = 64

set window "Snowflakes", 480*screenw()/screenh(), 480, true
set redraw off

snowflakeImage = loadimage("snowflake.png")

stars = List()
for i = 1 to 200  stars.Add([x: rnd()*2 - 1, y: rnd()*2 - 1, z: 0.1 + rnd()*0.9])

set color BG_R, BG_G, BG_B
cls

do
    for i = 0 to stars.size - 1
        s = stars[i]
        s.z = s.z - 0.01
        if s.z < 0.1
            s.z = s.z + 0.9
            s.x = rnd()*2 - 1
            s.y = rnd()*2 - 1
        endif
    next
    stars.Sort(function(a, b)
            return b.z - a.z
        endfunc)
   
    set color BG_R, BG_G, BG_B, 96
    cls
    wp = width(primary)/2
    hp = height(primary)/2
    for i = 0 to stars.size - 1
        s = stars[i]
        x = wp + s.x*wp/s.z*0.75
        y = hp + s.y*hp/s.z*0.75
        size = 16/s.z
        set color BG_R, BG_G, BG_B, s.z*255
        DrawScaledImage(snowflakeImage, x - size/2, y - size/2, size, size)
    next
    fwait 60
    redraw
until keydown(KEY_ESCAPE) or mousebutton(0)

function DrawScaledImage(img, x, y, w, h)
    du = 1/w
    u = 0
    for dx = 0 to w - 1
        draw vraster img, x + dx, y, y + h - 1, u, 0, u, 1
        u = u + du
    next
endfunc


Attached Files
.zip   snowflakes.zip (Size: 7.75 KB / Downloads: 7)
Reply


Messages In This Thread
Snowflakes - by Marcus - 12-09-2023, 11:15 AM
RE: Snowflakes - by johnno56 - 12-09-2023, 12:00 PM
RE: Snowflakes - by 1micha.elok - 12-21-2023, 10:25 AM
RE: Snowflakes - by johnno56 - 12-21-2023, 06:15 PM
RE: Snowflakes - by Marcus - 12-22-2023, 12:43 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)