Fonts from String Patterns - Printable Version +- QB64 Phoenix Edition (https://staging.qb64phoenix.com) +-- Forum: QB64 Rising (https://staging.qb64phoenix.com/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://staging.qb64phoenix.com/forumdisplay.php?fid=3) +---- Forum: Utilities (https://staging.qb64phoenix.com/forumdisplay.php?fid=8) +---- Thread: Fonts from String Patterns (/showthread.php?tid=1938) Pages:
1
2
|
Fonts from String Patterns - bplus - 08-27-2023 I've been wanting to do this since i saw Charlie's in BAM. grymmjack's call for Help got me fired up all over again last night, so here is my version: New and improved code is here: https://staging.qb64phoenix.com/showthread.php?tid=1938&pid=19096#pid19096 Compare that image of b+ with the one here: RE: Fonts from String Patterns - grymmjack - 08-27-2023 LOL STARFISHING Dude, you're amazing. Thank you for making this. I'll study and see how I can ruin it and put it into my library LOL. I might have questions! You said something about @CharlieJV having a BAM version? Can you share that information please Also, if you look at the final version of our combined work I added a few functionalities that might be useful to add to yours. - Save glyphs to disk as BMP images (uses Galleon SaveImage). In the thread I started, I posted a final version added with your help. Thanks again. I won't derail your own thread. A couple of thoughts though! We have single color fonts right now. We could simply add color support using an XPixMap (XPM) format approach! https://en.wikipedia.org/wiki/X_PixMap I was thinking instead of X, we could simply use hex numbers to identify up to 16 colors, and we could have each font have it's own colors stored in it, in this way while we're using it as a font, it's actually a tile system that is easily used. Code: (Select All) #define XFACE_format 1 Also check this it shows a good example of what I'm saying. https://www.reddit.com/r/programming/comments/esyfo/xpixmap_is_the_strangest_yet_simplest_image/ It might be a really fun project for you guys to add XPM support to QB64PE natively But I digress, and thank you again for your sweet work. You have such a great personality and I am really impressed by how terse and to the point your code is compared to mine. Like this part in your FPrintroutine: Code: (Select All)
My brain is Also should I be using _UNSIGNED LONGfor all my _RGB32 colors? RE: Fonts from String Patterns - CharlieJV - 08-27-2023 (08-27-2023, 05:24 PM)grymmjack Wrote: [...] I suspect that's a reference to both BAM: _LETCHR$ and _GETCHR$ and BAM: PUTSTRING prototyping Documentation for those as currently implemented in BAM: _LETCHR$ _GETCHR$ PUTSTRING RE: Fonts from String Patterns - CharlieJV - 08-27-2023 Actually, this is probably the @bplus reference: Just a tiny and fun bit of code RE: Fonts from String Patterns - Dav - 08-27-2023 Nice code, @bplus! Starfishing? lol... - Dav RE: Fonts from String Patterns - bplus - 08-27-2023 Thankyou grymmjack for your enthusiasm and inspiration, Charlie too! Both you guys were building characters from strings. When I saw Charlies I got out an old character editor and started working on it again. I was saving the whole character set to file that's why I used string arrays from 0 to 255 for ascii numbers. It should make a character or little printable images easier to create and translate into those pattern strings. (I think I was using 1's and 0's and for 8X16 or 8x8 characters.) "Also should I be using _UNSIGNED LONG for all my _RGB32 colors?" Yes! it's the only Type that can get whitest whites. There is a way to change a color in images and for one color printing that would be perfect after you have created image handles for all the characters. I will see if I can dig that up. @grymmjack I have to read over again you ideas for coloring right now I am bushed. RE: Fonts from String Patterns - jcm - 08-27-2023 with a little variation Code: (Select All)
_Title "Font From String Patterns" ' b+ 2023-08-27' Inspired by grymmjack post here https://staging.qb64phoenix.com/showthread...0#pid18990 ' I used his font patterns to get my version started Screen _NewImage(800, 600, 32) _ScreenMove 200, 60 Window (0, 0)-(800, 600) Dim spattern$(0 To 255) Dim pattern5$(0 To 255) LoadPatterns9x9 spattern$() LoadPatterns5x5 pattern5$() FPrint "TESTING", spattern$(), 323, 550, 2, 3, &HFF0000FF, 0 FPrint "STARFIGHTER", spattern$(), 218, 420, 3, 3, &HFFFF0000, -15 FPrint "STARFISHING", spattern$(), 70, 300, 5, 3, &HFFFFFF00, 15 FPrint "BPLUS", spattern$(), 376, 50, 1, 2, &HFF008800, -90 FPrint "b+", pattern5$(), 435, 53, 1, 1, &HFFFFFFFF, 0 Sleep Sub FPrint (s$, PA$(), x%, y%, scale%, spacing%, colr~&, Ang#) ' s$ is string to "print" out ' PA$() is the array of string holding the font THE SQUARE pattern (must be NxN pattern) ' x, y top, left corner of print just like _PrintString ' scale is multiplier of pixeled font at NxN so now is Scale * N x Scale * N ' spacing is amount of pixels * scale between letters ' color~& type allows up to _RGB32() colors Dim As Integer ls, a, sq, r, c, i Dim As Double Xp, Yp, Xpp, Ypp ls = Len(s$) For l = 1 To ls a = Asc(s$, l) If Len(PA$(a)) Then ' do we have a pattern sq = Sqr(Len(PA$(a))) 'Print Chr$(a), sq 'debug For r = 0 To sq - 1 ' row and col of letter block For c = 0 To sq - 1 i = r * sq + c + 1 If Asc(PA$(a), i) <> Asc(".") Then Xp = x% + ((l - 1) * (sq + spacing%) + c) * scale% Yp = y% + r * scale% '** Xpp = x% + (Xp - x%) * Cos(_D2R(Ang#)) - (Yp - y%) * Sin(_D2R(Ang#)) Ypp = y% - (Xp - x%) * Sin(_D2R(Ang#)) - (Yp - y%) * Cos(_D2R(Ang#)) 'Line (x% + ((l - 1) * (sq + spacing%) + c) * scale%, y% + r * scale%)-Step(scale%, scale%), colr~&, BF Line (Xpp, Ypp)-Step(scale%, scale%), colr~&, BF End If Next Next End If Next End Sub Sub LoadPatterns9x9 (SPattern() As String) Dim As Integer a a = Asc("S") SPattern(a) = "..XXXXXX." SPattern(a) = SPattern(a) + ".X......." SPattern(a) = SPattern(a) + ".X......." SPattern(a) = SPattern(a) + "..S......" SPattern(a) = SPattern(a) + "...SXS..." SPattern(a) = SPattern(a) + "......S.." SPattern(a) = SPattern(a) + ".......S." SPattern(a) = SPattern(a) + ".......S." SPattern(a) = SPattern(a) + "SXXXXXX.." a = Asc("T") SPattern(a) = "XXXXXXXXX" SPattern(a) = SPattern(a) + "....X...." SPattern(a) = SPattern(a) + "....X...." SPattern(a) = SPattern(a) + "....X...." SPattern(a) = SPattern(a) + "....X...." SPattern(a) = SPattern(a) + "....X...." SPattern(a) = SPattern(a) + "....X...." SPattern(a) = SPattern(a) + "....X...." SPattern(a) = SPattern(a) + "....X...." a = Asc("A") SPattern(a) = "...aXA..." SPattern(a) = SPattern(a) + "..X...X.." SPattern(a) = SPattern(a) + "..X...X.." SPattern(a) = SPattern(a) + ".X.....X." SPattern(a) = SPattern(a) + ".XXXXXXX." SPattern(a) = SPattern(a) + ".X.....X." SPattern(a) = SPattern(a) + "X.......X" SPattern(a) = SPattern(a) + "X.......X" SPattern(a) = SPattern(a) + "X.......X" a = Asc("F") SPattern(a) = "XXXXXXXXX" SPattern(a) = SPattern(a) + "F........" SPattern(a) = SPattern(a) + "F........" SPattern(a) = SPattern(a) + "F........" SPattern(a) = SPattern(a) + "FFFXXXX.." SPattern(a) = SPattern(a) + "X........" SPattern(a) = SPattern(a) + "X........" SPattern(a) = SPattern(a) + "X........" SPattern(a) = SPattern(a) + "X........" a = Asc("I") SPattern(a) = ".XXXXXXX." SPattern(a) = SPattern(a) + "....X...." SPattern(a) = SPattern(a) + "....X...." SPattern(a) = SPattern(a) + "....X...." SPattern(a) = SPattern(a) + "....X...." SPattern(a) = SPattern(a) + "....X...." SPattern(a) = SPattern(a) + "....X...." SPattern(a) = SPattern(a) + "....X...." SPattern(a) = SPattern(a) + ".XXXXXXX." a = Asc("G") SPattern(a) = ".XXXXXXXX" SPattern(a) = SPattern(a) + "X........" SPattern(a) = SPattern(a) + "X........" SPattern(a) = SPattern(a) + "X........" SPattern(a) = SPattern(a) + "X....GGGX" SPattern(a) = SPattern(a) + "X.......G" SPattern(a) = SPattern(a) + "X......gG" SPattern(a) = SPattern(a) + "X.....G.X" SPattern(a) = SPattern(a) + ".XXXXX..G" a = Asc("H") SPattern(a) = "X.......X" SPattern(a) = SPattern(a) + "X.......X" SPattern(a) = SPattern(a) + "X.......X" SPattern(a) = SPattern(a) + "X.......X" SPattern(a) = SPattern(a) + "XXXXXXXXX" SPattern(a) = SPattern(a) + "X.......X" SPattern(a) = SPattern(a) + "X.......X" SPattern(a) = SPattern(a) + "X.......X" SPattern(a) = SPattern(a) + "X.......X" a = Asc("E") SPattern(a) = "XXXXXXXXX" SPattern(a) = SPattern(a) + "X........" SPattern(a) = SPattern(a) + "X........" SPattern(a) = SPattern(a) + "X........" SPattern(a) = SPattern(a) + "XXXXXXX.." SPattern(a) = SPattern(a) + "X........" SPattern(a) = SPattern(a) + "X........" SPattern(a) = SPattern(a) + "X........" SPattern(a) = SPattern(a) + "XXXXXXXXX" a = Asc("N") SPattern(a) = "X.......N" SPattern(a) = SPattern(a) + "XX......N" SPattern(a) = SPattern(a) + "X.X.....N" SPattern(a) = SPattern(a) + "N..X....N" SPattern(a) = SPattern(a) + "N...X...N" SPattern(a) = SPattern(a) + "N....X..N" SPattern(a) = SPattern(a) + "N.....X.N" SPattern(a) = SPattern(a) + "N......XN" SPattern(a) = SPattern(a) + "N.......N" a = Asc("B") SPattern(a) = "BBBBBBB.." SPattern(a) = SPattern(a) + "X......B." SPattern(a) = SPattern(a) + "X.......N" SPattern(a) = SPattern(a) + "N......N." SPattern(a) = SPattern(a) + "NBBBBBN.." SPattern(a) = SPattern(a) + "N......b." SPattern(a) = SPattern(a) + "N.......B" SPattern(a) = SPattern(a) + "N......X." SPattern(a) = SPattern(a) + "NBBBBBB.." a = Asc("L") SPattern(a) = "B........" SPattern(a) = SPattern(a) + "X........" SPattern(a) = SPattern(a) + "X........" SPattern(a) = SPattern(a) + "N........" SPattern(a) = SPattern(a) + "N........" SPattern(a) = SPattern(a) + "N........" SPattern(a) = SPattern(a) + "N........" SPattern(a) = SPattern(a) + "N........" SPattern(a) = SPattern(a) + "NBBBBBBLL" a = Asc("U") SPattern(a) = "B.......U" SPattern(a) = SPattern(a) + "X.......U" SPattern(a) = SPattern(a) + "X.......U" SPattern(a) = SPattern(a) + "N.......U" SPattern(a) = SPattern(a) + "N.......U" SPattern(a) = SPattern(a) + "N.......U" SPattern(a) = SPattern(a) + "N.......U" SPattern(a) = SPattern(a) + "N.......U" SPattern(a) = SPattern(a) + ".BBBBBBL." a = Asc("P") SPattern(a) = "XPPPPPP.." SPattern(a) = SPattern(a) + "X......X." SPattern(a) = SPattern(a) + "X.......X" SPattern(a) = SPattern(a) + "X......P." SPattern(a) = SPattern(a) + "XXXXXX..." SPattern(a) = SPattern(a) + "X........" SPattern(a) = SPattern(a) + "X........" SPattern(a) = SPattern(a) + "X........" SPattern(a) = SPattern(a) + "X........" a = Asc("R") SPattern(a) = "XPPPPPP.." SPattern(a) = SPattern(a) + "X......X." SPattern(a) = SPattern(a) + "X.......X" SPattern(a) = SPattern(a) + "X......P." SPattern(a) = SPattern(a) + "XXXXXXR.." SPattern(a) = SPattern(a) + "X.....R.." SPattern(a) = SPattern(a) + "X......R." SPattern(a) = SPattern(a) + "X.......X" SPattern(a) = SPattern(a) + "X.......X" End Sub Sub LoadPatterns5x5 (SPattern() As String) Dim As Integer a a = Asc("b") SPattern(a) = "b...." SPattern(a) = SPattern(a) + "b...." SPattern(a) = SPattern(a) + "b.bb." SPattern(a) = SPattern(a) + "bb..b" SPattern(a) = SPattern(a) + "b.bb." a = Asc("+") SPattern(a) = "....." SPattern(a) = SPattern(a) + "..+.." SPattern(a) = SPattern(a) + ".+++." SPattern(a) = SPattern(a) + "..+.." SPattern(a) = SPattern(a) + "....." End Sub RE: Fonts from String Patterns - bplus - 08-28-2023 @jcm nice mod adding angles to "font" printing, funny how those little squares still want to go vertical and horizontal :-)) Gotta say I am impressed by math that uses both sin and cos for x and y calcs. RE: Fonts from String Patterns - vince - 08-28-2023 (08-28-2023, 01:54 AM)bplus Wrote: Gotta say I am impressed by math that uses both sin and cos for x and y calcs.one thing that's worth commiting to memory, bplus, is the rotation matrix formula for rotating any point (x,y) to a new point (p, q) across it's axis by angle (a) p = x*cos(a) - y*sin(a) q = x*sin(a) + y*cos(a) RE: Fonts from String Patterns - mnrvovrfc - 08-28-2023 (08-27-2023, 11:27 PM)jcm Wrote: Must select the whole code text and then press neat "QB64" button on reply toolbar. This is quoted, where it comes from had the code tags together. |