Author Topic: [FIXED] Help please an example taken from wiki is bugged! (Paint tiling)  (Read 7825 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
Re: Help please an example taken from wiki is bugged! (Paint tiling)
« Reply #15 on: November 13, 2019, 01:05:32 pm »
So. Maybe! Maybe. I am not really 100 percent sure. This is now QB64 output:

  [ You are not allowed to view this attachment ]  

It just confirmed that I must to sit down because i am something to read and not accept.... So. The first two bytes are MAYBE useless, the color problem seems to solve the screen mode directly. Or it is a coincidence and the number 4 will be coded in some way in the first two bytes. Here is the source code to explore.

Code: QB64: [Select]
  1. DIM Row$(1 TO 8)
  2.  
  3. 'make red-brick wall
  4. Row$(1) = CHR$(&H0) + CHR$(&H0) + CHR$(&HFE) + CHR$(&HFE)
  5. Row$(2) = Row$(1)
  6. Row$(3) = Row$(1)
  7. Row$(4) = CHR$(&H0) + CHR$(&H0) + CHR$(&H0) + CHR$(&H0)
  8. Row$(5) = CHR$(&H0) + CHR$(&H0) + CHR$(&HEF) + CHR$(&HEF)
  9. Row$(6) = Row$(5)
  10. Row$(7) = Row$(5)
  11. Row$(8) = Row$(4)
  12. Tile$ = Row$(1) + Row$(2) + Row$(3) + Row$(4) + Row$(5) + Row$(6) + Row$(7) + Row$(8)
  13. LINE (59, 124)-(581, 336), 14, B 'yellow box border to paint inside
  14.  
  15.  
  16. PPAINT 320, 240, 15, 14, Tile$ 'paints brick tiles within yellow border
  17.  
  18.  
  19.     PAINT (X, Y), c1, c2
  20.     D = _DEST
  21.  
  22.     'create mask:
  23.  
  24.     ROWS = LEN(s$) \ 4
  25.     DIM R(ROWS) AS STRING '* 32
  26.  
  27.     FOR M = 3 TO LEN(s) - 4 STEP 4 '                                start on byte 3 in text (first two bytes in are always 0, this must be key for color, but how...
  28.         FOR row = M TO M + 4
  29.             st$ = st$ + DECtoBIN$(ASC(s, row))
  30.         NEXT row
  31.         R(i) = st$
  32.         st$ = ""
  33.         i = i + 1
  34.     NEXT M
  35.  
  36.         CASE 0: LOCATE Y, X: PRINT s$: EXIT SUB
  37.         CASE 1: bh = 256
  38.         CASE 4: bh = 32
  39.     END SELECT
  40.     virtualTXT = _NEWIMAGE(_WIDTH, _HEIGHT, bh)
  41.     _DEST virtualTXT
  42.     Lin = 0
  43.     Colum = 0
  44.  
  45.     FOR Y = 1 TO _HEIGHT
  46.         FOR X = 1 TO _WIDTH
  47.             Colum = Colum + 1
  48.             IF Colum > 16 THEN Colum = 1 '                            upgraded to 16, because now we read 2 bytes, not 4
  49.  
  50.             IF MID$(R(Lin), Colum, 1) = "1" THEN
  51.                 PSET (X, Y), c1 AND 4 '                               SCREEN 12 is 4 bit screen
  52.             ELSE
  53.                 REM PSET (X, Y), c2
  54.             END IF
  55.         NEXT X
  56.         Lin = Lin + 1
  57.         IF Lin > UBOUND(r) THEN Lin = LBOUND(r)
  58.     NEXT Y
  59.  
  60.  
  61.     virtual = _NEWIMAGE(_WIDTH(D), _HEIGHT(D), bh)
  62.     _DEST virtual
  63.     _PUTIMAGE , D, virtual
  64.     _CLEARCOLOR c1, virtual
  65.     _PUTIMAGE , virtual, virtualTXT
  66.  
  67.     _PUTIMAGE , virtualTXT, _DISPLAY
  68.  
  69.  
  70.     _FREEIMAGE virtual
  71.     _FREEIMAGE virtualTXT
  72.  
  73. FUNCTION DECtoBIN$ (vstup)
  74.     FOR rj = 7 TO 0 STEP -1
  75.         IF vstup AND 2 ^ rj THEN DECtoBIN$ = DECtoBIN$ + "1" ELSE DECtoBIN$ = DECtoBIN$ + "0"
  76.     NEXT rj
  77.  


Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Help please an example taken from wiki is bugged! (Paint tiling)
« Reply #16 on: November 13, 2019, 01:51:33 pm »
So unfortunately, the color I'm looking for is the number 12. I can't figure out how to get that number. I add binary decomposition of the given painting, maybe someone find how the color number is written.

  [ You are not allowed to view this attachment ]  

If is really color writed as 4-bites number, then you search 1100.

Used code:

Code: [Select]
DIM Row$(1 TO 8)
SCREEN 12

'make red-brick wall
Row$(1) = CHR$(&H0) + CHR$(&H0) + CHR$(&HFE) + CHR$(&HFE)
Row$(2) = Row$(1)
Row$(3) = Row$(1)
Row$(4) = CHR$(&H0) + CHR$(&H0) + CHR$(&H0) + CHR$(&H0)
Row$(5) = CHR$(&H0) + CHR$(&H0) + CHR$(&HEF) + CHR$(&HEF)
Row$(6) = Row$(5)
Row$(7) = Row$(5)
Row$(8) = Row$(4)

FOR r = 1 TO 8
    FOR f = 1 TO LEN(Row$(r))
        PRINT DECtoBIN(ASC(Row$(r), f)); " ";
    NEXT
    PRINT "        Row:"; r
NEXT

PRINT
PRINT "Searching string for number 12 (wall color), binary "; DECtoBIN$(12); " but i see it not"
FUNCTION BINtoDEC (b AS STRING)
    FOR Si = 1 TO LEN(b)
        e$ = MID$(b$, Si, 1)
        c = VAL(e$) '
        Sj = LEN(b) - Si
        BINtoDEC = BINtoDEC + (c * 2 ^ Sj)
    NEXT Si
END FUNCTION

FUNCTION DECtoBIN$ (vstup)
    FOR rj = 7 TO 0 STEP -1
        IF vstup AND 2 ^ rj THEN DECtoBIN$ = DECtoBIN$ + "1" ELSE DECtoBIN$ = DECtoBIN$ + "0"
    NEXT rj
END FUNCTION
« Last Edit: November 13, 2019, 01:56:29 pm by Petr »

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 #17 on: November 13, 2019, 06:43:58 pm »
Colors aren't coded the way you think they are.   The usage depends of screen mode.

In monochrome (screen 2, screen 11...) the usage is very easy:
The tile MUST have a width of 8 bit, and can have a variable height.
You draw the tile by converting the bit-matrix to bytes.

Example (drawing a cross):
00001000=8
00001000=8
00001000=8
11111111=255
00001000=8
00001000=8
00001000=8

So the program:
Code: [Select]

screen 11
paint (10,10),chr$(8)+chr$(8)+chr$(8)+chr$(255)+chr$(8)+chr$(8)+chr$(8)

Will draw a "grid" (tiled crosses)

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).
So you can't use the same tile string in different screen modes unless they have the same number of colors (i.e. screen 7,8,12 are compatible)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

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 #18 on: November 13, 2019, 06:59:12 pm »
Testing in QB45 seems to support the previous notes.

SCREEN 12
LINE (40,120)-(320,270), 14, B
PAINT (120,140), CHR$(0) + CHR$(0) + CHR$(255) + CHR$(255), 14

The above will paint us with a RED fill color

Change that to CHR$(0) + CHR$(255) + CHR$(0) + CHR$(255) and we get a GREEN fill color. 
CHR$(255) + CHR$(0) + CHR$(0) + CHR$(255) gives us a BLUE fill color.


Play around with it a bit, and maybe it'll help you figure out the way it's supposed to act in QB45. 

So, when you wonder where your red is coming from , it's from these lines:
CHR$(&H0) + CHR$(&H0) + CHR$(&HFE) + CHR$(&HFE)  ==>  No Blue + No Green + High Red + High Intensity
« Last Edit: November 13, 2019, 07:56:51 pm by SMcNeill »
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 #19 on: November 13, 2019, 07:09:41 pm »
Grat Job Petr  you got it!

I can confirm that in Qbasic changing the border color (14) has no affect on the color red used to fill the brick of the wall!

Yes, also changing value of arguments of CHR$( ) I got in Qbasic different patterns but the same color red 12
moreover also changing SCREEN mode from 12 to 9 the color of the wall is always red! And also the other patterns are red!
A red word! :-)

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 #20 on: November 13, 2019, 07:16:56 pm »
Hi Steve
thanks to put out the Meta command of the RGBA in Tiling of QB45!
So it seems that if I want a brick tiling I can get only a red brick in the SCREEN 12  and SCREEN 9!

If it is so I can affirm, for my point of view, that masking for aspect of tile is great, but it is so poor for choose a color to paint because it forces to have a pattern only with fixed color, moreover you cannot disable the Mask color attribute and use only the masktiling with the color already set by the before graphic command/action!

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 #21 on: November 13, 2019, 07:48:28 pm »
Actually, I think I was looking at the color values wrong.  The old notes I found were right, my understanding of them was wrong.

Each line is 4 bytes in screen 12 -- Look at your screenshot above.

00000000       00000000     111111110       11111110  -- this is a single line....  If you wanted to know what its color value translates to in screen 12 colors, your colors would be pieced together from those 4 bytes.

For example, let's say I want a RED dot in the first spot, then a black dot, then a blue dot, then all black dots:

00100000      00000000      10000000     10100000

If you look at the first byte, you'll see that I want blue in the 3rd pixel only.  Looking at the third byte, you'll see that I only want red in the 1st pixel only.  And I want them to be the high intensity versions, when I use them, according to the last byte.

To make the first pixel yellow, it'd be:

00000000      10000000      10000000      10000000

no blue --- green in the first pixel --- red in the first pixel --- and high intensity colors.




Try with the above to generate your patterns.  I think I've finally deciphered what those old notes mean, in this case.  ;)
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 #22 on: November 14, 2019, 07:26:38 am »
Thanks I'll try later to put all together this informations into a running code.
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 #23 on: November 14, 2019, 07:56:20 am »
Thanks I'll try later to put all together this informations into a running code.

If it helps, here's an example of a blue on red cross in QB45 in SCREEN 12:

Code: QB64: [Select]
  1.  
  2. 'Cross Pattern -- 0 is RED, 1 is BLUE
  3. '00011000   = 24
  4. '00011000
  5. '11111111   = 255
  6. '00011000
  7. '00011000
  8. '00011000
  9. '00011000
  10.  
  11. r1$ = CHR$(128 + 64 + 32 + 0 + 0 + 4 + 2 + 1) 'Turn Bit values into a CHR$ value for each row
  12. r2$ = CHR$(0 + 0 + 0 + 0 + 0 + 0 + 0 + 0) 'And we only have 2 rows in total which we use as our building blocks for this cross pattern
  13.  
  14. b1$ = CHR$(0 + 0 + 0 + 16 + 8 + 0 + 0 + 0)
  15. b2$ = CHR$(128 + 64 + 32 + 16 + 8 + 4 + 2 + 1)
  16.  
  17. g$ = CHR$(0) 'No green in this pattern
  18. a$ = CHR$(0) 'And we want the dark colors.  If we set the bits here, we'd get the light colors.
  19.  
  20. tile$ = tile$ + b1$ + g$ + r1$ + a$
  21. tile$ = tile$ + b1$ + g$ + r1$ + a$
  22. tile$ = tile$ + b2$ + g$ + r2$ + a$
  23. tile$ = tile$ + b2$ + g$ + r2$ + a$
  24. tile$ = tile$ + b1$ + g$ + r1$ + a$
  25. tile$ = tile$ + b1$ + g$ + r1$ + a$
  26. tile$ = tile$ + b1$ + g$ + r1$ + a$
  27. tile$ = tile$ + b1$ + g$ + r1$ + a$
  28.  
  29. LINE (20, 20)-(240, 240), 14, B
  30. PAINT (21, 21), tile$, 14
  31.  

Run the above in QB45 and you'll get a nice image as a good cross pattern which will fill up the box we defined earlier.  ;)

Hopefully a solid, working example will help highlight how to build (and decipher) the tile$ for use in 16 color screens. 
« Last Edit: November 14, 2019, 08:05:53 am by SMcNeill »
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: Help please an example taken from wiki is bugged! (Paint tiling)
« Reply #24 on: November 14, 2019, 11:04:38 am »
Thank you Steve for a detailed analysis. I had nothing how orientate, so I tried to apply my assumption (as seen, so bad). I'll try somewhere to download the QB4.5 + dosbox for tests. If everything works as I suppose, maybe one old backlog could be solved in QB64? Even a completely new set of 32-bit color instructions could be applied? :) I will continue to experiment with it. It's a nice thing.

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 #25 on: November 14, 2019, 04:45:18 pm »
Thank you Steve for a detailed analysis. I had nothing how orientate, so I tried to apply my assumption (as seen, so bad). I'll try somewhere to download the QB4.5 + dosbox for tests. If everything works as I suppose, maybe one old backlog could be solved in QB64? Even a completely new set of 32-bit color instructions could be applied? :) I will continue to experiment with it. It's a nice thing.

Here's a quick and easy workup of paint tiling, using Bplus's little paintimage routine (modified to work with screen 12 screens), with a quick StringToTile16 function to create the 8x8 tile for us.  See if it doesn't mimic QB45's natural paint routine for you.  ;)

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.  
  13.  
  14.  
  15. text$ = text$ + CHR$(0) + CHR$(0) + CHR$(24) + CHR$(0)
  16. text$ = text$ + CHR$(0) + CHR$(0) + CHR$(255) + CHR$(0)
  17. text$ = text$ + CHR$(0) + CHR$(0) + CHR$(255) + CHR$(0)
  18. text$ = text$ + CHR$(0) + CHR$(0) + CHR$(24) + CHR$(0)
  19. text$ = text$ + CHR$(0) + CHR$(0) + CHR$(24) + CHR$(0)
  20. text$ = text$ + CHR$(0) + CHR$(0) + CHR$(24) + CHR$(0)
  21. text$ = text$ + CHR$(0) + CHR$(0) + CHR$(24) + CHR$(0)
  22. text$ = text$ + CHR$(0) + CHR$(0) + CHR$(24) + CHR$(0)
  23.  
  24. tileimage = StringToTile16(text$)
  25.  
  26. LINE (20, 20)-(240, 240), 14, B
  27.  
  28. paintImage 21, 21, 14, 0, tileimage
  29.  
  30. _PUTIMAGE (300, 100)-STEP(100, 100), tileimage
  31. LINE (300, 100)-STEP(100, 100), 14, B 'just to highlight our tile pattern
  32.  
  33.  
  34. FUNCTION StringToTile16 (text$)
  35.     d = _DEST: s = _SOURCE
  36.     tempimage = _NEWIMAGE(8, 8, 12)
  37.     _DEST tempimage: _SOURCE tempimage
  38.     FOR y = 0 TO 7
  39.         line$ = MID$(text$, y * 4 + 1, 4)
  40.         b = ASC(line$, 1) 'blue
  41.         g = ASC(line$, 2) 'green
  42.         r = ASC(line$, 3) 'red
  43.         a = ASC(line$, 4) 'alpha (intensity)
  44.         FOR x = 0 TO 7
  45.             p = 2 ^ x 'position to check
  46.             bp = b AND p
  47.             gp = g AND p
  48.             rp = r AND p
  49.             ap = a AND p
  50.             IF ap THEN zero = 85 ELSE zero = 0
  51.             IF bp THEN blue = 170 + zero ELSE blue = zero
  52.             IF gp THEN green = 170 + zero ELSE green = zero
  53.             IF rp THEN red = 170 + zero ELSE red = zero
  54.             PSET (x, y), _RGB(red, green, blue)
  55.         NEXT
  56.     NEXT
  57.     _DEST d: _SOURCE s
  58.     StringToTile16 = tempimage
  59.  
  60.  
  61.  
  62.  
  63.  
  64. SUB paintImage (x, y, Border~&, destHandle&, imageHandle&)
  65.     d = _DEST: s = _SOURCE
  66.     _DEST destHandle&
  67.     PAINT (x, y), _RGB(119, 24, 49), Border~&
  68.     FOR y = 0 TO _HEIGHT(destHandle&)
  69.         FOR x = 0 TO _WIDTH(destHandle&)
  70.             _SOURCE destHandle&
  71.             IF POINT(x, y) = _RGB(119, 24, 49) THEN
  72.                 _SOURCE imageHandle&
  73.                 PSET (x, y), POINT(x MOD _WIDTH(imageHandle&), y MOD _HEIGHT(imageHandle&))
  74.             END IF
  75.         NEXT
  76.     NEXT
  77.     _DEST d: _SOURCE s
  78.  
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: Help please an example taken from wiki is bugged! (Paint tiling)
« Reply #26 on: November 15, 2019, 09:25:25 am »
Perfect work, Steve! Your code work as expected and with TempodiBasic's string it draw correct brick! How you find values 85 and 170 in your StringToTile16 function? Yes, 170 + 85 is maximum, 255, but how you find value 170? It is with comparation between expected output in QB4.5 and your program, or how?

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 #27 on: November 15, 2019, 09:43:22 am »
Perfect work, Steve! Your code work as expected and with TempodiBasic's string it draw correct brick! How you find values 85 and 170 in your StringToTile16 function? Yes, 170 + 85 is maximum, 255, but how you find value 170? It is with comparation between expected output in QB4.5 and your program, or how?

SCREEN 12
FOR I = 0 TO 15
   PRINT I, _BLUE(I), _GREEN(I), _RED(I)
NEXT

Only values that print are 0, 85, 170, and 225.

After studying the values a bit, I noticed that the first 8 colors were all 170 or 0 (red, green, blue flag set, or not).  The second 8 values were exactly the same; just 85 higher for the high intensity colors.

Their is one color on the chart which is off pattern, which I can’t help but wonder if it’s a bug in QB64’s default palette, since all the rest follow the rule perfectly.  Maybe QB45 had the same “glitch” and we simply work to duplicate it perfectly? 

As long as we use _RGB, it doesn’t seem to matter: the color (0, 170, 170) still matches closest to (0, 85, 170), so we don’t need to code an exception to the little rules I created for my tile maker.  Still though, I can’t help but wonder, “Why is that one color different from the pattern with all the others??”  ;)
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 #28 on: November 15, 2019, 12:54:28 pm »
Hey Steve
excellent work! I have renamed your new code  "Paint Tiling Steve's QB45 Emulator.BAS".
Now I work to get a not red brickswall!
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 #29 on: November 15, 2019, 01:20:47 pm »
Hey Steve
excellent work! I have renamed your new code  "Paint Tiling Steve's QB45 Emulator.BAS".
Now I work to get a not red brickswall!

Easiest way is to map out your filer with 0s and 1s for each of the 3 colors you want.

Your wall fill is currently:

BLUE
00000000
00000000
00000000
00000000
00000000
00000000
00000000

GREEN
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000

RED
00000000
11111110
11111110
11111110
00000000
01111111
01111111
01111111

If you want a blue wall, just swap Red and Blue’s positions.  For a yellow wall, make green the same as reds.   A white wall has blue, green, red all matching.

That’s all it is to get the tiles.  Just use CHR$(&B00000000) to set those values as needed.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!