Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
3d text
#1
Johnno posted an old screensaver effect, so I'm doing the same Smile

It's a voxel text based on the pixels of a string printed with the default naalaa font.


Code:
' 3dtext.n7
' ---------

include "s3d.n7"

res = 480

set window "3D Text", res*min(screenw()/screenh(), 2), res, true
set redraw off

S3D_SetView(primary, rad(90), 0.1, 50)

mesh = Create3DText("NaaLaa VII", 4, 255, 255, 255, 64, 64, 96)

a = 0
while not keydown(KEY_ESCAPE)
    ay = (ay + 1)%360
    ax = (ax + 0.55)%360
   
    set color 0, 0, 0, 64
    cls
    S3D_Clear()
    S3D_Translate(0, 0, 4.5)
    S3D_Scale(0.1, 0.1, 0.1)
    S3D_RotateY(sin(rad(ay))*rad(65))
    S3D_RotateX(sin(rad(ax))*rad(22.5))
    S3D_RotateZ(sin(rad(ax*2))*rad(22.5))
    S3D_Mesh(mesh, 0)
    redraw
    fwait 60
wend

' Create3DText
' ------------
function Create3DText(txt, thickness, rtop, gtop, btop, rbtm, gbtm, bbtm)
    tex = createimage(64, 1)
    set image tex
    for x = 0 to width(tex) - 1
        p = x/width(tex)
        set color rtop*(1 - p) + rbtm*p, gtop*(1 - p) + gbtm*p, btop*(1 - p) + bbtm*p
        set pixel x, 0
    next
    set image primary
    w = fwidth(txt)
    h = fheight()
    tmpImage = createimage(w, h)
    set image tmpImage
    set color 255, 255, 255
    set caret 0, 0
    write txt
    set image primary
    maxy = 0
    for y = 0 to height(tmpImage) - 1  for x = 0 to width(tmpImage) - 1
        if Red(pixeli(tmpImage, x, y)) maxy = max(maxy, y)
    next
    mesh = S3D_BeginMesh()
    S3D_Begin(S3D_QUADS)
    S3D_Texture(tex)
    ht = thickness/2
    for y = 0 to height(tmpImage) - 1  for x = 0 to width(tmpImage) - 1
        if Red(pixeli(tmpImage, x, y))
            t = Red(pixeli(tmpImage, x, y - 1))
            b = Red(pixeli(tmpImage, x, y + 1))
            l = Red(pixeli(tmpImage, x - 1, y))
            r = Red(pixeli(tmpImage, x + 1, y))
            vx = x - w/2; vy = y - h/2
            tt = y/maxy; tb = (y + 1)/maxy
            S3D_Color(160, 160, 160)
            S3D_Vertex(vx, vy, -ht, tt, 0)
            S3D_Vertex(vx + 1, vy, -ht, tt, 0)
            S3D_Vertex(vx + 1, vy + 1, -ht, tb, 0)
            S3D_Vertex(vx, vy + 1, -ht, tb, 0)
            if not t
                S3D_Color(255, 255, 255)
                S3D_Vertex(vx, vy, ht, tt, 0)
                S3D_Vertex(vx + 1, vy, ht, tt, 0)
                S3D_Vertex(vx + 1, vy, -ht, tt, 0)
                S3D_Vertex(vx, vy, -ht, tt, 0)
            endif
            if not b
                S3D_Color(64, 64, 64)
                S3D_Vertex(vx, vy + 1, ht, tb, 0)
                S3D_Vertex(vx, vy + 1, -ht, tb, 0)
                S3D_Vertex(vx + 1, vy + 1, -ht, tb, 0)
                S3D_Vertex(vx + 1, vy + 1, ht, tb, 0)
            endif
            if not l
                S3D_Color(255, 255, 255)
                S3D_Vertex(vx, vy, ht, tt, 0)
                S3D_Vertex(vx, vy, -ht, tt, 0)
                S3D_Vertex(vx, vy + 1, -ht, tb, 0)
                S3D_Vertex(vx, vy + 1, ht, tb, 0)
            endif
            if not r
                S3D_Color(64, 64, 64)
                S3D_Vertex(vx + 1, vy, ht, tt, 0)
                S3D_Vertex(vx + 1, vy + 1, ht, tb, 0)
                S3D_Vertex(vx + 1, vy + 1, -ht, tb, 0)
                S3D_Vertex(vx + 1, vy, -ht, tt, 0)
            endif
        endif
    next
    S3D_End()
    S3D_EndMesh()
    free image tmpImage
    return mesh
endfunc

' 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
Reply
#2
Very cool indeed!!! Almost forgot about that one! Brilliant!
Logic is the beginning of wisdom.
Reply
#3
Floating letters twist and glide,
A screen saver from days gone by.
Nostalgic screens, a joy to see,
Thanks for sharing—brings back memories

Big Grin
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)