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

0 Members and 1 Guest are viewing this topic.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Hi guys
try to run this example (n°3 in the wiki on PAINT I get nothing ....
who can say me why?
Thans for attention and answers

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.  
  14.     LINE (59, 124)-(581, 336), 14, B 'yellow box border to paint inside
  15.     PAINT (320, 240), Tile$, 14 'paints brick tiles within yellow border
« Last Edit: June 14, 2020, 12:34:52 am by odin »
Programming isn't difficult, only it's  consuming time and coffee

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 #1 on: November 11, 2019, 10:17:58 am »
Hi. Bad News. in help for PAINT is:
fillColor could be a string made up of a sequence of CHR$ values, each representing a tiling pattern to fill the shape.
While this is not implemented in QB64, a string value is still accepted, though it won't produce any results.

I am afraid that this statement is still valid. BUT I can try to write my own tool on this. What exactly does it do? It fill this field with a text string? I have an idea how to do it if it is so.

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 #2 on: November 11, 2019, 11:10:26 am »
I just made a quick suggestion and now I realize my mistake: What you want is not filling the image with text, but filling the image with a bit mask. I'm on it!

bad code for text fill:

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. PPAINT 320, 240, 15, 14, Tile$ 'paints brick tiles within yellow border
  16.  
  17.     D = _DEST
  18.     PAINT (X, Y), c1, c2
  19.         CASE 0: LOCATE Y, X: PRINT s$: EXIT SUB
  20.         CASE 1: bh = 256
  21.         CASE 4: bh = 32
  22.     END SELECT
  23.     virtualTXT = _NEWIMAGE(_WIDTH, _HEIGHT, bh)
  24.  
  25.     COLOR c1
  26.         FOR X = 1 TO _WIDTH STEP _PRINTWIDTH(s)
  27.             _PRINTSTRING (X, Y), s$, virtualTXT
  28.     NEXT X, Y
  29.  
  30.     virtual = _NEWIMAGE(_WIDTH(D), _HEIGHT(D), bh)
  31.     _PUTIMAGE , D, virtual
  32.     _CLEARCOLOR c1, virtual
  33.     _PUTIMAGE , virtual, virtualTXT
  34.  
  35.     _PUTIMAGE , virtualTXT, _DISPLAY
  36.  
  37.     _FREEIMAGE virtual
  38.     _FREEIMAGE virtualTXT
  39.  

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 #3 on: November 11, 2019, 11:17:18 am »
How does it work correctly according to the original definition of QB4.5 for the PAINT command? Is the string a maximum of 32 bits (4 bytes) per line, or long as the format string line (* 8)? I'll try it for a maximum length of 4 bytes (although I don't know if it should be so.)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Help please an example taken from wiki is bugged! (Paint tiling)
« Reply #4 on: November 11, 2019, 11:56:57 am »
OK maybe it doesn't say on Wiki but in the IDE help I get this message below example #3 (also not in Wiki)

It says Tiling (like with Tile$) doesn't work in QB64.
« Last Edit: November 11, 2019, 12:06:01 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Help please an example taken from wiki is bugged! (Paint tiling)
« Reply #5 on: November 11, 2019, 12:04:53 pm »
Here's some bricks :)
Code: QB64: [Select]
  1. CONST white = &HFFFFFFFF
  2. CONST black = &HFF000000
  3. CONST red = &HFFFF0000
  4. CONST grey = &HFF7C7C7C
  5. CONST darkgrey = &HFF323232
  6.  
  7. DIM SHARED scrn&, background&, brick&, halfBrick&
  8.  
  9. scrn& = _NEWIMAGE(800, 600, 32)
  10. SCREEN scrn&
  11. makeBrick
  12. makeHalfBrick
  13. MakeBackground
  14. _DEST display& '<<< or just plain 0
  15. gameover$ = "false"
  16.     CLS
  17.     _PUTIMAGE (0, 0), background&
  18.     _DISPLAY
  19.     _LIMIT 60
  20. LOOP UNTIL gameover$ = "true"
  21.     _DISPLAY
  22.  
  23. 'for ease of brick laying I made 1 brick 49 wide and 24 high so next brick starts 50 before or after or 25 above or below
  24. SUB makeBrick ()
  25.     brick& = _NEWIMAGE(50, 25, 32)
  26.     _DEST brick&
  27.     LINE (0, 0)-STEP(49, 24), darkgrey, BF
  28.     LINE (1, 1)-STEP(46, 20), red, BF
  29.     LINE (1, 0)-STEP(46, 0), white
  30.     LINE (47, 0)-STEP(0, 21), white
  31.     LINE (0, 0)-STEP(0, 22), black
  32.     LINE (0, 0 + 22)-STEP(47, 0), black
  33.  
  34. SUB makeHalfBrick ()
  35.     halfBrick& = _NEWIMAGE(25, 25, 32)
  36.     _DEST halfBrick&
  37.     '_SOURCE brick&   '<<< not needed
  38.  
  39.     'oh the left side of the half bricks on right edge are off, need more space
  40.     _PUTIMAGE (0, 0)-(25, 25), brick&, halfBrick&, (25, 0)-(50, 25)
  41.     'need to add black line on left side
  42.     LINE (0, 0)-STEP(0, 22), black 'EDIT add a black line to left side of half brick
  43.  
  44.  
  45. SUB MakeBackground
  46.     background& = _NEWIMAGE(800, 600)
  47.     _DEST background&
  48.     'make sky
  49.     LINE (0, 0)-(800, 460), &HFF00AAFF, BF
  50.     i = 0
  51.     FOR y = 450 TO 600 STEP 25 'all bricks start 25 pixels after last
  52.         i = (i + 1) MOD 2
  53.         IF i MOD 2 THEN adj = 25 ELSE adj = 0
  54.         FOR x = 0 + adj TO 800 - 2 * adj STEP 50 'all bricks start 50 pxels after last
  55.             _PUTIMAGE (x, y), brick&, background&
  56.         NEXT
  57.         IF i THEN _PUTIMAGE (0, y), halfBrick&, background&
  58.         IF i THEN _PUTIMAGE (775, y), halfBrick&, background&
  59.     NEXT
  60.  
  61.  

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 #6 on: November 11, 2019, 12:21:47 pm »
So I have a result. I converted the strings into individual bits and used them to render the mask. Then, using transparency, I put an image with the original screen without a fill over the mask image. The result is a filling image. I did this by slow methods because I am still not quite sure about use AND for convert to bits. I do not know if it should be, or should be fill across the entire rectangle frame next to the frame, I would need to see the result under QB4.5 to tune the program (and a new brain, 3 coffee, and mainly peace and quiet...)

Tested just for 8 bit screens!

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.  
  17.  
  18.  
  19.  
  20. PPAINT 320, 240, 15, 14, Tile$ 'paints brick tiles within yellow border
  21.  
  22.  
  23.     PAINT (X, Y), c1, c2
  24.     D = _DEST
  25.  
  26.     'create mask:
  27.  
  28.     ROWS = LEN(s$) \ 4
  29.     DIM R(ROWS) AS STRING '* 32
  30.  
  31.     FOR M = 1 TO LEN(s) - 4 STEP 4
  32.         FOR row = M TO M + 4
  33.             st$ = st$ + DECtoBIN$(ASC(s, row))
  34.         NEXT row
  35.         R(i) = st$
  36.         st$ = ""
  37.         i = i + 1
  38.     NEXT M
  39.  
  40.         CASE 0: LOCATE Y, X: PRINT s$: EXIT SUB
  41.         CASE 1: bh = 256
  42.         CASE 4: bh = 32
  43.     END SELECT
  44.     virtualTXT = _NEWIMAGE(_WIDTH, _HEIGHT, bh)
  45.     _DEST virtualTXT
  46.     Lin = 0
  47.     Colum = 0
  48.  
  49.     FOR Y = 1 TO _HEIGHT
  50.         FOR X = 1 TO _WIDTH
  51.             Colum = Colum + 1
  52.             IF Colum > 32 THEN Colum = 1
  53.             IF MID$(R(Lin), Colum, 1) = "1" THEN
  54.                 PSET (X, Y), c1
  55.             ELSE
  56.                 '                PSET (X, Y), c2
  57.             END IF
  58.         NEXT X
  59.         Lin = Lin + 1
  60.         IF Lin > UBOUND(r) THEN Lin = LBOUND(r)
  61.     NEXT Y
  62.  
  63.  
  64.     virtual = _NEWIMAGE(_WIDTH(D), _HEIGHT(D), bh)
  65.     _DEST virtual
  66.     _PUTIMAGE , D, virtual
  67.     _CLEARCOLOR c1, virtual
  68.     _PUTIMAGE , virtual, virtualTXT
  69.  
  70.     _PUTIMAGE , virtualTXT, _DISPLAY
  71.  
  72.  
  73.     _FREEIMAGE virtual
  74.     _FREEIMAGE virtualTXT
  75.  
  76. FUNCTION DECtoBIN$ (vstup)
  77.     FOR rj = 7 TO 0 STEP -1
  78.         IF vstup AND 2 ^ rj THEN DECtoBIN$ = DECtoBIN$ + "1" ELSE DECtoBIN$ = DECtoBIN$ + "0"
  79.     NEXT rj
  80.  

  [ You are not allowed to view this attachment ]  

FellippeHeitor

  • Guest
Re: Help please an example taken from wiki is bugged! (Paint tiling)
« Reply #7 on: November 11, 2019, 12:26:31 pm »
Some bits in there set colors too. This is rendered red in QBasic.

FellippeHeitor

  • Guest
Re: Help please an example taken from wiki is bugged! (Paint tiling)
« Reply #8 on: November 11, 2019, 12:26:57 pm »
And without the gaps.

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 #9 on: November 11, 2019, 12:42:08 pm »
Hi Fellippe, Could you add a picture? I'll try to find it.

You say without spaces. This means that some bytes control color. Well, I'm going to look.
« Last Edit: November 11, 2019, 12:52:28 pm by Petr »

FellippeHeitor

  • Guest
Re: Help please an example taken from wiki is bugged! (Paint tiling)
« Reply #10 on: November 11, 2019, 01:36:45 pm »
There.
 [ You are not allowed to view this attachment ]  

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 #11 on: November 11, 2019, 02:55:34 pm »
Thank you.


Well, I can't figure it out. I looked at the Qbasic book and it says that the colors are coded into individual bytes (so, since SCREEN 12 is 4 bit, one byte should carry a 2 pixel color), but the correct color numbers do not match. I do not understand where it takes information about red, when the first two bytes are always zero...  it also seems that the bits in the first two bytes may control the bit mask laying method, which seems to be in the last two bytes. But they're all my assumptions, unsubstantiated. I'll try later, I'm hungry. I try later to add AND for background color cooperations, if it help...
« Last Edit: November 11, 2019, 03:02:48 pm by Petr »

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Help please an example taken from wiki is bugged! (Paint tiling)
« Reply #12 on: November 12, 2019, 09:21:39 am »
Hi
thanks for your time!

1.
tiling is not supported in QB64. I know this also for LINE command!
I have been surprised that there is an example in Wiki of PAINT.

2. about tiling how Qbasic does it....
I can confirm that it is a red wall of bricks also in my Qbasic under Dosbox.

  [ You are not allowed to view this attachment ]  

observing the CHR$ of Tile$ it uses &Hvalue,  3 same value and a forth zero for the 4 values (Row$) while it uses another 3 &H value for the first 3 value of second 4 Row$ and a final zero (the eightth Row$).

I have got strange results using just Row$(1) and/or Row$(5) as Tile$ of PAINT, while Row$(4) or Ror$(8) gives a black square.
So we can assume that using the pattern a decoder mask choose color and what pixel to color!



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 #13 on: November 13, 2019, 08:55:38 am »
Hi Bplus
your bricks are very beautyful!
Thanks also for blu sky!
Programming isn't difficult, only it's  consuming time and coffee

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Help please an example taken from wiki is bugged! (Paint tiling)
« Reply #14 on: November 13, 2019, 10:56:46 am »
Hi TempodiBasic,

You know, it is an interesting problem to "paint" a tile pattern, you've got me thinking (and Petr looks to be making good progress). I know Steve and I did "paint" balls of assorted sizes and colors in a defined rectangular area but "PAINTing" with a colored tile pattern in every nook and cranny not bounded by enclosed areas is a thinker... :)