Steve's 3D Print - SMcNeill - 04-27-2022
Inspired by Petr's 3D printing, I sat down and worked up a simple little routine to make pseudo-3d text of my own, and I wrapped it up into a single neat little SUB with 3 zillion parameters...
Code: (Select All) SCREEN _NEWIMAGE(1024, 720, 32)
_SCREENMOVE _MIDDLE
OE20 = _LOADFONT("calibri.ttf", 72)
_FONT OE20
Print3D 100, 100, "Hello World", 10, 10, OE20, &HFFFFFF00, 1, 1, 1, 1
Print3D 100, 200, "Steve is Awesome!", 5, -10, OE20, &HFFFF0000, -1, 1, 1, 1.25
Print3D 100, 300, "So, what do you guys think?", 6, 0, OE20, &HFFFFFFFF, 1, .5, .5, .5
Print3D 100, 400, "No 3D, just *italic* style text.", 1, 20, OE20, &HFF00FF00, 0, 0, 1, 1
SUB Print3D (x AS INTEGER, y AS INTEGER, text$, thick AS INTEGER, tilt AS INTEGER,_
f AS LONG, fg AS _UNSIGNED LONG, xchange as integer, ychange as integer,_
scalex as _float, scaley as _float)
DIM copy AS INTEGER
DIM dx1 AS _FLOAT, dx2 AS _FLOAT, dy1 AS _FLOAT, dy2 AS _FLOAT
d = _DEST: s = _SOURCE: font = _FONT
copy = _NEWIMAGE(_WIDTH, _HEIGHT, 32)
_DEST copy: _SOURCE copy
_FONT f
sx1 = 0: sy1 = 0
sx2 = _PRINTWIDTH(text$, copy): sy2 = _FONTHEIGHT(f)
dx1 = x: dy1 = y
dx2 = x + sx2 * scalex: dy2 = y + sy2 * scaley
FOR i = thick TO 0 STEP -1
CLS , 0
COLOR _RGBA32(_RED32(fg), _GREEN32(fg), _BLUE32(fg), 155 + 100 / i), 0
PRINT text$
_MAPTRIANGLE (sx1, sy1)-(sx2, sy1)-(sx1, sy2), copy TO(dx1 + tilt, dy1)-(dx2 + tilt, dy1)-(dx1, dy2), d
_MAPTRIANGLE (sx1, sy2)-(sx2, sy1)-(sx2, sy2), copy TO(dx1, dy2)-(dx2 + tilt, dy1)-(dx2, dy2), d
dx1 = dx1 + xchange: dx2 = dx2 + xchange: dy1 = dy1 + ychange: dy2 = dy2 + ychange
NEXT
_DEST d: _SOURCE s: _FONT font
_FREEIMAGE copy
END SUB
Various thickness is supported. Different tilts are supported. Text can expand from any direction... We can use it to italicize our text if we want to... It scales text to different widths and heights...
It's not a true 3D text, as in we can't rotate it on the x/y/z axis, but it makes a nice imitation text which we can use to create a nice title screen, or such, for our programs.
Play around with it, see what you guys think of it, and I'll be happily awaiting to see how you guys who are much better than me in math will improve/alter this.
Many thanks go to Petr for providing the inspiration for me to sit down and play around with getting this up and going to the point where it is. I'm really quite happy with how it performs and what it can do for us, and I think this will end up going into my toolbox for regular use from now on.
And a little demo of some of the various styles of 3d text which we can generate with the routine. Watch and pay attention to which direction the text tilts and turns as the program goes along.
Code: (Select All) SCREEN _NEWIMAGE(1024, 720, 32)
_SCREENMOVE _MIDDLE
OE20 = _LOADFONT("calibri.ttf", 72)
_FONT OE20
FOR x = -2 TO 2 STEP 0.1
CLS , 0
Print3D 100, 200, "Steve is Awesome!", 5, x * 20, OE20, &HFFFF0000, x, x, 1, 1.25
_LIMIT 3
_DISPLAY
NEXT
FOR x = -2 TO 2 STEP 0.1
CLS , 0
Print3D 100, 200, "Steve is Awesome!", 5, x * 20, OE20, &HFFFF0000, -x, -x, 1, 1.25
_LIMIT 3
_DISPLAY
NEXT
FOR x = -2 TO 2 STEP 0.1
CLS , 0
Print3D 100, 200, "Steve is Awesome!", 5, x * 20, OE20, &HFFFF0000, x, -x, 1, 1.25
_LIMIT 3
_DISPLAY
NEXT
FOR x = -2 TO 2 STEP 0.1
CLS , 0
Print3D 100, 200, "Steve is Awesome!", 5, x * 20, OE20, &HFFFF0000, -x, x, 1, 1.25
_LIMIT 3
_DISPLAY
NEXT
SUB Print3D (x AS INTEGER, y AS INTEGER, text$, thick AS INTEGER, tilt AS INTEGER,_
f AS LONG, fg AS _UNSIGNED LONG, xchange as integer, ychange as integer,_
scalex as _float, scaley as _float)
DIM copy AS INTEGER
DIM dx1 AS _FLOAT, dx2 AS _FLOAT, dy1 AS _FLOAT, dy2 AS _FLOAT
d = _DEST: s = _SOURCE: font = _FONT
copy = _NEWIMAGE(_WIDTH, _HEIGHT, 32)
_DEST copy: _SOURCE copy
_FONT f
sx1 = 0: sy1 = 0
sx2 = _PRINTWIDTH(text$, copy): sy2 = _FONTHEIGHT(f)
dx1 = x: dy1 = y
dx2 = x + sx2 * scalex: dy2 = y + sy2 * scaley
FOR i = thick TO 0 STEP -1
CLS , 0
COLOR _RGBA32(_RED32(fg), _GREEN32(fg), _BLUE32(fg), 155 + 100 / i), 0
PRINT text$
_MAPTRIANGLE (sx1, sy1)-(sx2, sy1)-(sx1, sy2), copy TO(dx1 + tilt, dy1)-(dx2 + tilt, dy1)-(dx1, dy2), d
_MAPTRIANGLE (sx1, sy2)-(sx2, sy1)-(sx2, sy2), copy TO(dx1, dy2)-(dx2 + tilt, dy1)-(dx2, dy2), d
dx1 = dx1 + xchange: dx2 = dx2 + xchange: dy1 = dy1 + ychange: dy2 = dy2 + ychange
NEXT
_DEST d: _SOURCE s: _FONT font
_FREEIMAGE copy
END SUB
RE: Steve's 3D Print - dcromley - 07-22-2022
> So, what do you guys think?
Steve is Awesome
|