Author Topic: 8X8 Character Editor  (Read 3676 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
8X8 Character Editor
« on: September 18, 2020, 03:38:40 pm »
EDIT 2020-09-19: a couple of fixes as noted in change log under title "Best Answer" is here!

Create your own customized 8X8 character set:

Code: QB64: [Select]
  1. _TITLE "8x8 ASCII Character Editor" 'started 2018-08-27 by bplus
  2. 'QB64 X 64 version 1.2 20180228/86  from git b301f92
  3. ' 2020-09-18  Modify this to 8x8 Editor
  4. ' 2020-09-19 Make it better.
  5. ' fix: check if character set changes have been saved on exit.
  6. '      OK but almost doubled lines of code adding inputBox$ code,
  7. '      but it is the perfect job for inputBox$ !
  8. ' fix: alignment of text under the save character to set button. OK
  9. ' fix: previews of character as it is being changed. Done
  10.  
  11. '========================== Instructions: =================================
  12. '
  13. ' Arrow keys move the highlighter around, spacebar toggles tile on/off
  14. ' or just click with mouse to do the same.
  15.  
  16. ' Click buttons to either
  17. ' 1. Enter an ascii by number to edit.
  18. ' 2. Enter a character by pressing the key(s) from which the ascii number is taken.
  19. ' 3. Save a modified character.
  20. ' 4. Save all edits made to file called "8X8 Character Set.DAT".
  21. '
  22. ' You must save character changes to update an array tracking data. 3rd button
  23. ' But you also must File this array data back to disk to save changes after Run.
  24. ' use the 4th button or be prompted.
  25.  
  26. ' Note: If want to work with more sets, just rename Character Set.DAT
  27. '       If that file isn't found, this app will start from scratch.
  28. '
  29. '==========================================================================
  30. CONST cFile$ = "8x8 Character Set.DAT"
  31. CONST CW = 8
  32. CONST CH = 8
  33. CONST SQ = 25
  34. CONST XOFF = 60
  35. CONST YOFF = 80
  36. CONST WW = 800
  37. CONST WH = 600
  38. CONST WHITE = &HFFFFFFFF
  39. CONST BLACK = &HFF000000
  40.  
  41. SCREEN _NEWIMAGE(WW, WH, 32)
  42. _DELAY .25
  43.  
  44. DIM blank AS _UNSIGNED LONG ' for reading black off screen it is not &HFF000000
  45. DIM SHARED AN%, CX, CY, SAVED
  46. DIM SHARED MAP(CW + 2, CH + 2) AS STRING * 1
  47. DIM SHARED CS(256) AS STRING * 64
  48.  
  49. '==============================   main
  50.  
  51. 'see if there is a file in the works to load else start from scratch
  52.     OPEN cFile$ FOR INPUT AS #1
  53.     FOR i = 1 TO 256
  54.         INPUT #1, CS(i - 1)
  55.     NEXT
  56.     CLOSE #1
  57.     SAVED = -1 ' fine if no saved changed to characters
  58.     _FONT 8
  59.     COLOR WHITE, BLACK
  60.     CLS
  61.     blank = POINT(1, 1) 'why isn't black &HFF000000 ???
  62.     FOR a = 0 TO 255
  63.         CLS
  64.         _PRINTSTRING (0, 0), CHR$(a)
  65.         b$ = ""
  66.         FOR y = 0 TO CH - 1
  67.             FOR x = 0 TO CW - 1
  68.                 IF POINT(x, y) <> blank THEN b$ = b$ + "1" ELSE b$ = b$ + "0"
  69.             NEXT
  70.         NEXT
  71.         CS(a) = b$
  72.     NEXT
  73.     SAVED = 0 'haven't written this file yet
  74.  
  75. 'FOR j = 0 TO 255 'checking characters
  76. '    CLS
  77. '    FOR i = 1 TO 64
  78. '        PRINT MID$(CS(j), i, 1);
  79. '        IF i MOD CW = 0 THEN PRINT
  80. '    NEXT
  81. '    IF j > 5 AND j < 32 THEN _CONTINUE
  82. '    PRINT: PRINT j, CHR$(j)
  83. '    PRINT
  84. '    INPUT "Ok, any + enter to quit ", w$
  85. '    IF LEN(w$) THEN EXIT FOR
  86. 'NEXT
  87.  
  88. 'sample B for starters
  89. AN% = 66 '        SHARED variable tracking the Ascii number we are modifying
  90. load 66 'B        for some reason the pixel on B is getting pressed, that was from check code above
  91. CX = 1: CY = 1 '  this is the cursor position inside the pixel map of character
  92.         mx = _MOUSEX: my = _MOUSEY
  93.         _DELAY .2
  94.         'ascii #  to edit
  95.         IF mx > 500 AND mx < 700 AND my > 50 AND my < 100 THEN
  96.             COLOR WHITE, 0
  97.             LINE (500, 50)-(700, 100), BLACK, BF
  98.             LOCATE 5, 67: INPUT "Ascii # "; a%
  99.             IF a% >= 0 AND a% <= 255 THEN AN% = a%: load AN%
  100.         END IF
  101.         'chr$  to edit
  102.         IF mx > 500 AND mx < 700 AND my > 110 AND my < 160 THEN
  103.             COLOR WHITE, 0
  104.             LINE (500, 110)-(700, 160), BLACK, BF
  105.             LOCATE 9, 67: INPUT "Enter Chr$ "; char$
  106.             a% = ASC(char$)
  107.             IF a% >= 0 AND a% <= 255 THEN AN% = a%: load AN%
  108.         END IF
  109.         'save character edit
  110.         IF mx > 500 AND mx < 700 AND my > 170 AND my < 220 THEN
  111.             b$ = build$
  112.             CS(AN%) = b$
  113.             COLOR WHITE, 0
  114.             LINE (500, 170)-(700, 220), BLACK, BF
  115.             _PRINTSTRING (66 * 8, 12 * 16 - 4), "Character recorded."
  116.             SAVED = 0
  117.             _DISPLAY
  118.             _DELAY 1.5
  119.         END IF
  120.         'file character set
  121.         IF mx > 500 AND mx < 700 AND my > 230 AND my < 280 THEN saveSet
  122.  
  123.         'mouse over edit box, toggle tiles and update cursor
  124.         tx = (mx - XOFF) \ SQ: ty = (my - YOFF) \ SQ
  125.         IF tx >= 1 AND tx <= CW AND ty >= 1 AND ty <= CH THEN
  126.             CX = tx: CY = ty
  127.             IF MAP(CX, CY) = "1" THEN MAP(CX, CY) = "0" ELSE MAP(CX, CY) = "1"
  128.         END IF
  129.     END IF
  130.     KH& = _KEYHIT
  131.     SELECT CASE KH&
  132.         CASE 32 'space bar
  133.             IF MAP(CX, CY) = "1" THEN MAP(CX, CY) = "0" ELSE MAP(CX, CY) = "1"
  134.         CASE 18432 'up
  135.             IF CY - 1 >= 1 THEN CY = CY - 1
  136.         CASE 20480 'down
  137.             IF CY + 1 <= CH THEN CY = CY + 1
  138.         CASE 19200 'left
  139.             IF CX - 1 >= 1 THEN CX = CX - 1
  140.         CASE 19712 'right
  141.             IF CX + 1 <= CW THEN CX = CX + 1
  142.     END SELECT
  143.  
  144.     IF _KEYDOWN(27) OR _EXIT THEN ' quitting check for saved work
  145.         IF SAVED = 0 THEN ' a message box would be nice
  146.             ans$ = inputBox$("Do you want to save your changes to the set? (y for yes)", "Save changes before leaving?", 60)
  147.             IF LCASE$(LEFT$(ans$, 1)) = "y" THEN saveSet
  148.             SYSTEM
  149.         ELSE
  150.             SYSTEM
  151.         END IF
  152.     END IF
  153.     update
  154.     _DISPLAY
  155.     _LIMIT 60
  156.  
  157. FUNCTION build$ 'need to do twice in program so a sub, take squares
  158.     b$ = ""
  159.     FOR y = 1 TO CH
  160.         FOR x = 1 TO CW
  161.             b$ = b$ + MAP(x, y)
  162.         NEXT
  163.     NEXT
  164.     build$ = b$
  165.  
  166. SUB saveSet ' along with saving the set this displays a little message in save file button
  167.     COLOR WHITE, 0
  168.     LINE (500, 230)-(700, 280), BLACK, BF
  169.     OPEN cFile$ FOR OUTPUT AS #1
  170.     FOR a = 0 TO 255
  171.         PRINT #1, CS(a)
  172.     NEXT
  173.     CLOSE #1
  174.     LOCATE 16, 65: PRINT cFile$
  175.     LOCATE 17, 71: PRINT "File Saved"
  176.     SAVED = -1
  177.     _DISPLAY
  178.     _DELAY 1.5
  179.  
  180. SUB load (asci) ' loads 2D MAP array with 0's and 1's to make it easier to display
  181.     FOR i = 1 TO 64
  182.         y = i \ CW + 1
  183.         x = i MOD CW: IF x = 0 THEN x = 8: y = y - 1
  184.         MAP(x, y) = MID$(CS(asci), i, 1)
  185.     NEXT
  186.  
  187. SUB update
  188.     COLOR WHITE, _RGB32(100, 110, 100): CLS
  189.     drwBtn 500, 50, "Load map with Ascii"
  190.     drwBtn 500, 110, "Load map with Chr$"
  191.     drwBtn 500, 170, "Save Character Edit"
  192.     drwBtn 500, 230, "File Character Set"
  193.     COLOR _RGB32(250, 225, 255), _RGB32(100, 110, 100)
  194.     _PRINTSTRING (398, 400), "Current Ascii% =" + STR$(AN%) + " or CHR$(" + LTRIM$(STR$(AN%)) + ") = " + CHR$(AN%)
  195.     IF SAVED THEN s$ = " Saved." ELSE s$ = " not Saved yet."
  196.     _PRINTSTRING (398, 440), "File: " + cFile$ + s$
  197.     LINE (XOFF - 1, YOFF - 1)-STEP((CW + 2) * SQ + 2, (CH + 2) * SQ + 2), _RGB32(255, 255, 0), B
  198.     LINE (XOFF + 1, YOFF + 1)-STEP((CW + 2) * SQ, (CH + 2) * SQ), BLACK, B
  199.     LINE (XOFF, YOFF)-STEP((CW + 2) * SQ, (CH + 2) * SQ), _RGB32(255, 80, 0), BF
  200.     FOR y = 1 TO CH
  201.         FOR x = 1 TO CW
  202.             IF MAP(x, y) = "1" THEN c& = _RGB32(200, 200, 200) ELSE c& = _RGB32(0, 0, 0)
  203.             LINE ((x) * SQ + XOFF, (y) * SQ + YOFF)-STEP(SQ - 2, SQ - 2), c&, BF
  204.         NEXT
  205.     NEXT
  206.     ' let's see actual size!
  207.     COLOR _RGB32(255, 255, 0)
  208.     b$ = build$
  209.     FOR i = 1 TO 4 'update Previews
  210.         drwStr01 XOFF + 16 * (i * 2), .5 * YOFF - (8 * i) / 2, b$, i
  211.     NEXT
  212.     'highlight sqr
  213.     LINE (CX * SQ - 1 + XOFF, CY * SQ - 1 + YOFF)-STEP(SQ, SQ), WHITE, B
  214.  
  215. SUB drwBtn (x, y, s$)
  216.     _FONT 16
  217.     th = 16: tw = 8 * LEN(s$): gray& = _RGB32(190, 190, 190)
  218.     LINE (x, y)-STEP(200, 50), _RGB32(0, 0, 0), BF
  219.     LINE (x, y)-STEP(197, 47), _RGB32(255, 255, 255), BF
  220.     LINE (x + 1, y + 1)-STEP(197, 47), gray&, BF
  221.     COLOR _RGB32(0, 0, 0), gray&
  222.     _PRINTSTRING (x + 100 - 4 * LEN(s$), y + 17), s$
  223.  
  224. SUB drwStr01 (x0, y0, s01$, size) 'what ever the present color is set at
  225.     FOR y = 0 TO CH - 1
  226.         FOR x = 0 TO CW - 1
  227.             i = i + 1
  228.             IF MID$(s01$, i, 1) = "1" THEN LINE (x0 + x * size, y0 + y * size)-STEP(size - 1, size - 1), , BF
  229.         NEXT
  230.     NEXT
  231.  
  232. ' for saving and restoring screen settins
  233. SUB scnState (restoreTF AS INTEGER) 'Thanks Steve McNeill
  234.     STATIC Font AS LONG, DefaultColor AS _UNSIGNED LONG, BackGroundColor AS _UNSIGNED LONG, Dest AS LONG, Source AS LONG
  235.     STATIC row AS INTEGER, col AS INTEGER, autodisplay AS INTEGER, mb AS INTEGER
  236.     IF restoreTF THEN
  237.         _FONT Font
  238.         COLOR DefaultColor, BackGroundColor
  239.         _DEST Dest
  240.         _SOURCE Source
  241.         LOCATE row, col
  242.         IF autodisplay THEN _AUTODISPLAY ELSE _DISPLAY
  243.         _KEYCLEAR
  244.         WHILE _MOUSEINPUT: WEND 'clear mouse clicks
  245.         mb = _MOUSEBUTTON(1)
  246.         IF mb THEN
  247.             DO
  248.                 WHILE _MOUSEINPUT: WEND
  249.                 mb = _MOUSEBUTTON(1)
  250.                 _LIMIT 100
  251.             LOOP UNTIL mb = 0
  252.         END IF
  253.     ELSE
  254.         Font = _FONT: DefaultColor = _DEFAULTCOLOR: BackGroundColor = _BACKGROUNDCOLOR
  255.         Dest = _DEST: Source = _SOURCE
  256.         row = CSRLIN: col = POS(0): autodisplay = _AUTODISPLAY
  257.     END IF
  258.  
  259.  
  260. ' You can grab this box by title and drag it around screen for full viewing while answering prompt.
  261. ' Only one line allowed for prompt$
  262. ' boxWidth is 4 more than the allowed length of input, it needs to be longer than title$ and prompt$ also
  263. ' Utilities > Input Box > Input Box 1 tester v 2019-07-31
  264. FUNCTION inputBox$ (prompt$, title$, boxWidth AS _BYTE)
  265.     DIM ForeColor AS _UNSIGNED LONG, BackColor AS _UNSIGNED LONG
  266.     DIM sw AS INTEGER, sh AS INTEGER, curScrn AS LONG, backScrn AS LONG, ibx AS LONG 'some handles
  267.  
  268.     'colors
  269.     ForeColor = &HFF000055 '<  change as desired  prompt text color, back color or type in area
  270.     BackColor = &HFF6080CC '<  change as desired  used fore color in type in area
  271.  
  272.     'items to restore at exit
  273.     scnState 0
  274.  
  275.     'screen snapshot
  276.     sw = _WIDTH: sh = _HEIGHT: curScrn = _DEST
  277.     backScrn = _NEWIMAGE(sw, sh, 32)
  278.     _PUTIMAGE , curScrn, backScrn
  279.  
  280.     'moving box around on screen
  281.     DIM bxW AS INTEGER, bxH AS INTEGER
  282.     DIM mb AS INTEGER, mx AS INTEGER, my AS INTEGER, mi AS INTEGER, grabx AS INTEGER, graby AS INTEGER
  283.     DIM tlx AS INTEGER, tly AS INTEGER 'top left corner of message box
  284.     DIM lastx AS INTEGER, lasty AS INTEGER
  285.     DIM inp$, kh&
  286.  
  287.     'draw message box
  288.     bxW = boxWidth * 8: bxH = 7 * 16
  289.     ibx = _NEWIMAGE(bxW, bxH, 32)
  290.     _DEST ibx
  291.     COLOR &HFF880000, &HFFFFFFFF
  292.     LOCATE 1, 1: PRINT LEFT$(SPACE$(INT((boxWidth - LEN(title$) - 3)) / 2) + title$ + SPACE$(boxWidth), boxWidth)
  293.     COLOR &HFFFFFFFF, &HFFBB0000
  294.     LOCATE 1, boxWidth - 2: PRINT " X "
  295.     COLOR ForeColor, BackColor
  296.     LOCATE 2, 1: PRINT SPACE$(boxWidth);
  297.     LOCATE 3, 1: PRINT LEFT$(SPACE$((boxWidth - LEN(prompt$)) / 2) + prompt$ + SPACE$(boxWidth), boxWidth);
  298.     LOCATE 4, 1: PRINT SPACE$(boxWidth);
  299.     LOCATE 5, 1: PRINT SPACE$(boxWidth);
  300.     LOCATE 6, 1: PRINT SPACE$(boxWidth);
  301.     inp$ = ""
  302.     GOSUB finishBox
  303.  
  304.     'convert to pixels the top left corner of box at moment
  305.     bxW = boxWidth * 8: bxH = 5 * 16
  306.     tlx = (sw - bxW) / 2: tly = (sh - bxH) / 2
  307.     lastx = tlx: lasty = tly
  308.     _KEYCLEAR
  309.     'now allow user to move it around or just read it
  310.     WHILE 1
  311.         CLS
  312.         _PUTIMAGE , backScrn
  313.         _PUTIMAGE (tlx, tly), ibx, curScrn
  314.         _DISPLAY
  315.         WHILE _MOUSEINPUT: WEND
  316.         mx = _MOUSEX: my = _MOUSEY: mb = _MOUSEBUTTON(1)
  317.         IF mb THEN
  318.             IF mx >= tlx AND mx <= tlx + bxW AND my >= tly AND my <= tly + 16 THEN 'mouse down on title bar
  319.                 IF mx >= tlx + bxW - 24 THEN EXIT WHILE
  320.                 grabx = mx - tlx: graby = my - tly
  321.                 DO WHILE mb 'wait for release
  322.                     mi = _MOUSEINPUT: mb = _MOUSEBUTTON(1)
  323.                     mx = _MOUSEX: my = _MOUSEY
  324.                     IF mx - grabx >= 0 AND mx - grabx <= sw - bxW AND my - graby >= 0 AND my - graby <= sh - bxH THEN
  325.                         'attempt to speed up with less updates
  326.                         IF ((lastx - (mx - grabx)) ^ 2 + (lasty - (my - graby)) ^ 2) ^ .5 > 10 THEN
  327.                             tlx = mx - grabx: tly = my - graby
  328.                             CLS
  329.                             _PUTIMAGE , backScrn
  330.                             _PUTIMAGE (tlx, tly), ibx, curScrn
  331.                             lastx = tlx: lasty = tly
  332.                             _DISPLAY
  333.                         END IF
  334.                     END IF
  335.                     _LIMIT 400
  336.                 LOOP
  337.             END IF
  338.         END IF
  339.         kh& = _KEYHIT
  340.         SELECT CASE kh& 'whew not much for the main event!
  341.             CASE 13: EXIT WHILE
  342.             CASE 27: inp$ = "": EXIT WHILE
  343.             CASE 32 TO 128: IF LEN(inp$) < boxWidth - 4 THEN inp$ = inp$ + CHR$(kh&): GOSUB finishBox ELSE BEEP
  344.             CASE 8: IF LEN(inp$) THEN inp$ = LEFT$(inp$, LEN(inp$) - 1): GOSUB finishBox ELSE BEEP
  345.         END SELECT
  346.  
  347.         _LIMIT 60
  348.     WEND
  349.  
  350.     'put things back
  351.     scnState 1 'need fg and bg colors set to cls
  352.     CLS '? is this needed YES!!
  353.     _PUTIMAGE , backScrn
  354.     _DISPLAY
  355.     _FREEIMAGE backScrn
  356.     _FREEIMAGE ibx
  357.     scnState 1 'because we have to call _display, we have to call this again
  358.     inputBox$ = inp$
  359.  
  360.     finishBox:
  361.     _DEST ibx
  362.     COLOR BackColor, ForeColor
  363.     LOCATE 5, 2: PRINT LEFT$(" " + inp$ + SPACE$(boxWidth - 2), boxWidth - 2)
  364.     _DEST curScrn
  365.     RETURN
  366.  
  367.  

EDIT 2020-09-19: a couple of fixes as noted in change log under title
8x8 b+ mod.PNG
* 8x8 b+ mod.PNG (Filesize: 15.63 KB, Dimensions: 802x617, Views: 236)
« Last Edit: September 19, 2020, 03:38:12 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: 8X8 Character Editor
« Reply #1 on: September 18, 2020, 03:44:47 pm »
Using a custom 8x8 Character Set that you made:

Code: QB64: [Select]
  1. _TITLE "Using custom 8X8 Characters"
  2. 'started 2018-08-27 by bplus
  3. 'QB64 X 64 version 1.2 20180228/86  from git b301f92
  4. ' 2020-09-18 mod for 8X8
  5.  
  6. CONST CW = 8, CH = 8, cFile$ = "8X8 Character Set.DAT" 'for the drawChar sub
  7. DIM SHARED CS(255) AS STRING * 64
  8. DIM SHARED cFore AS _UNSIGNED LONG, cBack AS _UNSIGNED LONG 'for charcter colors fore and back
  9. DIM SHARED cRow, cCol 'for future 8x8 modified character subs
  10.  
  11. SCREEN _NEWIMAGE(800, 600, 32)
  12. _DELAY .25
  13.  
  14. '==============================   main
  15. ' set character colors
  16. cBack = &H00000000: cFore = &HFF0000FF
  17. FOR y = 10 TO 500 STEP 10
  18.     FOR x = 10 TO 700 STEP 10
  19.         i = i + 1
  20.         IF i > 255 THEN EXIT FOR
  21.         drwChar x, y, i, 1
  22.     NEXT
  23.     IF i > 255 THEN EXIT FOR
  24. LOCATE 10, 1: PRINT "If you can read this little writing checkout the modified b."
  25. PRINT " Maybe with magnifying glass?"
  26. PRINT "Test printing: 'blue bubble blobs' with modified b's 4 x's size, dull white on red"
  27. cFore = &HFFBBBBBB: cBack = &HFFFF0000 ' dull white on red
  28. s$ = "blue bubble blobs"
  29. FOR i = 1 TO LEN(s$)
  30.     L$ = MID$(s$, i, 1)
  31.     ascii = ASC(L$)
  32.     x0 = i * 8 * 4 '8 width * size 4
  33.     y0 = 14 * 16 'line 14 * 16 (8x16 chars)
  34.     drwChar x0, y0, ascii, 4
  35.  
  36. 'this has flaw in that first character does not get drawn from first time used
  37. SUB drwChar (x0, y0, ascn, size) 'what ever the present color is set at
  38.     'DIM SHARED CS(256) AS STRING * 64  in starting setup
  39.     STATIC beenHere
  40.     IF beenHere = 0 THEN
  41.         'see if there is a file in the works to load else start from scratch
  42.         IF _FILEEXISTS(cFile$) THEN
  43.             OPEN cFile$ FOR INPUT AS #1
  44.             FOR i = 0 TO 255
  45.                 INPUT #1, CS(i)
  46.             NEXT
  47.             CLOSE #1
  48.         ELSE
  49.             PRINT "Can't find file: 8X8 Character Set.DAT, goodbye!"
  50.             END
  51.         END IF
  52.         beenHere = -1
  53.     END IF
  54.     LINE (x0, y0)-STEP(8 * size, 8 * size), cBack, BF 'set backcolor of letter
  55.     FOR y = 0 TO CH - 1
  56.         FOR x = 0 TO CW - 1
  57.             i = i + 1
  58.             IF MID$(CS(ascn), i, 1) = "1" THEN LINE (x0 + x * size, y0 + y * size)-STEP(size - 1, size - 1), cFore, BF
  59.         NEXT
  60.     NEXT
  61.  
  62.  
  63.  

 
Using custom 8x8 characters demo.PNG


This demo of course only scratches surface if you want to use custom 8x8 with commands like Locate, Print, Cls, Input... I have done it all in JB with large print characters.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: 8X8 Character Editor
« Reply #2 on: September 18, 2020, 07:10:52 pm »
This is brilliant!!  I wish I had something like this back in the mid-80's. On my old Amstrad, I had to use pencil and paper to "plot" the 8x8 character, then using binary, convert the image to a "symbol" command. (nb: symbol was used to modify a character)... and yes. I still have the user manual... Sad or what? lol  The process, for me anyway, was tedious. I will not bore you with the details, but if you want to know I can whip up some instructions... (drier than burned toast... lol)

The Symbol command would modify the character "on the fly" and obviously be lost when the program terminated... unless the symbol was somehow saved...

Your program would have been ideal for making characters and sprites (combining modified characters into a small 'grid')...

8x8 fonts, back then, were - as you implied - tiny - but that was ok. After all, what other choice did we have? lol But those characters looked ok on 320x240 and 640x400 screens...

I have a "shopping list" that needs to be processed... It has just gone 9am... No coffee... and expected to cope with a Supermarket on 0% caffeine... Wish me luck!
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: 8X8 Character Editor
« Reply #3 on: September 18, 2020, 08:28:56 pm »
This is brilliant!!  I wish I had something like this back in the mid-80's. On my old Amstrad, I had to use pencil and paper to "plot" the 8x8 character, then using binary, convert the image to a "symbol" command. (nb: symbol was used to modify a character)... and yes. I still have the user manual... Sad or what? lol  The process, for me anyway, was tedious. I will not bore you with the details, but if you want to know I can whip up some instructions... (drier than burned toast... lol)

The Symbol command would modify the character "on the fly" and obviously be lost when the program terminated... unless the symbol was somehow saved...

Your program would have been ideal for making characters and sprites (combining modified characters into a small 'grid')...

8x8 fonts, back then, were - as you implied - tiny - but that was ok. After all, what other choice did we have? lol But those characters looked ok on 320x240 and 640x400 screens...

I have a "shopping list" that needs to be processed... It has just gone 9am... No coffee... and expected to cope with a Supermarket on 0% caffeine... Wish me luck!

@johnno56

For you specially, 2 styles of printing special character strings:
QB64 _PRINTSTRING syle" LP xPix, yPix, s$   where xPix and yPix are graphics screen Pixel locations.

Naalaa style Carrot print where the xCarrot and yCarrot are exactly in the center of what you are going to print.
(Maybe that's not exactly right it's been awhile since I worked with Naalaa.)

Anyway print a string of special 8x8 characters is made easier with these little supplemental subs.

Code: QB64: [Select]
  1. _TITLE "Using custom 8X8 Characters mod, pess any ..."
  2. 'started 2018-08-27 by bplus
  3. 'QB64 X 64 version 1.2 20180228/86  from git b301f92
  4. ' 2020-09-18 mod for 8X8
  5. ' 2020-09-18 mod, add supplemental subs for printing special 8X8
  6.  
  7. CONST CW = 8, CH = 8, cFile$ = "8X8 Character Set.DAT" 'for the drawChar sub
  8. DIM SHARED CS(255) AS STRING * 64, cFore AS _UNSIGNED LONG, cBack AS _UNSIGNED LONG, cSize
  9.  
  10. SCREEN _NEWIMAGE(800, 600, 32)
  11. _DELAY .25
  12.  
  13. '==============================   main
  14. ' set character colors
  15. cColor &HFF0000FF, &H00000000: cSize = 1
  16. FOR y = 10 TO 500 STEP 10
  17.     FOR x = 10 TO 700 STEP 10
  18.         i = i + 1
  19.         IF i > 255 THEN EXIT FOR
  20.         drwChar x, y, i
  21.     NEXT
  22.     IF i > 255 THEN EXIT FOR
  23. cColor &HFFFFFFFF, &HFF000000 '  ye ole white on black
  24. LOCATE 10, 1: PRINT "If you can read this little writing checkout the modified b."
  25. PRINT " Maybe with magnifying glass?"
  26. PRINT "Test printing: 'blue bubble blobs' with modified b's 4 x's size, dull white on blue"
  27.  
  28. cSize = 4 'set the shared variable for 8x8 magnification
  29. cColor &HFF000088, &HFF0000FF 'sets color and saves values
  30. s$ = "blue bubble blobs"
  31. LP 0, 14 * 16, s$
  32. cSize = 3
  33. LP 0, 14 * 16 + 32 + 4, s$
  34. cSize = 2
  35. LP 0, 14 * 16 + 32 + 4 + 24 + 4, s$
  36. cSize = 1
  37. LP 0, 14 * 16 + 32 + 4 + 24 + 4 + 16 + 4, s$
  38.  
  39. _TITLE "Using custom 8X8 Characters mod with NaaLaa style carrot print"
  40. cCLS
  41. cSize = 4
  42. carrotPrint _WIDTH / 2, _HEIGHT / 4, s$
  43. cSize = 3
  44. carrotPrint _WIDTH / 2, _HEIGHT / 2, s$
  45. cSize = 2
  46. carrotPrint _WIDTH / 2, _HEIGHT * 5 / 8, s$
  47. cSize = 1
  48. carrotPrint _WIDTH / 2, INT(_HEIGHT * 11 / 16), s$
  49.  
  50.  
  51. SUB drwChar (x0, y0, ascn) 'draws one character at a time, x0, y0 pixel locations
  52.     ' x0, y0, top left pixel loaction to draw cell 8x8 character
  53.     ' magnified by SHARED cSize and colored with SHARED cFore and cBack colors.
  54.  
  55.     '      !!! set next 2 lines in main program !!!
  56.     'CONST CW = 8, CH = 8, cFile$ = "8X8 Character Set.DAT" 'for the drawChar sub
  57.     'DIM SHARED CS(255) AS STRING * 64, cFore AS _UNSIGNED LONG, cBack AS _UNSIGNED LONG, cSize
  58.     'CW = character cell width
  59.     'CH = character cell height
  60.     'cFile$ = 8X8 custom set of characters in 1's and 0's
  61.     'CS(255) contains directions for pixel locations for each ascii character
  62.     'cFore and cBack are SHARED colors for drawing those 1's and 0's
  63.     'cSize is for magnifying the characters for those of us with older eye sight.
  64.  
  65.     STATIC beenHere
  66.     IF beenHere = 0 THEN 'load the CS array once and only once for RUN
  67.         IF _FILEEXISTS(cFile$) THEN
  68.             OPEN cFile$ FOR INPUT AS #1
  69.             FOR i = 0 TO 255
  70.                 INPUT #1, CS(i)
  71.             NEXT
  72.             CLOSE #1
  73.         ELSE
  74.             PRINT "Can't find file: 8X8 Character Set.DAT, goodbye!"
  75.             END
  76.         END IF
  77.         beenHere = -1
  78.     END IF
  79.  
  80.     'actual draw character part you can use transparent colors for foreground or background
  81.     LINE (x0, y0)-STEP(8 * cSize, 8 * cSize), cBack, BF 'set backcolor of letter
  82.     FOR y = 0 TO CH - 1
  83.         FOR x = 0 TO CW - 1
  84.             i = i + 1
  85.             IF MID$(CS(ascn), i, 1) = "1" THEN LINE (x0 + x * cSize, y0 + y * cSize)-STEP(cSize - 1, cSize - 1), cFore, BF
  86.         NEXT
  87.     NEXT
  88.  
  89. SUB LP (xPix, yPix, s$) '  QB64 _PRINTSTRING style  of Locate and Print
  90.     ' xPix, yPix is Top Left corner of first character cell
  91.     ' s$ is the string to print
  92.  
  93.     ' requires: SUB drwChar (x0, y0, ascn) 'draws one character at a time, x0, y0 pixel locations
  94.  
  95.     FOR i = 1 TO LEN(s$)
  96.         L$ = MID$(s$, i, 1)
  97.         ascii = ASC(L$)
  98.         drwChar xPix + (i - 1) * 8 * cSize, yPix, ascii
  99.     NEXT
  100.  
  101. SUB carrotPrint (xCarrot, yCarrot, s$) ' Naalaa style making xCarrot, yCarrot
  102.     ' xCarrot, yCarrot = pixel location of exact center of print job.
  103.     ' s$ = string to print
  104.  
  105.     ' requires: SUB drwChar (x0, y0, ascn) 'draws one character at a time, x0, y0 pixel locations
  106.  
  107.     xwide = LEN(s$) * 8 * cSize
  108.     LP xCarrot - .5 * xwide, yCarrot - .5 * 8 * cSize, s$
  109.  
  110. SUB cColor (fg AS _UNSIGNED LONG, bg AS _UNSIGNED LONG) 'change cFore and cBack with color for 8x8 custom chars
  111.     ' working with SHARED cFore and cBack
  112.     cFore = fg: cBack = bg
  113.     COLOR cFore, cBack
  114.  
  115. SUB cCLS 'cls for graphics window with custom 8x8 characters
  116.     ' working with SHARED cFore and cBack
  117.     COLOR cFore, cBack
  118.     CLS
  119.     cRow = 1: cCol = 1 ' << I was going to do something that was not simple
  120.  
  121.  

 
Using custom 8x8 demo MOD.PNG
« Last Edit: September 18, 2020, 08:41:50 pm by bplus »

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: 8X8 Character Editor
« Reply #4 on: September 19, 2020, 01:37:46 am »
Bonza! Ya blood's worth bottling!
Logic is the beginning of wisdom.

Offline euklides

  • Forum Regular
  • Posts: 128
    • View Profile
Re: 8X8 Character Editor
« Reply #5 on: September 19, 2020, 04:31:09 am »
On the same idea, test this...


Code: QB64: [Select]
  1. DIM linept$(8)
  2. CAR$ = "@" 'you can change this
  3.  
  4. word$ = "Hello QB64 !" '<--- your little texte here
  5.  
  6.  
  7. WIDTH 150, 30: SCREEN 2, 0
  8. 'capture points
  9. FOR y = 1 TO LEN(word$): a$ = MID$(word$, y, 1): LOCATE 1, 1: PRINT a$
  10.     UH = 7: IF a$ = " " THEN UH = 4
  11.     FOR Vx = 0 TO 7: z$ = "":
  12.         FOR Hx = 0 TO UH: z = POINT(Hx, Vx): IF z = 0 THEN linept$(Vx) = linept$(Vx) + " " ELSE linept$(Vx) = linept$(Vx) + CAR$
  13.         NEXT Hx
  14.         FOR X = 1 TO 8: linept$(Vx) = linept$(Vx) + MID$(z$, X, 1): NEXT X
  15.     NEXT Vx
  16. 'spaces compression
  17. COMP$ = "": FOR X = 1 TO LEN(linept$(1)): CX = 0: FOR y = 0 TO 7:
  18.         IF MID$(linept$(y), X, 1) = CAR$ THEN CX = CX + 1
  19.     NEXT y: IF CX = 0 THEN COMP$ = COMP$ + "." ELSE COMP$ = COMP$ + CAR$
  20. FOR J = 8 TO 2 STEP -1: L = INT(J / 2): IF L > 4 THEN L = 5
  21.     Reprise: K = INSTR(COMP$, STRING$(J, "."))
  22.     IF K > 0 THEN
  23.         MID$(COMP$, K, J) = STRING$(J, "o")
  24.         FOR y = 0 TO 7: MID$(linept$(y), K + L, J - L) = STRING$(J - L, "z"): NEXT y
  25.     END IF
  26.     IF K > 0 THEN GOTO Reprise
  27. FOR y = 0 TO 7: a$ = "": FOR X = 1 TO LEN(linept$(y)): Q$ = MID$(linept$(y), X, 1): IF Q$ = "z" THEN Q$ = ""
  28.     a$ = a$ + Q$: NEXT X: linept$(y) = a$
  29.  
  30. 'showing result
  31. FOR X = 0 TO 7: PRINT " "; linept$(X): NEXT
  32.  

 
qb64car.jpg
« Last Edit: September 19, 2020, 04:47:36 am by euklides »
Why not yes ?

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: 8X8 Character Editor
« Reply #6 on: September 19, 2020, 10:29:20 am »
Yeah @euklides

I've been using "capture the points" trick since way back:
Code: QB64: [Select]
  1. _TITLE "WELCOME"
  2. CONST xmax = 1200
  3. CONST ymax = 600
  4.  
  5. COMMON SHARED cN, pR!, pG!, pB!
  6.  
  7. SCREEN _NEWIMAGE(xmax, ymax, 32)
  8. mess$ = " Amazing.bas how sweet thou art... "
  9. PRINT mess$
  10. w = 8 * LEN(mess$): h = 16
  11. DIM p(w, h)
  12. black&& = POINT(0, 10)
  13. FOR y = 0 TO h
  14.     FOR x = 0 TO w
  15.         IF POINT(x, y) <> black&& THEN
  16.             p(x, y) = 1
  17.         END IF
  18.     NEXT
  19.  
  20. xo = 5: yo = 235: m = 4
  21. resetPlasma
  22.     FOR y = 0 TO h - 1
  23.         FOR x = 0 TO w - 1
  24.             IF p(x, y) THEN
  25.                 changePlasma
  26.             ELSE
  27.                 COLOR 0
  28.             END IF
  29.             LINE (xo + x * m, yo + y * m)-(xo + x * m + m, yo + y * m + m), , BF
  30.         NEXT
  31.     NEXT
  32.     _LIMIT 10
  33.     lc = lc + 1
  34.     IF lc MOD 30 = 0 THEN resetPlasma
  35.  
  36. SUB changePlasma ()
  37.     cN = cN + 1
  38.     COLOR _RGB(127 + 127 * SIN(pR! * .3 * cN), 127 + 127 * SIN(pG! * .3 * cN), 127 + 127 * SIN(pB! * .3 * cN))
  39.  
  40. SUB resetPlasma ()
  41.     pR! = RND ^ 2: pG! = RND ^ 2: pB! = RND ^ 2
  42.  
  43.  

 
Capture the points.PNG

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: 8X8 Character Editor
« Reply #7 on: September 19, 2020, 12:44:56 pm »
@johnno56  and all!

I am updating some things in 8X8 Editor in case anyone wants to use this allot as a tool for making their own font or something. So feel free to list items you'd like me to fix or add but I think what we really want is a little 8x8 tile maker with colors and an editor to place tiles about to build a background and a tool or two to change a tile or set of them to a sprite by using colors to make transparent. Then we have elements for making a game.

Already I've added a Save to file check on exit to avoid accidentally closing app without saving work, I hate that!
It is the perfect job for inputBox$ to find out if you want to save your changes but it doubled the LOC!

The previews aren't updating as you change the pixels so I am on the that issue plus a minor print alignment.

Update: These items are fixed see first post in thread.
« Last Edit: September 20, 2020, 12:11:52 am by bplus »