Author Topic: Pseudo 3D text  (Read 4823 times)

0 Members and 1 Guest are viewing this topic.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Pseudo 3D text
« on: November 14, 2019, 11:43:59 am »
Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(1024, 768, 32)
  2. im1 = _NEWIMAGE(400, 140, 32)
  3. _DEST im1
  4. D = _LOADFONT("calibri.ttf", 40, "BOLD")
  5. _FONT D, im1
  6. PRINT "Have nice day!"
  7. kX = 1
  8.     LINE (0, 0)-(1024, 768), &HDD000000, BF
  9.     i = 0
  10.     FOR f = _PI / 2 + .2 TO _PI(1.5) - .2 STEP (_PI(1.5) - .2 - _PI / 2 + .2) / 399
  11.         i = i + 1
  12.         x = 512 + SIN(f + r) * 500
  13.         x2 = 512 + SIN(f + .1 + r) * 500
  14.         y = 264 + COS(f + r) * 250
  15.         y2 = 564 + COS(f + r) * 230
  16.         XX = kX * i
  17.         _MAPTRIANGLE (XX - kX, 0)-(XX, 0)-(XX - kX, 120), im1 TO(x, y)-(x2, y)-(x, y2), 0
  18.         _MAPTRIANGLE (XX, 0)-(XX - kX, 120)-(XX, 120), im1 TO(x2, y)-(x, y2)-(x2, y2), 0
  19.     NEXT
  20.     r = r - .01
  21.     _DISPLAY
  22.  

* calibri.ttf (Filesize: 792.79 KB, Downloads: 150)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Pseudo 3D text
« Reply #1 on: November 14, 2019, 11:47:27 am »
Oh yeah! Nice effect Petr  :)

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Pseudo 3D text
« Reply #2 on: November 14, 2019, 11:49:44 am »
Thank you, BPlus :)

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Pseudo 3D text
« Reply #3 on: November 14, 2019, 01:29:04 pm »
Incredible Petr. It's not only 3D text but it's an optical illusion. It also can work without the font. This would make an amazing opening screen to any program or game.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Pseudo 3D text
« Reply #4 on: November 15, 2019, 09:41:40 am »
THAT is soooo cool. Nice one Petr!!
Logic is the beginning of wisdom.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Pseudo 3D text
« Reply #5 on: November 16, 2019, 09:51:29 am »
Yes very nice!

try this my mod

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(1024, 768, 32)
  2. im1 = _NEWIMAGE(400, 140, 32)
  3. _DEST im1
  4. D = _LOADFONT("calibri.ttf", 40, "BOLD")
  5. _FONT D, im1
  6. PRINT "Gret job Petr!!"
  7. kX = 1
  8.     LINE (0, 0)-(1024, 768), &HDD000000, BF
  9.     i = 0
  10.     FOR f = _PI / 2 + .2 TO _PI(1.5) - .2 STEP (_PI(1.5) - .2 - _PI / 2 + .2) / 399
  11.         i = i + 1
  12.         x = 512 + SIN(f + r) * 500
  13.         x2 = 512 + SIN(f + .1 + r) * 500
  14.         y = 264 + COS(f + r) * 250
  15.         y2 = 564 + COS(f + r) * 230
  16.         XX = kX * i
  17.         _MAPTRIANGLE (XX - kX, 0)-(XX, 0)-(XX - kX, 120), im1 TO(x, y)-(x2, y)-(x, y2), 0
  18.         _MAPTRIANGLE (XX, 0)-(XX - kX, 120)-(XX, 120), im1 TO(x2, y)-(x, y2)-(x2, y2), 0
  19.     NEXT
  20.     r = r - .01
  21.     _DISPLAY
  22.  
Programming isn't difficult, only it's  consuming time and coffee

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Pseudo 3D text
« Reply #6 on: November 16, 2019, 01:03:28 pm »
Here is my mod for it using the Mouse Wheel to speed up, slow down, and make it go in reverse. I also added the speed number in the top left corner.

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(1024, 768, 32)
  2. im1 = _NEWIMAGE(400, 140, 32)
  3. _DEST im1
  4. D = _LOADFONT("calibri.ttf", 40, "BOLD")
  5. _FONT D, im1
  6. PRINT "Mouse Wheel"
  7. kX = 1
  8.     LINE (0, 0)-(1024, 768), &HDD000000, BF
  9.     i = 0
  10.     FOR f = _PI / 2 + .2 TO _PI(1.5) - .2 STEP (_PI(1.5) - .2 - _PI / 2 + .2) / 399
  11.         i = i + 1
  12.         x = 512 + SIN(f + r) * 500
  13.         x2 = 512 + SIN(f + .1 + r) * 500
  14.         y = 264 + COS(f + r) * 250
  15.         y2 = 564 + COS(f + r) * 230
  16.         XX = kX * i
  17.         _MAPTRIANGLE (XX - kX, 0)-(XX, 0)-(XX - kX, 120), im1 TO(x, y)-(x2, y)-(x, y2), 0
  18.         _MAPTRIANGLE (XX, 0)-(XX - kX, 120)-(XX, 120), im1 TO(x2, y)-(x, y2)-(x2, y2), 0
  19.     NEXT
  20.  
  21.         mouseX = _MOUSEX
  22.         mouseY = _MOUSEY
  23.         mouseWheel = mouseWheel + _MOUSEWHEEL
  24.     LOOP
  25.     LOCATE 1, 1: PRINT mouseWheel
  26.     rr = mouseWheel / 100
  27.     'r = r - .01
  28.     r = r - rr
  29.     _DISPLAY
  30.  

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Pseudo 3D text
« Reply #7 on: November 16, 2019, 02:09:30 pm »
Thank you for your modifications :)

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Pseudo 3D text
« Reply #8 on: November 17, 2019, 02:34:17 pm »
I like this little set of code quite a bit!

This reminds me somewhat of how I basically do italics without loading a different font for use with it.  One of my most used tools is my "TextToImage" routines, and once I have an image, it's a breeze to put a tilt of various amounts on it, like so:

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(1024, 720, 32)
  2. OE20 = _LOADFONT("calibri.ttf", 20)
  3. _FONT OE20
  4.  
  5. COLOR &HFFFFFF00, 0
  6. text$ = "Hello  World!!"
  7. PRINT text$
  8. source = _COPYIMAGE(0)
  9. '   x1         x2   (slide the top left or right to create an italicized look for the font)
  10. 'y1 -----------
  11. '   |        /|
  12. '   |      /  |
  13. '   |    /    |
  14. '   |  /      |
  15. '   |/        |
  16. 'y2 -----------   (we could also slide the bottom in an opposite direction as well, but I don't here)
  17.  
  18. sx1 = 0: sy1 = 0
  19. sx2 = _PRINTWIDTH(text$): sy2 = _FONTHEIGHT
  20.  
  21. dx1 = 200: dy1 = 100
  22. dx2 = 200 + sx2 * 3: dy2 = 100 + sy2 * 3
  23.  
  24. direction = 1
  25.  
  26.     CLS
  27.     tilt = tilt + direction: IF ABS(tilt) > 300 THEN direction = -direction
  28.     _MAPTRIANGLE (sx1, sy1)-(sx2, sy1)-(sx1, sy2), source TO(dx1 + tilt, dy1)-(dx2 + tilt, dy1)-(dx1, dy2)
  29.     _MAPTRIANGLE (sx1, sy2)-(sx2, sy1)-(sx2, sy2), source TO(dx1, dy2)-(dx2 + tilt, dy1)-(dx2, dy2)
  30.     _LIMIT 30
  31.     _DISPLAY

I haven't sorted out the math in your code yet, but it seems to work on a similar principle to the above (just taken to a greater degree).

My question is this one: Can you take what you've got and make us a SUB which would allow us to make a custom 3D-style font?  Something like the following:

SUB 3dText (x, y, text$, thick, tilt)

x/y would be where we'd want to place the text at on the screen.
text$ would be the text we'd want to place.
thick would be the thickness of the text (your demo has a rather thick looking 3D text; I'd prefer one half as deep usually, so a variable to adjust for that thickness would be nice.)
tilt would would decide the direction that the 3d text would tilt in.  "Hello World" with the shadow/thickness to the left, or the right, or wherever we wanted...

It's a little beyond my 3D skills, without a lot of brushing up and studying, but such a little routine would be PERFECT for the toolbox here on the forums.  I know I for one would love to be able to make use of such a versatile little snippet!  ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Pseudo 3D text
« Reply #9 on: November 17, 2019, 03:27:32 pm »
Hi. It is not real 3D :) I try do it as you wrote, Steve. Try on row 16 rewriting          x2 = 512 + SIN(f + .01 + r) * 500    as     x2 = 512 + SIN(f + .05 + r) * 500  for  other thick :)
« Last Edit: November 17, 2019, 03:31:07 pm by Petr »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Pseudo 3D text
« Reply #10 on: November 17, 2019, 09:37:37 pm »
Hi. It is not real 3D :) I try do it as you wrote, Steve. Try on row 16 rewriting          x2 = 512 + SIN(f + .01 + r) * 500    as     x2 = 512 + SIN(f + .05 + r) * 500  for  other thick :)

I decided to play with my own idea somewhat; here's what I've came up with for a pseudo-3D print routine:

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(1024, 720, 32)
  2. OE20 = _LOADFONT("calibri.ttf", 72)
  3. _FONT OE20
  4.  
  5. Print3D 100, 100, "Hello World", 10, 10, OE20, &HFFFFFF00
  6. Print3D 100, 200, "Steve is Awesome!", 5, -10, OE20, &HFFFF0000
  7. Print3D 100, 300, "So, what do you guys think?", 3, 0, 16, &HFFFFFFFF
  8.  
  9.  
  10. SUB Print3D (x AS INTEGER, y AS INTEGER, text$, thick AS INTEGER, tilt AS INTEGER,_
  11.              f AS LONG, fg AS _UNSIGNED LONG)
  12.     DIM copy AS INTEGER
  13.  
  14.     d = _DEST: s = _SOURCE: font = _FONT
  15.     copy = _NEWIMAGE(_WIDTH, _HEIGHT, 32)
  16.     _DEST copy: _SOURCE copy
  17.     _FONT f
  18.     sx1 = 0: sy1 = 0
  19.     sx2 = _PRINTWIDTH(text$, copy): sy2 = _FONTHEIGHT(f)
  20.  
  21.     dx1 = x: dy1 = y
  22.     dx2 = x + sx2: dy2 = y + sy2
  23.  
  24.     FOR i = thick TO 1 STEP -1
  25.         CLS , 0
  26.         COLOR _RGBA32(_RED32(fg), _GREEN32(fg), _BLUE32(fg), 155 + 100 / i), 0
  27.         PRINT text$
  28.         _MAPTRIANGLE (sx1, sy1)-(sx2, sy1)-(sx1, sy2), copy TO(dx1 + tilt, dy1)-(dx2 + tilt, dy1)-(dx1, dy2), d
  29.         _MAPTRIANGLE (sx1, sy2)-(sx2, sy1)-(sx2, sy2), copy TO(dx1, dy2)-(dx2 + tilt, dy1)-(dx2, dy2), d
  30.         dx1 = dx1 + 1: dx2 = dx2 + 1: dy1 = dy1 + 1: dy2 = dy2 + 1
  31.     NEXT
  32.     _DEST d: _SOURCE s: _FONT font

3D print.jpg
* 3D print.jpg (Filesize: 48.22 KB, Dimensions: 1030x749, Views: 191)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!