Things falling down - Marcus - 01-04-2025
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
RE: Things falling down - johnno56 - 01-04-2025
Cool... Reminds me of a "close up" of a snow globe... Nicely done...
Almost hypnotic... hypnotic... hpy...
RE: Things falling down - 1micha.elok - 01-05-2025
Things Falling Down
Let things fall and let them fade
For in that fall, new dreams are made
The ground may catch what once soared high
But from that place, we learn to fly
RE: Things falling down - johnno56 - 01-05-2025
Very poetic... I was immediately reminded of the silly quote, "If at first you don't succeed, skydiving is not for you". (Well... it involved flying, falling and ground... almost poetic, right?) lol
RE: Things falling down - 1micha.elok - 01-06-2025
Perhaps ....
the blend of a hobbyist game developer and poet writer—
crafting epic quests in code and rhyming the Zen of Naalaa
Code: '===================================
' THE ZEN OF NAALAA
'
' ACKNOWLEDGEMENTS :
' - Things Falling Down by Marcus
' - Star Text Effect 3D by Marcus
'===================================
include "s3d.n7"
'set window title, width, height, fullscreen
set window "The Zen of Naalaa", 800, 600, false
set redraw off
'image : thing
thing = createimage(63, 63)
set image thing
set color 0, 0, 0
cls
set color 150, 150, 150
draw ellipse 31, 31, 20, 20, true
set image primary
'make it blur
BoxBlur(thing, 8, 8)
'reimage : thing
set image thing
for y = 0 to height(thing) - 1 for x = 0 to width(thing) - 1
set color 150, 150, 150, 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)
' create font and a texture (image).
set font createfont("arial", 16, true)
tex = createimage(500, 400)
' set target image to the one we created and write some
' text to it.
set image tex
set color 255, 255, 255
set caret 128, 0
wln "The Zen of Naalaa"
wln ""
wln "Simple is better than complex."
wln "Commands are few, but their meaning is deep."
wln "Let your code flow like water,"
wln "With purpose, with order"
wln ""
wln "Arrays have been replaced with tables"
wln "consist of key and value pairs"
wln "Migrating to Naalaa"
wln "shouldn't be much of problem"
wln ""
wln "Variables may change type at any time"
wln "And every variable is a treasure,"
wln "Every byte, a reminder"
wln "Of the beauty in the language"
wln ""
wln "A FOR loop is a poem,"
wln "A THEN is a moment of truth."
wln "WRITE not for the machine,"
wln "But for the understanding between you."
' set image to primary (window) again.
set image primary
set image colorkey tex,0,0,0
' Init s3d.
S3D_SetView(primary, rad(90), 0.1, 2)
S3D_SetPerspectiveCorrection(S3D_NORMAL)
' text z, scroll value.
textZ = 0
' size of text quad.
sizeX = 1
sizeZ = height(tex)/width(tex)
'-----------
' Main Loop
'-----------
while not keydown(KEY_ESCAPE)
blura = blura + 0.01
foreach p in particles p.Update()
set color 32, 32, 96, 100 + sin(blura)
cls
set additive true
foreach p in particles p.Draw()
set additive false
' scroll.
if textZ < 1 then
textZ = textZ + 0.001
else
textZ = 0
endif
S3D_Clear()
S3D_Texture(tex)
S3D_Color(255, 255, 255)
S3D_RotateX(rad(40))
S3D_Translate(0, 0.5, textZ)
S3D_Begin(S3D_QUADS)
S3D_Vertex(-sizeX*0.5, 0, 0, 0, 0)
S3D_Vertex(sizeX*0.5, 0, 0, 1, 0)
S3D_Vertex(sizeX*0.5, 0, -sizeZ, 1, 1)
S3D_Vertex(-sizeX*0.5, 0, -sizeZ, 0, 1)
S3D_End()
S3D_Render()
'info box
set caret 10,10
wln textZ
redraw
fwait 20
wend
'-----------
' Functions
'-----------
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
|