Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
another variation of "10 PRINT"
#1
although this is much larger than the "10 PRINT" program from commodore 64...

Code: (Select All)
DIM AS INTEGER u1, u2, j, ps, wd, ht, x, y, xm, ym
DIM AS LONG mfont
RANDOMIZE VAL(RIGHT$(TIME$, 2))
ps = 20
xm = ps \ 2
ym = ps
wd = 640
ht = 400
SCREEN _NEWIMAGE(wd, ht, 32)
mfont = _LOADFONT(ENVIRON$("HOME") + "/.local/share/fonts/CousineNerdFontMono-Regular.ttf", ps, "UNICODE")
_FONT mfont
_PRINTMODE _KEEPBACKGROUND
FOR j = 1 TO 1600
    u1 = &H25
    u2 = INT(RND * 3) + &H71
    IF u2 <> &H72 THEN
        _UPRINTSTRING (x, y), CHR$(&H71) + CHR$(u1), ps, 16
    END IF
    IF u2 <> &H71 THEN
        _UPRINTSTRING (x, y), CHR$(&H72) + CHR$(u1), ps, 16
    END IF
    x = x + xm
    IF x >= wd THEN
        x = 0
        y = y + ym
        IF y >= ht THEN EXIT FOR
    END IF
NEXT
SLEEP
SYSTEM

it's impossible to create the "x" sigil so it matches well with the other shapes at top and bottom.  and also has both smooth diagonals.  it requires _PRINTMODE line, i wish it didn't.  on the other hand, i was able to remove "x" sigil from reasoning and use both slant sigils to create it instead.  the picture looks better this way.  at least i'm glad _UPRINTSTRING could print what is seen in gucharmap.  with option enabled: "view/show only glyphs from this font".

this program should work on linux.  but requires installing font which is easy for user.  just copy using your file manager, it doesn't need "superuser" privilege.  this "cousine mono" font is easy to get, it is an alternative to "liberation mono" which doesn't have saxophone-looking lowercase L.  there are other "nerd" fonts too.


https://github.com/ryanoasis/nerd-fonts


i'm sorry but i don't know what to tell you on windows.  install in user directory but where?  install in "C:\windows\fonts" but the o.s. might not like it if you don't like it.  anyway only the full path with _LOADFONT needs to be changed.

i had to start a new topic, because i cannot find the old topic.  probably it was in one of the restricted forums.  but the "10 PRINT" program picture interested me.  there are many ways to create something like it.  but it's amazing with only two glyphs used.
Reply
#2
I tried it. I got an error. 
I found and installed the font. CousineNerdFontMono-Bold.ttf
line 11, invalid handle.
I tried to set to the actual path of the font, in /windows/fonts, it didn't fix it.
I think I've seen this error before. Something's up with doing fonts for me.
Jack

[edit]
I see now, it can't seem to find the font file name.
When you open a file folder, the real name of the ttf is not what it is, you do a DIR listing in DOS and it is not the same
So I assume the file I really need is courbd.tff
I use that and don't get the error, but I don't see the pattern a print10 program gives.
See the attachment

[Image: print10.jpg]


Also
gucharmap.  with option enabled: "view/show only glyphs from this font".
What is gucharmap? What is this view/show command?
I'm using a win10 machine. Is this not for my OS?
                                                                                                                 
MoreCowbell(everything)
Reply
#3
i don't expect someone to use boldfaced font.  the code line to load the font should read:

Code: (Select All)
mfont = _LOADFONT("C:\windows\fonts\CousineNerdFontMono-Regular.ttf", ps, "UNICODE")
this is for regular monospace font.  you could try with boldfaced instead.  instead of ps variable, try using point size of 16 or 24. (shrugs)

the "courier new" font might not have a lot of unicode symbols.  i don't know if "cyberbit.ttf" is still packaged with qb64.  it was with earlier versions.  especially before phoenix edition.  if you happen to have an early installation of qb64 then find that font and try with it.  however it's not monospaced.  it might not have the graphics characters employed in this topic's example.

"gucharmap" is the gnome character map viewer for linux.  windows should have an equivalent program called "character map" or similar found somewhere in the start menu.  it should show you information about a sigil that you click on with the mouse.  most important is the "U+xxxx" feature where "xxxx" is a 4-digit hexadecimal (base-16) number, which is the "utf-8" code to produce that character with _uprintstring in qb64 phoenix.  it is a bit tricky as you could notice in my program...
Reply
#4
Is this the one that is supposed to fill the screen with a seeming maze using \ and / ? I ask becuase it looks far too complex for that simple thing and of course does not work without outside sources never needed before.
b = b + ...
Reply
#5
Code: (Select All)
Dim As Integer u1, u2, j, ps, wd, ht, x, y, xm, ym
Dim As Long mfont
Randomize Val(Right$(Time$, 2))
ps = 20
xm = ps \ 2
ym = ps
wd = 640
ht = 400
Screen _NewImage(wd, ht, 32)
mfont = _LoadFont("CousineNerdFontMono-Regular.ttf", ps, "UNICODE")
_Font mfont
_PrintMode _KeepBackground
For j = 1 To 1600
    u1 = &H25
    u2 = Int(Rnd * 3) + &H71
    If u2 <> &H72 Then
        _UPrintString (x, y), Chr$(&H71) + Chr$(u1), ps, 16
    End If
    If u2 <> &H71 Then
        _UPrintString (x, y), Chr$(&H72) + Chr$(u1), ps, 16
    End If
    x = x + xm
    If x >= wd Then
        x = 0
        y = y + ym
        If y >= ht Then Exit For
    End If
Next
Sleep
System

I don't know why some folks are acting like it's difficult to get this demo to run on Windows.  All one has to do is grab the proper font file (I've zipped it up and attached it here for convenience's sake, but it can be found following the link in the first post as well.), and then extract it into the QB64PE folder and change the path where it'll be found as above.

That's all there is to it!

1) Copy code above into IDE
2) Download and extract font here into your QB64PE folder.
3) Compile and Run.

Nothing complicated about any of that.  Wink


Attached Files
.7z   CousineNerdFontMono-Regular.7z (Size: 1.23 MB / Downloads: 9)
Reply
#6
That is certainly way more difficult than this:
Code: (Select All)
10 _Font 8: cnt = cnt + 1: If cnt < 1921 Then If Rnd < .5 Then Print "\";: GoTo 10 Else Print "/";: GoTo 10
b = b + ...
Reply
#7
(01-11-2025, 11:48 PM)bplus Wrote: That is certainly way more difficult than this:
Code: (Select All)
10 _Font 8: cnt = cnt + 1: If cnt < 1921 Then If Rnd < .5 Then Print "\";: GoTo 10 Else Print "/";: GoTo 10

And that's not as simple as this:

Code: (Select All)
_Font 8
For cnt = 1 To 1920
If Rnd < .5 Then Print "\"; Else Print "/";
Next

Code doesn't always have to be simple to be shared. Personally, I think it's nice to see folks posting different ways to do the same thing.

One thing curious though, and see if you can answer this: Why does your method take several seconds to run, while mine is instant?

And why does yours freeze up the program and require a close from task manager, if you click on the red X in the top right while it's running? Why won't it close properly, without issues?
Reply
#8
(01-11-2025, 11:48 PM)bplus Wrote: That is certainly way more difficult than this:
Code: (Select All)
10 _Font 8: cnt = cnt + 1: If cnt < 1921 Then If Rnd < .5 Then Print "\";: GoTo 10 Else Print "/";: GoTo 10

I had to pester the other devs and dig into why this is such crappy code (and that's not saying @bplus is a crappy coder; that's just saying *THIS* is some crappy code), and after some digging and annoying everyone else, here's the issue:

_FONT shouldn't be called endlessly inside a loop like this!!

In a text screen (like the SCREEN 0 that we default to, and which is in play here), _FONT requires a complete redraw and resize of the entire screen *each and every* time it's called!   

So what's going on here is:

_Font 8:  Redraw and Resize entire screen
cnt = cnt + 1: increase count
IF cnt....   draw our slash and repeat entire process 1920 times

That 1920 calls to _Font 8 is the issue.  You really don't need that pause for redrawing and resizing, and it certainly doesn't play nice with early termination of the program.

Lesson learned here??

Keep _Font calls to a minimum and definitely don't include them into the middle of a loop like this.  Not unless you just WANT to generate issues for your programs and make them unstable for some odd reason.
Reply
#9
??? "One thing curious though, and see if you can answer this: Why does your method take several seconds to run, while mine is instant?"

I suspect it is the _Font 8 line that slows things down. Obviously, to me anyway, I was going for a one-liner like the original that didn't need the _Font 8 to fix the print.

Another way that is fast:
Code: (Select All)
_Font 8
10 If Rnd < .5 Then Print "\"; Else Print "/";
c = c + 1: If c < 1920 Then GoTo 10

Another way:
Code: (Select All)
_Font 8
10 c = c + 1: If c < 2001 Then If Rnd < .5 Then Print "\"; Else Print "/";
GoTo 10
b = b + ...
Reply
#10
(01-12-2025, 12:41 AM)bplus Wrote: I suspect it is the _Font 8 line that slows things down. Obviously, to me anyway, I was going for a one-liner like the original that didn't need the _Font 8 to fix the print.

Another way that is fast:
Code: (Select All)
_Font 8
[code]10 If Rnd < .5 Then Print "\"; Else Print "/";
c = c + 1: If c < 1920 Then GoTo 10

Another way:
_Font 8
10 c = c + 1: If c < 2001 Then If Rnd < .5 Then Print "\"; Else Print "/";
GoTo 10[/code]

It is.  See my post before yours for details.  Wink
Reply




Users browsing this thread: JRace, 13 Guest(s)