Author Topic: [FIXED] Help please an example taken from wiki is bugged! (Paint tiling)  (Read 9282 times)

0 Members and 1 Guest are viewing this topic.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Help please an example taken from wiki is bugged! (Paint tiling)
« Reply #30 on: November 15, 2019, 07:15:41 pm »
Thanks Steve
in the while I'm playing with the ideas that you give above and so I got this scheme
Code: QB64: [Select]
  1. ' Name             String full color                        AttributeColor       Non Zero Value (255=full)
  2. '        blu        green     red       light
  3. SBlack = CHR$(0) + CHR$(0) + CHR$(0) + CHR$(0) '                 0             0 255
  4.  
  5. Sblu = CHR$(255) + CHR$(0) + CHR$(0) + CHR$(0) '                 1             1 SOLO 255
  6. Sgreen = CHR$(0) + CHR$(255) + CHR$(0) + CHR$(0) '               2
  7. Sred = CHR$(0) + CHR$(0) + CHR$(255) + CHR$(0) '                 4
  8. Sgray = CHR$(0) + CHR$(0) + CHR$(0) + CHR$(255) '                8
  9.  
  10. Scyan = CHR$(255) + CHR$(255) + CHR$(0) + CHR$(0) '              3              2 SOLI 255
  11. Sporpora = CHR$(255) + CHR$(0) + CHR$(255) + CHR$(0) '           5
  12. Sviolet = CHR$(255) + CHR$(0) + CHR$(0) + CHR$(255) '            9
  13. Sbrown = CHR$(0) + CHR$(255) + CHR$(255) + CHR$(0) '             6
  14. SgreenLight = CHR$(0) + CHR$(255) + CHR$(0) + CHR$(255) '       10
  15. SredLight = CHR$(0) + CHR$(0) + CHR$(255) + CHR$(255) '         12
  16.  
  17. Swhite = CHR$(255) + CHR$(255) + CHR$(255) + CHR$(0) '           7              3 255
  18. Sceleste = CHR$(255) + CHR$(255) + CHR$(0) + CHR$(255) '        11
  19. Spink = CHR$(255) + CHR$(0) + CHR$(255) + CHR$(255) '           13
  20. Syellow = CHR$(0) + CHR$(255) + CHR$(255) + CHR$(255) '         14
  21.  
  22. SwhiteLight = CHR$(255) + CHR$(255) + CHR$(255) + CHR$(255) '   15             4 255
  23. ' using a value in the range 1-254 we get some masks

so here a different color for brick-wall using your Paint Tiling QB45 Emulator
Code: QB64: [Select]
  1. DEFLNG A-Z
  2.  
  3. DIM Row$(1 TO 8)
  4. 'make Sporpora-brick wall
  5. Row$(1) = CHR$(&HFE) + CHR$(&H0) + CHR$(&HFE) + CHR$(&H0)
  6. Row$(2) = Row$(1)
  7. Row$(3) = Row$(1)
  8. Row$(4) = CHR$(&H0) + CHR$(&H0) + CHR$(&H0) + CHR$(&H0)
  9. Row$(5) = CHR$(&HEF) + CHR$(&H0) + CHR$(&HEF) + CHR$(&H0)
  10. Row$(6) = Row$(5)
  11. Row$(7) = Row$(5)
  12. Row$(8) = Row$(4)
  13. Tile$ = Row$(1) + Row$(2) + Row$(3) + Row$(4) + Row$(5) + Row$(6) + Row$(7) + Row$(8)
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21. 'red cross pattern on black background
  22. '00011000
  23. '11111111
  24. '11111111
  25. '00011000
  26. '00011000
  27. '00011000
  28. '00011000
  29. '00011000
  30.  
  31. 'text$ = text$ + CHR$(0) + CHR$(0) + CHR$(24) + CHR$(0)
  32. 'text$ = text$ + CHR$(0) + CHR$(0) + CHR$(255) + CHR$(0)
  33. 'text$ = text$ + CHR$(0) + CHR$(0) + CHR$(255) + CHR$(0)
  34. 'text$ = text$ + CHR$(0) + CHR$(0) + CHR$(24) + CHR$(0)
  35. 'text$ = text$ + CHR$(0) + CHR$(0) + CHR$(24) + CHR$(0)
  36. 'text$ = text$ + CHR$(0) + CHR$(0) + CHR$(24) + CHR$(0)
  37. 'text$ = text$ + CHR$(0) + CHR$(0) + CHR$(24) + CHR$(0)
  38. 'text$ = text$ + CHR$(0) + CHR$(0) + CHR$(24) + CHR$(0)
  39.  
  40. text$ = Tile$
  41.  
  42. tileimage = StringToTile16(text$)
  43.  
  44.  
  45. LINE (20, 20)-(240, 240), 14, B
  46. paintImage 21, 21, 14, 0, tileimage
  47. _PUTIMAGE (300, 100)-STEP(100, 100), tileimage
  48. LINE (300, 100)-STEP(100, 100), 14, B 'just to highlight our tile pattern
  49.  
  50. FUNCTION StringToTile16 (text$)
  51.     d = _DEST: s = _SOURCE
  52.     tempimage = _NEWIMAGE(8, 8, 12)
  53.     _DEST tempimage: _SOURCE tempimage
  54.     FOR y = 0 TO 7
  55.         LINE$ = MID$(text$, y * 4 + 1, 4)
  56.         b = ASC(LINE$, 1) 'blue
  57.         g = ASC(LINE$, 2) 'green
  58.         r = ASC(LINE$, 3) 'red
  59.         a = ASC(LINE$, 4) 'alpha (intensity)
  60.         FOR x = 0 TO 7
  61.             p = 2 ^ x 'position to check
  62.             bp = b AND p
  63.             gp = g AND p
  64.             rp = r AND p
  65.             ap = a AND p
  66.             IF ap THEN zero = 85 ELSE zero = 0
  67.             IF bp THEN blue = 170 + zero ELSE blue = zero
  68.             IF gp THEN green = 170 + zero ELSE green = zero
  69.             IF rp THEN red = 170 + zero ELSE red = zero
  70.             PSET (x, y), _RGB(red, green, blue)
  71.         NEXT
  72.     NEXT
  73.     _DEST d: _SOURCE s
  74.     StringToTile16 = tempimage
  75.  
  76.  
  77.  
  78.  
  79.  
  80. SUB paintImage (x, y, Border~&, destHandle&, imageHandle&)
  81.     d = _DEST: s = _SOURCE
  82.     _DEST destHandle&
  83.     PAINT (x, y), _RGB(119, 24, 49), Border~&
  84.     FOR y = 0 TO _HEIGHT(destHandle&)
  85.         FOR x = 0 TO _WIDTH(destHandle&)
  86.             _SOURCE destHandle&
  87.             IF POINT(x, y) = _RGB(119, 24, 49) THEN
  88.                 _SOURCE imageHandle&
  89.                 PSET (x, y), POINT(x MOD _WIDTH(imageHandle&), y MOD _HEIGHT(imageHandle&))
  90.             END IF
  91.         NEXT
  92.     NEXT
  93.     _DEST d: _SOURCE s
  94.  
Programming isn't difficult, only it's  consuming time and coffee

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Help please an example taken from wiki is bugged! (Paint tiling)
« Reply #31 on: November 16, 2019, 06:58:06 am »
Hi Steve
playing just a bit more with your Informations I can affirm that your QB45 PaintTiling emulator is Cool!

here an example about how it is versatle using &B as mask for tiling
  [ You are not allowed to view this attachment ]  

Code: QB64: [Select]
  1.  
  2. 'red cross pattern on black background
  3. '00011000
  4. '11111111
  5. '11111111
  6. '00011000
  7. '00011000
  8. '00011000
  9. '00011000
  10. '00011000
  11.  
  12. '       Binary scheme gives direct more powerful control of mask
  13. '                      Blu                 Green               Red             Light
  14. text$ = text$ + CHR$(&B00011000) + CHR$(&B00011000) + CHR$(&B11100111) + CHR$(&B00000000)
  15. text$ = text$ + CHR$(&B00000000) + CHR$(&B11111111) + CHR$(&B11100111) + CHR$(&B00000000)
  16. text$ = text$ + CHR$(&B00000000) + CHR$(&B11111111) + CHR$(&B11100111) + CHR$(&B00000000)
  17. text$ = text$ + CHR$(&B00011000) + CHR$(&B00011000) + CHR$(&B11100111) + CHR$(&B00000000)
  18. text$ = text$ + CHR$(&B00011000) + CHR$(&B00000000) + CHR$(&B11100111) + CHR$(&B00000000)
  19. text$ = text$ + CHR$(&B00011000) + CHR$(&B00000000) + CHR$(&B11100111) + CHR$(&B00000000)
  20. text$ = text$ + CHR$(&B00011000) + CHR$(&B00000000) + CHR$(&B11100111) + CHR$(&B00000000)
  21. text$ = text$ + CHR$(&B00011000) + CHR$(&B00011000) + CHR$(&B11100111) + CHR$(&B00000000)
  22.  
  23.  
  24.  
  25. tileimage = StringToTile16(text$)
  26. LINE (20, 20)-(240, 240), 14, B
  27. paintImage 21, 21, 14, 0, tileimage
  28. _PUTIMAGE (300, 100)-STEP(100, 100), tileimage
  29. LINE (300, 100)-STEP(100, 100), 14, B 'just to highlight our tile pattern
  30.  
  31. FUNCTION StringToTile16 (text$)
  32.     d = _DEST: s = _SOURCE
  33.     tempimage = _NEWIMAGE(8, 8, 12)
  34.     _DEST tempimage: _SOURCE tempimage
  35.     FOR y = 0 TO 7
  36.         LINE$ = MID$(text$, y * 4 + 1, 4)
  37.         b = ASC(LINE$, 1) 'blue
  38.         g = ASC(LINE$, 2) 'green
  39.         r = ASC(LINE$, 3) 'red
  40.         a = ASC(LINE$, 4) 'alpha (intensity)
  41.         FOR x = 0 TO 7
  42.             p = 2 ^ x 'position to check
  43.             bp = b AND p
  44.             gp = g AND p
  45.             rp = r AND p
  46.             ap = a AND p
  47.             IF ap THEN zero = 85 ELSE zero = 0
  48.             IF bp THEN blue = 170 + zero ELSE blue = zero
  49.             IF gp THEN green = 170 + zero ELSE green = zero
  50.             IF rp THEN red = 170 + zero ELSE red = zero
  51.             PSET (x, y), _RGB(red, green, blue)
  52.         NEXT
  53.     NEXT
  54.     _DEST d: _SOURCE s
  55.     StringToTile16 = tempimage
  56.  
  57.  
  58.  
  59.  
  60.  
  61. SUB paintImage (x, y, Border~&, destHandle&, imageHandle&)
  62.     d = _DEST: s = _SOURCE
  63.     _DEST destHandle&
  64.     PAINT (x, y), _RGB(119, 24, 49), Border~&
  65.     FOR y = 0 TO _HEIGHT(destHandle&)
  66.         FOR x = 0 TO _WIDTH(destHandle&)
  67.             _SOURCE destHandle&
  68.             IF POINT(x, y) = _RGB(119, 24, 49) THEN
  69.                 _SOURCE imageHandle&
  70.                 PSET (x, y), POINT(x MOD _WIDTH(imageHandle&), y MOD _HEIGHT(imageHandle&))
  71.             END IF
  72.         NEXT
  73.     NEXT
  74.     _DEST d: _SOURCE s
  75.  
Thanks
Programming isn't difficult, only it's  consuming time and coffee

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Help please an example taken from wiki is bugged! (Paint tiling)
« Reply #32 on: November 16, 2019, 07:35:11 am »
about
Quote
In 16 color modes, every line is 4-byte long (2^4=16): one byte sets the red attribute, one the green, one the blue, one the brightess of the eight pixels of the line.

In 256-color mode, you will need 8 bytes for every line (2^8=256).

two questions:
1. in a 32 bit mode how many bytes do we need to code color?
2. in 256 color mode  I think that the 8 bytes are grouped for the 3 cardinal values BGRA  as BBGGRRAA?
thanks
Programming isn't difficult, only it's  consuming time and coffee

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Help please an example taken from wiki is bugged! (Paint tiling)
« Reply #33 on: November 16, 2019, 09:08:02 am »
about
two questions:
1. in a 32 bit mode how many bytes do we need to code color?
2. in 256 color mode  I think that the 8 bytes are grouped for the 3 cardinal values BGRA  as BBGGRRAA?
thanks

In 256 color mode, each byte is one pixel, IIRC.

QB45 doesn’t have a 32-bit mode, so whoever wrote the routine could make it to their specification.  Personally, I’d just make it pixel-by-pixel like 256 color mode, and it’d be 4 bytes per pixel for Blue, Green, Red, Alpha, in that order, so we could just plug it into _MEM and directly push it to the screen.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Help please an example taken from wiki is bugged! (Paint tiling)
« Reply #34 on: November 16, 2019, 11:50:48 am »
Well it seems that I must do your _MEM tutorial and then I must MOD your Paint Tiling QB45 emulator to _MEM power!

Quote
Q :in 256 color mode  I think that the 8 bytes are grouped for the 3 cardinal values BGRA  as BBGGRRAA?
thanks
A: In 256 color mode, each byte is one pixel, IIRC.

Q. IIRC? I have googled finding a graphic chipset of AMIGA in the 1996!

.....
one byte one pixel....
? I must remove more dust from my memory!
SCREEN 13  has 64 attribute color (0-63) for 256 colors!
so each byte brings information 0-63 !
I'll try to adapt your QB45 emulator to SCREEN 13!

Programming isn't difficult, only it's  consuming time and coffee

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Help please an example taken from wiki is bugged! (Paint tiling)
« Reply #35 on: November 16, 2019, 11:59:41 am »
http://qb64.org/wiki/SCREEN

SCREEN 13 has 256 color attributes, black background.

https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Help please an example taken from wiki is bugged! (Paint tiling)
« Reply #36 on: November 24, 2019, 05:43:24 pm »
Hi Steve here a first step to empower your QB45 paint tiling Emulator

now supported SCREEN 7, 8, 9 added to the original 12, and SCREEN 13.

Code: QB64: [Select]
  1. ' Name             String full color                        AttributeColor       Non Zero Value (255=full)
  2. '        blu        green     red       light
  3. SBlack = CHR$(0) + CHR$(0) + CHR$(0) + CHR$(0) '                 0             0 255
  4.  
  5. Sblu = CHR$(255) + CHR$(0) + CHR$(0) + CHR$(0) '                 1             1 SOLO 255
  6. Sgreen = CHR$(0) + CHR$(255) + CHR$(0) + CHR$(0) '               2
  7. Sred = CHR$(0) + CHR$(0) + CHR$(255) + CHR$(0) '                 4
  8. Sgray = CHR$(0) + CHR$(0) + CHR$(0) + CHR$(255) '                8
  9.  
  10. Scyan = CHR$(255) + CHR$(255) + CHR$(0) + CHR$(0) '              3              2 SOLI 255
  11. Sporpora = CHR$(255) + CHR$(0) + CHR$(255) + CHR$(0) '           5
  12. Sviolet = CHR$(255) + CHR$(0) + CHR$(0) + CHR$(255) '            9
  13. Sbrown = CHR$(0) + CHR$(255) + CHR$(255) + CHR$(0) '             6
  14. SgreenLight = CHR$(0) + CHR$(255) + CHR$(0) + CHR$(255) '       10
  15. SredLight = CHR$(0) + CHR$(0) + CHR$(255) + CHR$(255) '         12
  16.  
  17. Swhite = CHR$(255) + CHR$(255) + CHR$(255) + CHR$(0) '           7              3 255
  18. Sceleste = CHR$(255) + CHR$(255) + CHR$(0) + CHR$(255) '        11
  19. Spink = CHR$(255) + CHR$(0) + CHR$(255) + CHR$(255) '           13
  20. Syellow = CHR$(0) + CHR$(255) + CHR$(255) + CHR$(255) '         14
  21.  
  22. SwhiteLight = CHR$(255) + CHR$(255) + CHR$(255) + CHR$(255) '   15             4 255
  23.  
  24. DEFLNG A-Z
  25. ScreenMode = 13
  26. SCREEN ScreenMode
  27.  
  28. DIM Row$(1 TO 8)
  29. 'one byte one column for a mask of 8 byte for 64 max bytes
  30. 'screen 13 has 255 colors
  31. Row$(1) = CHR$(4) + CHR$(2) + CHR$(0) + CHR$(14) + CHR$(12) + CHR$(2) + CHR$(0) + CHR$(10)
  32. Row$(2) = Row$(1)
  33. Row$(3) = Row$(1)
  34. Row$(4) = CHR$(0) + CHR$(0) + CHR$(0) + CHR$(0) + CHR$(0) + CHR$(0) + CHR$(0) + CHR$(0)
  35. Row$(5) = CHR$(3) + CHR$(3) + CHR$(1) + CHR$(1) + CHR$(14) + CHR$(14) + CHR$(15) + CHR$(11)
  36. Row$(6) = Row$(5)
  37. Row$(7) = Row$(5)
  38. Row$(8) = Row$(4)
  39. Tile$ = Row$(1) + Row$(2) + Row$(3) + Row$(4) + Row$(5) + Row$(6) + Row$(7) + Row$(8)
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47. 'in screen 12 mode  4 bytes for line of tile with RGBA scheme
  48. 'red cross pattern on black background
  49. 'Cross Pattern -- 0 is black, 1 is BLUE
  50. '00011000   = 24
  51. '00011000
  52. '11111111   = 255
  53. '11111111   = 255
  54. '00011000
  55. '00011000
  56. '00011000
  57. '00011000
  58. text$ = text$ + CHR$(0) + CHR$(0) + CHR$(24) + CHR$(0)
  59. text$ = text$ + CHR$(0) + CHR$(0) + CHR$(255) + CHR$(0)
  60. text$ = text$ + CHR$(0) + CHR$(0) + CHR$(255) + CHR$(0)
  61. text$ = text$ + CHR$(0) + CHR$(0) + CHR$(24) + CHR$(0)
  62. text$ = text$ + CHR$(0) + CHR$(0) + CHR$(24) + CHR$(0)
  63. text$ = text$ + CHR$(0) + CHR$(0) + CHR$(24) + CHR$(0)
  64. text$ = text$ + CHR$(0) + CHR$(0) + CHR$(24) + CHR$(0)
  65. text$ = text$ + CHR$(0) + CHR$(0) + CHR$(24) + CHR$(0)
  66.  
  67. text$ = Tile$ ' REM this line to test SCREEN 12, 9, 8, 7
  68.  
  69. tileimage = StringToTile16(text$, ScreenMode)
  70.  
  71.  
  72. LINE (20, 20)-(180, 180), 14, B
  73. paintImage 21, 21, 14, 0, tileimage
  74. _PUTIMAGE (250, 100)-STEP(50, 50), tileimage ' to overshow tile
  75. LINE (250, 100)-STEP(50, 50), 14, B 'just to highlight our tile pattern
  76.  
  77. ' questa e' la funzione da adattare
  78. FUNCTION StringToTile16 (text$, SMode)
  79.     DIM Bbyte AS INTEGER, RowByte AS INTEGER, Kolor AS _UNSIGNED LONG
  80.     IF SMode = 12 OR SMode = 9 OR SMode = 8 OR SMode = 7 THEN
  81.         Bbyte = 4: RowByte = 4
  82.     ELSEIF SMode = 13 THEN
  83.         Bbyte = 8: RowByte = 8
  84.     ELSE
  85.         PRINT "Error ScreenMode not supported"
  86.         StringToTile16 = 9999
  87.         EXIT FUNCTION
  88.     END IF
  89.     d = _DEST: s = _SOURCE
  90.     tempimage = _NEWIMAGE(8, 8, SMode) ' imagine 8x8  but if text$ is more than
  91.     _DEST tempimage: _SOURCE tempimage
  92.     FOR y = 0 TO 7
  93.         LINE$ = MID$(text$, y * Bbyte + 1, RowByte)
  94.         IF SMode = 12 OR SMode = 9 OR SMode = 8 OR SMode = 7 THEN
  95.             b = ASC(LINE$, 1) 'blue
  96.             g = ASC(LINE$, 2) 'green
  97.             r = ASC(LINE$, 3) 'red
  98.             a = ASC(LINE$, 4) 'alpha (intensity)
  99.         END IF
  100.  
  101.         FOR x = 0 TO 7
  102.             IF SMode = 12 OR SMode = 9 OR SMode = 8 OR SMode = 7 THEN
  103.                 p = 2 ^ x 'position to check
  104.                 bp = b AND p
  105.                 gp = g AND p
  106.                 rp = r AND p
  107.                 ap = a AND p
  108.                 IF ap THEN zero = 85 ELSE zero = 0
  109.                 IF bp THEN blue = 170 + zero ELSE blue = zero
  110.                 IF gp THEN green = 170 + zero ELSE green = zero
  111.                 IF rp THEN red = 170 + zero ELSE red = zero
  112.                 Kolor = _RGB(red, green, blue)
  113.             ELSEIF SMode = 13 THEN
  114.                 Kolor = ASC(LINE$, x + 1)
  115.             END IF
  116.             PSET (x, y), Kolor
  117.         NEXT
  118.     NEXT
  119.     _DEST d: _SOURCE s
  120.     StringToTile16 = tempimage
  121.  
  122.  
  123.  
  124.  
  125.  
  126. SUB paintImage (x, y, Border~&, destHandle&, imageHandle&)
  127.     d = _DEST: s = _SOURCE
  128.     _DEST destHandle&
  129.     PAINT (x, y), _RGB(119, 24, 49), Border~&
  130.     FOR y = 0 TO _HEIGHT(destHandle&)
  131.         FOR x = 0 TO _WIDTH(destHandle&)
  132.             _SOURCE destHandle&
  133.             IF POINT(x, y) = _RGB(119, 24, 49) THEN
  134.                 _SOURCE imageHandle&
  135.                 PSET (x, y), POINT(x MOD _WIDTH(imageHandle&), y MOD _HEIGHT(imageHandle&))
  136.             END IF
  137.         NEXT
  138.     NEXT
  139.     _DEST d: _SOURCE s
  140.  
  141.  
Further step SCREEN 32.
Programming isn't difficult, only it's  consuming time and coffee

FellippeHeitor

  • Guest
[FIXED]: Help please an example taken from wiki is bugged! (Paint tiling)
« Reply #37 on: June 14, 2020, 12:34:20 am »
Bringing back this old thread just to let you guys know that PAINT tiling has been added to QB64 for legacy SCREEN modes and is now available in the latest development build: https://www.qb64.org/portal/development-build/
« Last Edit: June 14, 2020, 12:37:04 am by FellippeHeitor »

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Cool!
Another step towards the future wonderful QB64 with more support of QB45.
Now it is wider the retrogaming perspective.
Programming isn't difficult, only it's  consuming time and coffee

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Here verifications with QB64x64 and QB64x32

  [ You are not allowed to view this attachment ]  

  [ You are not allowed to view this attachment ]  
great job!
Programming isn't difficult, only it's  consuming time and coffee

FellippeHeitor

  • Guest
Thanks for testing it, TempodiBasic.

The latest patch was added by a github user called NEONTEC75.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
I'm very happy about that! Thank you for adding this functionality!