Welcome, Guest |
You have to register before you can post on our site.
|
Forum Statistics |
» Members: 37
» Latest member: Ludwig
» Forum threads: 195
» Forum posts: 1,498
Full Statistics
|
Online Users |
There are currently 65 online users. » 0 Member(s) | 64 Guest(s) Bing
|
|
|
3D Breakout, just a quick test |
Posted by: Marcus - 02-01-2025, 04:52 PM - Forum: NaaLaa 7 Code
- Replies (6)
|
 |
Just the basic functionality of a 3d breakout game.
Code: ' breakout3d.n7
' -------------
include "s3d.n7"
include "sfx.n7"
constant FPS_CAP = 60
constant MOUSE_SENS = 1 ' Modify this if mouse sensitivity feels wrong
visible vSfx = SFX()
visible vSoundMaxD = 32
visible vRes = 480
visible vRedBrickImage, vGreenBrickImage, vBlueBrickImage, vBallImage, vPaddleImage
visible vWhiteImage
visible vFloorImage
visible vPaddleSound, vWallSound, vBrickHitSound, vBrickDestroyedSound
visible vPaddleX, vPaddleZ, vPaddleW
visible vCamX, vCamY, vCamZ, vCamYaw, vCamPitch
set window "Breakout 3D", vRes*screenw()/screenh(), vRes, true
set redraw off
LoadAssets()
S3D_SetView(primary, rad(60), 0.1, 30)
cube = S3D_BeginMesh()
S3D_Scale(0.5, 0.5, 0.5)
S3D_Translate(1, -1, 1)
S3D_Begin(S3D_QUADS)
' Top face.
S3D_Vertex(1, -1, 1, 1, 1)
S3D_Vertex(1, -1, -1, 1, 0)
S3D_Vertex(-1, -1, -1, 0, 0)
S3D_Vertex(-1, -1, 1, 0, 1)
' Front face.
S3D_Vertex(1, -1, -1, 1, 0)
S3D_Vertex(1, 1, -1, 1, 1)
S3D_Vertex(-1, 1, -1, 0, 1)
S3D_Vertex(-1, -1, -1, 0, 0)
' Left face.
S3D_Vertex(-1, 1, 1, 1, 1)
S3D_Vertex(-1, -1, 1, 0, 1)
S3D_Vertex(-1, -1, -1, 0, 0)
S3D_Vertex(-1, 1, -1, 1, 0)
' Right face.
S3D_Vertex(1, 1, -1, 1, 0)
S3D_Vertex(1, -1, -1, 0, 0)
S3D_Vertex(1, -1, 1, 0, 1)
S3D_Vertex(1, 1, 1, 1, 1)
' Done drawing quads.
S3D_End()
S3D_EndMesh()
paddle = S3D_BeginMesh()
S3D_Scale(0.5, 0.25, 0.25)
S3D_Translate(0, -1, 0)
S3D_Begin(S3D_QUADS)
' Top face.
S3D_Vertex(1, -1, 1, 1, 1)
S3D_Vertex(1, -1, -1, 1, 0)
S3D_Vertex(-1, -1, -1, 0, 0)
S3D_Vertex(-1, -1, 1, 0, 1)
' Front face.
S3D_Vertex(1, -1, -1, 1, 0)
S3D_Vertex(1, 1, -1, 1, 1)
S3D_Vertex(-1, 1, -1, 0, 1)
S3D_Vertex(-1, -1, -1, 0, 0)
' Left face.
S3D_Vertex(-1, 1, 1, 0.25, 1)
S3D_Vertex(-1, -1, 1, 0, 1)
S3D_Vertex(-1, -1, -1, 0, 0)
S3D_Vertex(-1, 1, -1, 0.25, 0)
' Right face.
S3D_Vertex(1, 1, -1, 0.25, 0)
S3D_Vertex(1, -1, -1, 0, 0)
S3D_Vertex(1, -1, 1, 0, 1)
S3D_Vertex(1, 1, 1, 0.25, 1)
' Done drawing quads.
S3D_End()
S3D_EndMesh()
visible vBricks = fill(unset, 15, 10, 3)
for x = 0 to 14 for z = 0 to 9 for y = 0 to 2
if y = 0 and rnd(2) = 0 or y > 0 and vBricks[x][z][y - 1] and rnd(2) = 0
select rnd(3)
case 0 vBricks[x][z][y] = [st: 1, m: cube, t: vRedBrickImage, offs: 0, ht: 0]
case 1 vBricks[x][z][y] = [st: 2, m: cube, t: vGreenBrickImage, offs: 0, ht: 0]
case 2 vBricks[x][z][y] = [st: 3, m: cube, t: vBlueBrickImage, offs: 0, ht: 0]
endsel
endif
next
visible vLastTick = 0
vCamX = 7.5
vCamZ = -8.5
vCamY = -8
vCamPitch = -rad(45)
vCamYaw = 0
vPaddleX = 7.5
vPaddleZ = -5
vPaddleW = 2
ball = [x: 7.5, z: -2, dx: 1, dz: 1, spd: 5]
k = 1/sqr(ball.dx^2 + ball.dz^2)
ball.dx = ball.dx*k; ball.dz = ball.dz*k
balls = []
balls[sizeof(balls)] = ball
set mouse off
while not keydown(KEY_ESCAPE, true)
dt = DeltaTime()
mdx = mouserelx()
set mouse width(primary)/2, height(primary)/2
vPaddleX = min(max(vPaddleX + min(mdx*0.075*MOUSE_SENS, 0.5), vPaddleW/2), 15 - vPaddleW/2)
vCamX = vCamX*0.975 + vPaddleX*0.025
' camz can be modified a bit by the ball position
vCamYaw = -rad(5*(vPaddleX - 7.5)/7.5)
i = 0; while i < sizeof(balls)
if UpdateBall(ball, dt) i = i + 1
else free key balls, i
wend
set color 0, 0,0
cls
S3D_Clear()
S3D_RotateX(-vCamPitch)
S3D_RotateY(-vCamYaw)
S3D_Translate(-vCamX, -vCamY, -vCamZ)
S3D_Texture(vFloorImage)
S3D_SetDepthBuffer(S3D_Z_BUFFER_WRITE)
S3D_SetSorting(S3D_NONE)
S3D_Begin(S3D_QUADS)
S3D_Color(255, 255, 255)
S3D_Vertex(0, 0.05, -6, 0, 1)
S3D_Vertex(0, 0.05, 10, 0, 0)
S3D_Vertex(15, 0.05, 10, 1, 0)
S3D_Vertex(15, 0.05, -6, 1, 1)
S3D_End()
S3D_Render()
S3D_SetSorting(S3D_NONE)
S3D_SetDepthBuffer(S3D_Z_BUFFER)
for x = 0 to 14 for z = 0 to 9 for y = 0 to 2
b = vBricks[x][z][y]
if b
if b.offs > 0
b.spd = b.spd + 7*dt
b.offs = max(b.offs - b.spd*dt, 0)
endif
S3D_Push()
S3D_Translate(x, -(y + b.offs), z)
if b.ht
b.ht = max(b.ht - 1, 0)
S3D_Texture(vWhiteImage)
else
S3D_Texture(b.t)
endif
S3D_Mesh(b.m, 0)
S3D_Pop()
endif
next
S3D_Push()
S3D_Translate(vPaddleX, 0, vPaddleZ)
S3D_Scale(vPaddleW, 1, 1)
S3D_Texture(vPaddleImage)
S3D_Mesh(paddle, 0)
S3D_Pop()
foreach ball in balls
S3D_Push()
S3D_Translate(ball.x, -0.25, ball.z)
S3D_RotateY(vCamYaw)
S3D_RotateX(vCamPitch)
S3D_Texture(vBallImage)
S3D_Color(255, 255, 255)
S3D_Begin(S3D_QUADS)
S3D_Vertex(0.25, -0.25, 0, 1, 0)
S3D_Vertex(0.25, 0.25, 0, 1, 1)
S3D_Vertex(-0.25, 0.25, 0, 0, 1)
S3D_Vertex(-0.25, -0.25, 0, 0, 0)
S3D_End()
S3D_Pop()
next
S3D_Render()
set caret 0, 0
set color 255, 255, 255
wln int(1/dt)
redraw
' no fps cap might affect mouse input on fast computers, maybe wait more than 1?
if FPS_CAP > 0 fwait FPS_CAP
else wait 1
wend
' UpdateBall
' ----------
function UpdateBall(ball, dt)
' Move in z.
ball.z = ball.z + dt*ball.dz*ball.spd
if ball.dz < 0
iz = floor(ball.z - 0.25)
if iz >= 0 and iz < 10
ixl = floor(ball.x - 0.25); ixr = floor(ball.x + 0.25)
if ixl >= 0 and ixl < 15 and vBricks[ixl][iz][0]
HitBrick(ixl, iz)
ball.z = iz + 1 + 0.251; ball.dz = |ball.dz|
endif
if ixr >= 0 and ixr < 15 and vBricks[ixr][iz][0]
HitBrick(ixr, iz)
ball.z = iz + 1 + 0.251; ball.dz = |ball.dz|
endif
elseif iz < -10
ball.z = -10 + 0.251; ball.dz = |ball.dz|
endif
elseif ball.dz > 0
iz = floor(ball.z + 0.25)
if iz >= 0 and iz < 10
ixl = floor(ball.x - 0.25); ixr = floor(ball.x + 0.25)
if ixl >= 0 and ixl < 15 and vBricks[ixl][iz][0]
HitBrick(ixl, iz)
ball.z = iz - 0.251; ball.dz = -|ball.dz|
endif
if ixr >= 0 and ixr < 15 and vBricks[ixr][iz][0]
HitBrick(ixr, iz)
ball.z = iz - 0.251; ball.dz = -|ball.dz|
endif
elseif iz >= 10
ball.z = 10 - 0.251; ball.dz = -|ball.dz|
PlaySound3D(vWallSound, 1, ball.x, 0.25, ball.z, vSoundMaxD)
endif
endif
' Move in x.
ball.x = ball.x + dt*ball.dx*ball.spd
if ball.dx < 0
ix = floor(ball.x - 0.25)
if ix >= 0 and ix < 15
izt = floor(ball.z - 0.25); izb = floor(ball.z + 0.25)
if izt >= 0 and izt < 10 and vBricks[ix][izt][0]
HitBrick(ix, izt)
ball.x = ix + 1 + 0.251; ball.dx = |ball.dx|
endif
if izb >= 0 and izb < 10 and vBricks[ix][izb][0]
HitBrick(ix, izb)
ball.x = ix + 1 + 0.251; ball.dx = |ball.dx|
endif
elseif ix < 0
ball.x = 0.251; ball.dx = |ball.dx|
PlaySound3D(vWallSound, 1, ball.x, 0.25, ball.z, vSoundMaxD)
endif
elseif ball.dx > 0
ix = floor(ball.x + 0.25)
if ix >= 0 and ix < 15
izt = floor(ball.z - 0.25); izb = floor(ball.z + 0.25)
if izt >= 0 and izt < 10 and vBricks[ix][izt][0]
HitBrick(ix, izt)
ball.x = ix - 0.251; ball.dx = -|ball.dx|
endif
if izb >= 0 and izb < 10 and vBricks[ix][izb][0]
HitBrick(ix, izb)
ball.x = ix - 0.251; ball.dx = -|ball.dx|
endif
elseif ix >= 15
ball.x = 15 - 0.251; ball.dx = -|ball.dx|
PlaySound3D(vWallSound, 1, ball.x, 0.25, ball.z, vSoundMaxD)
endif
endif
dx = (ball.x - vPaddleX)/(vPaddleW*0.5 + 0.25)
if |dx| < 1 and ball.dz < 0 and ball.z > vPaddleZ and ball.z - vPaddleZ < 0.5
ball.dx = dx*2.5
ball.dz = 1
k = 1/sqr(ball.dx^2 + ball.dz^2)
ball.dx = ball.dx*k; ball.dz = ball.dz*k
PlaySound3D(vPaddleSound, 1, ball.x, 0.25, ball.z, vSoundMaxD)
endif
return true
endfunc
' HitBrick
' --------
function HitBrick(x, z)
b = vBricks[x][z][0]
if b and b.ht = 0 and b.offs < 0.5
b.st = b.st - 1
if b.st > 0
b.ht = 10
PlaySound3D(vBrickHitSound, 1, x + 0.5, 0.5 + b.offs, z + 0.5, vSoundMaxD)
else
for i = 0 to 1
vBricks[x][z][i] = vBricks[x][z][i + 1]
if vBricks[x][z][i]
if vBricks[x][z][i].offs = 0
vBricks[x][z][i].spd = 0
endif
vBricks[x][z][i].offs = vBricks[x][z][i].offs + 1
endif
next
vBricks[x][z][2] = unset
PlaySound3D(vBrickDestroyedSound, 1, x + 0.5, 0.5 + b.offs, z + 0.5, vSoundMaxD)
endif
endif
endfunc
function DeltaTime()
t = clock()
dt = (min(t - vLastTick, 100))/1000
vLastTick = t
return dt
endfunc
' LoadAssets
' ----------
function LoadAssets()
' Make bricks less and less bright for each hit.
vRedBrickImage = createimage(32, 32)
set image vRedBrickImage
set color 32, 0, 32; cls
set color 255, 255, 255; draw rect 0, 0, 32, 32, false
set color 255, 0, 128; draw rect 1, 1, 30, 30, false
set color 128, 0, 0; draw rect 2, 2, 28, 28, false
set image primary
BoxBlur(vRedBrickImage, 3, 3)
vGreenBrickImage = createimage(32, 32)
set image vGreenBrickImage
set color 32, 16, 0; cls
set color 255, 255, 255; draw rect 0, 0, 32, 32, false
set color 255, 128, 0; draw rect 1, 1, 30, 30, false
set color 128, 0, 0; draw rect 2, 2, 28, 28, false
set image primary
BoxBlur(vGreenBrickImage, 3, 3)
vBlueBrickImage = createimage(32, 32)
set image vBlueBrickImage
set color 0, 16, 32; cls
set color 255, 255, 255; draw rect 0, 0, 32, 32, false
set color 0, 128, 255; draw rect 1, 1, 30, 30, false
set color 0, 0, 128; draw rect 2, 2, 28, 28, false
set image primary
BoxBlur(vBlueBrickImage, 3, 3)
vBallImage = createimage(31, 31)
set image vBallImage
set color 255, 255, 255; cls
set color 16, 16, 16; draw ellipse 15, 15, 11, 11, true
set image primary
BoxBlur(vBallImage, 4, 4)
set image vBallImage
set color 255, 0, 255
for y = 0 to 30 for x = 0 to 30
d = sqr((x - 15)^2 + (y - 15)^2)
if d >= 14.5 set pixel x, y
next
set image primary
set image colorkey vBallImage, 255, 0, 255
data = MD_Generate(257, 1, 0.1, 52)
vFloorImage = createimage(256, 256)
set image vFloorImage
for y = 0 to 255 for x = 0 to 255
c = data[x][y]
if int(y/17 + x/17)%2 = 0
set color c*4, c*16, c*32
else
set color c*2, c*8, c*16
endif
set pixel x, y
next
set image primary
BoxBlur(vFloorImage, 2, 2)
vPaddleImage = createimage(128, 32)
set image vPaddleImage
set color 0, 8, 32; cls
set color 204, 0, 0
draw rect 0, 0, 32, 32, true; draw rect 96, 0, 32, 32, true
set color 255, 255, 255, 204
draw rect 0, 0, 32, 32; draw rect 1, 1, 30, 30; draw rect 2, 2, 28, 28
draw rect 96, 0, 32, 32; draw rect 97, 1, 30, 30; draw rect 98, 2, 28, 28
set color 0, 64, 255, 128
draw rect 32, 0, 64, 32; draw rect 33, 1, 62, 30; draw rect 34, 2, 60, 28
set image primary
BoxBlur(vPaddleImage, 3, 3)
vWhiteImage = createimage(32, 32)
set image vWhiteImage
set color 255, 255, 255
cls
set image primary
' create sound effects.
vSfx.SetEcho(3, 0.25, 0.1, 0.25)
vPaddleSound = vSfx.SineWave(0.2, [400, 100, 200], [1, 0])
vWallSound = vSfx.SineWave(0.15, [200, 100, 400], [0.5, 0])
vBrickHitSound = vSfx.SquareWave(0.15, [150, 100, 50], [0.25, 0, 0])
vBrickDestroyedSound = vSfx.Noise(0.3, [1000, 100, 500], [1, 0])
endfunc
' PlaySound3D
' -----------
function PlaySound3D(snd, vol, x, y, z, maxd)
dx = x - vCamX; dy = y - vCamY; dz = z - vCamZ
d = dx*dx + dy*dy + dz*dz
if d >= maxd*maxd return
if d > 0
d = sqr(d); k = 1.0/d
dx = dx*k; dy = dy*k; dz = dz*k
d = (maxd - min(maxd, d))/maxd
cp = cos(vCamPitch)
pan = (cos(vCamYaw)*cp*dx - sin(vCamYaw)*cp*dz)*0.9
else
d = 1
pan = 0
endif
play sound snd, vol*d, pan
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
function MD_Generate(size, contrast, smooth, seed)
randomize seed
contrast = max(min(contrast, 1), 0)
smooth = 1 - max(min(smooth, 1), 0)
md = dim(size, size)
md[0][0] = 0.5 + contrast*rnd() - contrast*0.5
md[size - 1][0] = 0.5 + contrast*rnd() - contrast*0.5
md[size - 1][size - 1] = 0.5 + contrast*rnd() - contrast*0.5
md[0][size - 1] = 0.5 + contrast*rnd() - contrast*0.5
MD_Rec(md, 0, 0, size - 1, size - 1, contrast, smooth)
return md
function MD_Rec(md, xmin, ymin, xmax, ymax, contrast, smooth)
if xmax - xmin <= 1 return
if ymax - ymin <= 1 return
hw = (xmin + xmax)/2
hh = (ymin + ymax)/2
md[hw][hh] = (md[xmin][ymin] + md[xmax][ymin] + md[xmax][ymax] + md[xmin][ymax])*0.25 + contrast*rnd() - contrast*0.5
md[hw][hh] = max(md[hw][hh], 0)
md[hw][hh] = min(md[hw][hh], 1)
md[xmin][hh] = (md[xmin][ymin] + md[xmin][ymax])*0.5
md[xmax][hh] = (md[xmax][ymin] + md[xmax][ymax])*0.5
md[hw][ymin] = (md[xmin][ymin] + md[xmax][ymin])*0.5
md[hw][ymax] = (md[xmin][ymax] + md[xmax][ymax])*0.5
MD_Rec(md, xmin, ymin, hw, hh, contrast*smooth, smooth)
MD_Rec(md, hw, ymin, xmax, hh, contrast*smooth, smooth)
MD_Rec(md, xmin, hh, hw, ymax, contrast*smooth, smooth)
MD_Rec(md, hw, hh, xmax, ymax, contrast*smooth, smooth)
endfunc
endfunc
|
|
|
Render on an image before sending to screen |
Posted by: bul71 - 01-27-2025, 10:21 AM - Forum: NaaLaa 6 Questions
- Replies (4)
|
 |
Hi.
I'm currently trying to make my drawing logic on an image of logical window dimensions then if the game runs in windowed mode, I just send this image on the window but if the game runs in fullscreen, I try to send this image on an image with the screen dimensions after applying code to calculate vertical or horizontal margins depending on the difference in aspect ratios between the physical screen and the window.
My windowed mode works fine.
In fullscreen :
-----------------
I succefully prepare graphics on the window sized image then send it to physical screen image then on the screen but I'm not able the fit the logical image on the screen size and place it accordingly with the margins.
Can you show me the way to do it properlly ?
Thank you.
|
|
|
Repurposed Sprite Editor |
Posted by: johnno56 - 01-23-2025, 07:57 PM - Forum: NaaLaa 7 Code
- Replies (13)
|
 |
Marcus,
Back in December of 2024, I mention that I was having difficulty(s), with my Sprite Editor. The fix you provided worked like a charm... The project has been "gathering dust" since then because of lack of planning on my part. Creating an editor without considering, "Do I have the skill set to complete it?" The answer was a resounding "NO."...
Then I got to thinking (Ok, you can stop laughing now... very funny...) that the Sprite Editor is very similar to a Tile Map Editor. Mind you, a bare-bones, editor... lol Functions like, New, Load, Save, Quit, Draw and Erase tile... Seeing that Wolf3D does not seem to have a Editor per se, maybe the Sprite Editor, could be repurposed?
Here is my idea: Wolf3D uses a standard 64x64 tiled "map". Single level (ie: no layers). The Sprite Editor is already configured for a 64x64 "pixel" display. Give the different walls etc a specific colour. "Draw" the wall "pixel" etc to create the "map". Scan the main grid to convert it to a 64x64 character text grid then convert that grid to the standard Wolf3D "map = [[ ]]" layout.
No prizes for guessing that I have already started... kind of... The four main function are working (sort of) and the selection of the "tiles" can be drawn and erased. Saving and loading are my biggest issues at the moment... After all - it's only been 1 day... lol
I realize that EngineA already has a Tile Based editor and was wondering if your intentions are focused more toward that type of game creation than the Wolf3D game style? Reason: If the focus is on EngineA then it would be illogical to continue with the W3D editor... What do you think? Is a W3D editor a kind of "re-inventing the wheel" type of deal?
|
|
|
Thunderbird Methuselah (Game of Life) |
Posted by: 1micha.elok - 01-17-2025, 11:22 AM - Forum: NaaLaa 7 Code
- Replies (7)
|
 |
click each image to zoom in
CONWAY'S GAME OF LIFE
Just a quick conversion to N7
Reference :
"Thunderbird" methuselah evolution in the Game of Life
https://rosettacode.org/wiki/Conway%27s_...e#BASIC256
Code: '==============================================================
' CONWAY'S GAME OF LIFE
' Just a quick conversion to N7
'
' Reference :
' "Thunderbird" methuselah evolution in the Game of Life
' https://rosettacode.org/wiki/Conway%27s_Game_of_Life#BASIC256
'==============================================================
'set window
#win32
set window "Game of Life",236,140,true
set redraw off
'color definition
black = [0,0,0]
white = [255,255,255]
purple = [128,0,128]
green = [0,255,0]
red = [255,0,0]
yellow = [255,255,0]
X = 59 ; Y = 35 ; H = 4
c = dim(X,Y)
cn = dim(X,Y)
cl = dim(X,Y)
'Thunderbird methuselah pattern
c[X/2-1][Y/3+1] = 1
c[X/2][Y/3+1] = 1
c[X/2+1][Y/3+1] = 1
c[X/2][Y/3+3] = 1
c[X/2][Y/3+4] = 1
c[X/2][Y/3+5] = 1
'initial value
s = 0
start = 1
'main loop
do
'clear screen
set color black
cls
alive = 0
stable = 1
s = s + 1
for y = 0 to Y-1
for x = 0 to X-1
xm1 = (x-1+X)%X
xp1 = (x+1+X)%X
ym1 = (y-1+Y)%Y
yp1 = (y+1+Y)%Y
cn[x][y] = c[xm1][y] + c[xp1][y]
cn[x][y] = c[xm1][ym1] + c[x][ym1] + c[xp1][ym1] + cn[x][y]
cn[x][y] = c[xm1][yp1] + c[x][yp1] + c[xp1][yp1] + cn[x][y]
if c[x][y] = 1 then
if cn[x][y] < 2 or cn[x][y] > 3 then
cn[x][y] = 0
else
cn[x][y] = 1
alive = alive + 1
endif
else
if cn[x][y] = 3 then
cn[x][y] = 1
alive = alive + 1
else
cn[x][y] = 0
endif
endif
if c[x][y] then
if cn[x][y] then
if cl[x][y] then
set color purple # adult
endif
if not cl[x][y] then
set color green # newborn
endif
else
if cl[x][y] then
set color red # old
endif
if not cl[x][y] then
set color yellow # shortlived
endif
endif
draw rect x*H,y*H,H,H,true
endif
next
next
redraw
fwait 10
# Copy arrays
for i = 0 to X-1
for j = 0 to Y-1
if cl[i][j]<>cn[i][j] then stable = 0
cl[i][j] = c[i][j]
c[i][j] = cn[i][j]
next
next
if start then
set color white
set caret width()/2, height()-15
center "Press Enter to Continue"
redraw
do;wait 1;until keydown(KEY_RETURN,true)
start = false
endif
until not alive or stable
'final message
set color white
set caret width()/2,height()-15
if not alive then
center "Died in "+s+" iterations"
else
center "Stabilized in "+(s-2)+" iterations"
endif
redraw
'Escape to quit
do;wait 1;until keydown(KEY_ESCAPE,true)
|
|
|
Irregular Beauty |
Posted by: 1micha.elok - 01-07-2025, 12:46 AM - Forum: NaaLaa 7 Code
- Replies (2)
|
 |
IRREGULAR BEAUTY 3D
Beyond isometric, the world unfolds,
In 3D grace, its secrets told.
Irregular forms, yet beauty reigns,
Elegance shines where chaos remains.
click the image to zoom-in
Code: '==================================================
' IRREGULAR BEAUTY 3D
' Beyond isometric, the world unfolds,
' In 3D grace, its secrets told.
' Irregular forms, yet beauty reigns,
' Elegance shines where chaos remains.
'
' References :
' - Pillars s3d (Marcus)
'==================================================
#win32
'library
include "s3d.n7"
'window size
set window "Irregular Beauty 3D", 480*screenw()/screenh(), 480, false
set redraw off
'color definition
black = [0,0,0]
white = [255,255,255]
'set up 3D view
S3D_SetView(primary, rad(90), 0.1, 360)
S3D_SetPerspectiveCorrection(S3D_NORMAL)
'cube 3D
cube = S3D_BeginMesh()
S3D_Translate(0, -1, 0)
S3D_Begin(S3D_QUADS)
S3D_Color(0,0,0) 'bottom
S3D_Vertex(1, 1, -1, 0, 0)
S3D_Vertex(1, 1, 1, 0, 0)
S3D_Vertex(-1, 1, 1, 0, 0)
S3D_Vertex(-1, 1, -1, 0, 0)
S3D_Color(200, 200, 0) 'top color
S3D_Vertex(1, -1, 1, 0, 0)
S3D_Vertex(1, -1, -1, 0, 0)
S3D_Vertex(-1, -1, -1, 0, 0)
S3D_Vertex(-1, -1, 1, 0, 0)
S3D_Color(200, 200, 0) 'back
S3D_Vertex(1, 1, 1, 0, 0)
S3D_Vertex(1, -1, 1, 0, 0)
S3D_Vertex(-1, -1, 1, 0, 0)
S3D_Vertex(-1, 1, 1, 0, 0)
S3D_Color(150, 150, 0) 'front color
S3D_Vertex(1, -1, -1, 0, 0)
S3D_Vertex(1, 1, -1, 0, 0)
S3D_Vertex(-1, 1, -1, 0, 0)
S3D_Vertex(-1, -1, -1, 0, 0)
S3D_Color(60, 60, 0) 'left color
S3D_Vertex(-1, 1, 1, 0, 0)
S3D_Vertex(-1, -1, 1, 0, 0)
S3D_Vertex(-1, -1, -1, 0, 0)
S3D_Vertex(-1, 1, -1, 0, 0)
S3D_Color(60, 60, 0) 'right color
S3D_Vertex(1, 1, -1, 0, 0)
S3D_Vertex(1, -1, -1, 0, 0)
S3D_Vertex(1, -1, 1, 0, 0)
S3D_Vertex(1, 1, 1, 0, 0)
S3D_End()
S3D_EndMesh()
'-----------
' MAIN LOOP
'-----------
while not keydown(KEY_ESCAPE, true)
angleA = (angleA + 90*0.01)%360
S3D_Clear()
'clear screen
set color black;cls
set color white
'rotate
S3D_RotateX(rad(90))
S3D_RotateY(rad(135))
'the whole pillars translation
S3D_Translate(-43,83,-45)
for z = 0 to 30 - 1
for x = 0 to 30 - 1
'pattern
d = ((15-x) ^ 2 + (15-z) ^ 2) ^ 0.5
s = 1.5*sin(d*2+rad(angleA))+2
S3D_Push()
S3D_Translate(x*3, 0, z*3)
S3D_Scale(1.2, s, 1.2)
S3D_Mesh(cube,0)
S3D_Pop()
next
next
S3D_Render()
redraw
fwait 60
wend
|
|
|
Burning polygon mess |
Posted by: Marcus - 01-06-2025, 08:41 AM - Forum: NaaLaa 7 Code
- Replies (3)
|
 |
Code: visible vPolyT = dim(64)
set window "Burning polygon mess", screenw()/screenh()*512, 512, true
set redraw off
set color 0, 8, 32
cls
particles = []
while not keydown(KEY_ESCAPE)
i = 0
while i < sizeof(particles)
if particles[i].Update() i = i + 1
else free key particles, i
wend
particles[sizeof(particles)] = FireParticle(width(primary)/2, height(primary) - 64)
set color 0, 8, 32, 96
cls
set additive true
foreach p in particles p.Draw()
set additive false
redraw
fwait 60
wend
function FireParticle(x, y)
p = []
p.pts = []
for i = 1 to 3 + rnd(4)
p.pts[sizeof(p.pts)] = (rnd() - 0.5)*48
p.pts[sizeof(p.pts)] = (rnd() - 0.5)*48
next
p.x = x + rnd(32) - 16; p.y = y + rnd(32) - 16
p.a = rnd(2*PI); p.as = (rnd() - 0.5)*0.2
p.dx = (rnd() - 0.5)*2; p.dy = (rnd() - 0.75)*2
p.r = 96; p.g = 80; p.b = 64
p.fi = 0; p.p = 0
p.Update = function()
.x = .x + .dx; .y = .y + .dy
.r = 8 + (.r - 8)*0.98; .g = 8 + (.g - 8)*0.96; .b = 8 + (.b - 8)*0.9
.dx = .dx*0.975; .dy = max(.dy - 0.01, - 4)
.a = .a + .as
.fi = min(.fi + 0.05, 1); .p = .p + 0.003
if .p >= 1 return false
return true
endfunc
p.Draw = function()
set color .r, .g, .b, .fi*(1 - .p)*255
DrawPolyXForm(.pts, .x, .y, (1 - .p)*2, 2, .a, false)
endfunc
return p
endfunc
' n7 needs something like this in its core: 'draw poly xform', 'draw poly image xform'
function DrawPolyXForm(points, x, y, sx, sy, a, scaleFirst)
if scaleFirst
for i = 0 to sizeof(points)/2 - 1
px = points[i*2]*sx; py = points[i*2 + 1]*sy
vPolyT[i*2] = x + px*cos(a) - py*sin(a)
vPolyT[i*2 + 1] = y + py*cos(a) + px*sin(a)
next
else
for i = 0 to sizeof(points)/2 - 1
px = points[i*2]; py = points[i*2 + 1]
vPolyT[i*2] = x + (px*cos(a) - py*sin(a))*sx
vPolyT[i*2 + 1] = y + (py*cos(a) + px*sin(a))*sy
next
endif
draw poly vPolyT, true, sizeof(points)/2
endfunc
|
|
|
Things falling down |
Posted by: Marcus - 01-04-2025, 09:51 AM - Forum: NaaLaa 7 Code
- Replies (4)
|
 |
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
|
|
|
|