Author Topic: Graphics Test #1 Are You Certifiable?  (Read 6506 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Graphics Test #1 Are You Certifiable?
« on: November 21, 2021, 01:32:26 pm »
Create this Pattern:
 
Cert Test #1.PNG


Too easy? Here's 2 mods:
 
Shrinking Chess Patterns.PNG

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Graphics Test #1 Are You Certifiable?
« Reply #1 on: November 21, 2021, 03:52:49 pm »
My wife is of the opinion that I am certifiable.... Does that help?
Logic is the beginning of wisdom.

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: Graphics Test #1 Are You Certifiable?
« Reply #2 on: November 21, 2021, 05:17:41 pm »
While not certifiable, I'll content myself with getting in the ballpark.

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(400, 400, 32)
  2. s% = _WIDTH(0): bx% = 0: by% = 0: i% = 0: a& = &HFFFFFFFF: c& = &HFF000000
  3.     s% = _SHR(s%, 1)
  4.     DO
  5.         SWAP a&, c&
  6.         LINE (bx%, by%)-(bx% + s%, by% + s%), c&, BF
  7.         by% = by% + s%
  8.     LOOP UNTIL by% + s% >= _HEIGHT(0)
  9.     SWAP a&, c&
  10.     bx% = bx% + s%
  11.     by% = 0
  12. LOOP UNTIL bx% >= _WIDTH(0)
  13.  

Ok, given that I'm using _SHR it works better if I change to SCREEN _NEWIMAGE(512, 512, 32)

PS. Oh yeah, and silly me that last LOOP UNTIL should be s% = 1. Task manager told me so...
« Last Edit: November 21, 2021, 05:52:05 pm by OldMoses »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Graphics Test #1 Are You Certifiable?
« Reply #3 on: November 21, 2021, 06:23:14 pm »
Oh you caught just as I was going to post with this:

 
Andy fix.PNG

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Graphics Test #1 Are You Certifiable?
« Reply #4 on: November 21, 2021, 06:33:40 pm »
Could do in less lines (no colons) and not be dependent on powers of 2 for side widths or heights:

 
not dependent on powers of 2.PNG

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Graphics Test #1 Are You Certifiable?
« Reply #5 on: November 21, 2021, 07:31:18 pm »
Well I guess it better to do Shrinking Chess Pattern 2 like this:
 
Shrinking Chess Pattern 2.PNG


To get to this, Shrinking Pattern 3:
 
Shrinking Chess Pattern 3.PNG

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Graphics Test #1 Are You Certifiable?
« Reply #6 on: November 21, 2021, 08:43:27 pm »
How about a different way to do these?

Code: QB64: [Select]
  1. Screen _NewImage(400, 400, 256)
  2. Line (0, 0)-Step(200, 200), 15, BF
  3. Copy
  4.  
  5.  
  6.  
  7. Sub Copy
  8.     t& = _NewImage(200, 200, 256)
  9.     _PutImage , 0, t&, (0, 0)-(199, 399)
  10.     x = 200: count = 1: s = 200
  11.     Do
  12.         Sleep
  13.         count = count * 2
  14.         Locate 1, 1
  15.         For i = 0 To count
  16.             _PutImage (x, i * s)-Step(s / 2, s), t&, 0
  17.         Next
  18.         s = s / 2: x = x + s
  19.     Loop Until x >= 400
  20.  
  21.  

At one point, there was a recursive glitch inside _PUTIMAGE itself that used to do images like this if the destination and source were the same, before I went in and fixed it, which is what made me think about doing something in this manner. 

From this point, you guys should be able to see that the mods are nothing more than just the same idea at work like this, right?  Just take a portion of the screen and then use _putimage to duplicate a portions of it and flip/reverse it as needed to make the other patterns.

What I find a little surprising is the actual number of screens that we reproduce with this.  We go multiple times at the end without seeing any visible change, so we must be drawing partial pixel screens before the total exceeds 400 for us.  LOL![/code]
« Last Edit: November 21, 2021, 09:02:43 pm by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Graphics Test #1 Are You Certifiable?
« Reply #7 on: November 21, 2021, 09:15:45 pm »
Different definitely makes you certifiable!

Luv what Andy and Steve have presented.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Graphics Test #1 Are You Certifiable?
« Reply #8 on: November 22, 2021, 11:49:37 am »
Here's the ordinary way I did it with comments:
Code: QB64: [Select]
  1. Screen _NewImage(1000, 600, 32) '     "Shrinking Chess Pattern tsh73" 'b+ 2021-11-21
  2. For p = 1 To 9 '                       for powers of 2
  3.     lx = _Width / 2 ^ p + lastlx '     left most x
  4.     dy = _Height / 2 ^ p '             change in y's  or the height of the boxes
  5.     For y = 0 To _Height - 2 Step dy ' width of boxes is lx - lastlx
  6.         If i Mod 2 Then Line (lastlx, y)-(lx, y + dy), &HFF000000, BF Else Line (lastlx, y)-(lx, y + dy), &HFFFFFFFF, B
  7.         i = i + 1 '                    this switches colors after each box
  8.     Next
  9.     lastlx = lx '                      before getting next power of 2 update lastlx  with lx the one we just used
  10. Sleep '                                don't ruin the shot with a black line that appears at end of program
  11.  

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: Graphics Test #1 Are You Certifiable?
« Reply #9 on: November 22, 2021, 01:21:47 pm »
Your work is always educational (as is Steve's). That 2 power loop is a pretty cool method, and never would have occurred to me.

I originally was trying to use a MOD 2 routine for color picking, but the implementation was causing errors in my LINE statement for some reason. I couldn't figure out why and just went with SWAP.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Graphics Test #1 Are You Certifiable?
« Reply #10 on: November 22, 2021, 01:54:16 pm »
Your work is always educational (as is Steve's). That 2 power loop is a pretty cool method, and never would have occurred to me.

I originally was trying to use a MOD 2 routine for color picking, but the implementation was causing errors in my LINE statement for some reason. I couldn't figure out why and just went with SWAP.

Either would work with one more box on each inner loop:
Code: QB64: [Select]
  1. Screen _NewImage(512, 512, 32)
  2. s% = _Width
  3. a& = &HFFFFFFFF: c& = &HFF000000
  4.     s% = _SHR(s%, 1)
  5.     Do
  6.         Swap a&, c& ' do an even number of swaps in this loop
  7.         Line (bx%, by%)-(bx% + s%, by% + s%), c&, BF
  8.         by% = by% + s%
  9.     Loop Until by% >= _Height(0) - 1 ' b+ changed to do one more box down y axis so that always start powers with even number
  10.     bx% = bx% + s%
  11.     by% = 0
  12. Loop Until bx% >= _Width(0) - 1 '<<< to actually end computations!
  13.  

Gives this box structure:
 
Boxes drawn.PNG
« Last Edit: November 22, 2021, 01:59:35 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Graphics Test #1 Are You Certifiable?
« Reply #11 on: November 22, 2021, 02:09:50 pm »
And one more line gets to 2nd part, from which 3rd screen might be made:
Code: QB64: [Select]
  1. Screen _NewImage(512, 512, 32)
  2. s% = _Width
  3. a& = &HFFFFFFFF: c& = &HFF000000
  4.     s% = _SHR(s%, 1)
  5.     Do
  6.         Swap a&, c& ' do an even number of swaps in this loop
  7.         Line (bx%, by%)-(bx% + s%, by% + s%), a&, BF
  8.         Line (_Width - 1 - bx%, _Height - 1 - by%)-(_Width - 1 - bx% - s%, -height - 1 - by% - s%), a&, BF
  9.         by% = by% + s%
  10.     Loop Until by% >= _Height(0) - 1 ' b+ changed to do one more box down y axis so that always start powers with even number
  11.     bx% = bx% + s%
  12.     by% = 0
  13. Loop Until bx% >= _Width(0) - 1
  14.  
  15.  

 
Part 2.PNG

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Graphics Test #1 Are You Certifiable?
« Reply #12 on: November 22, 2021, 09:23:49 pm »
Hy guys and gals

fine graphic task!
And see what different results changing the type of variable: Single  on the left versus Integer on the right.
 
What difference between Single and Integer in Shrinking chess.PNG


however attached there is my code, because it is not so schematich like that of OldMoses, not short like that of Bplus and not so good like that of Steve.

Very glad to observe your mind in action boys!
* Shrinked chess pattern 1.bas (Filesize: 0.67 KB, Downloads: 268)
Programming isn't difficult, only it's  consuming time and coffee

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Graphics Test #1 Are You Certifiable?
« Reply #13 on: November 22, 2021, 10:10:07 pm »
@TempodiBasic

I was wondering when your program ended so I put a Beep at the end, never heard it!

OK so maybe Sum never makes it to _Width but should to _Width -1, no? ! ???

WTH? is with Sum, Print, Print... Oh!!!

Needed a fix to quit when you expected it to.
Code: QB64: [Select]
  1.  
  2. Const white = _RGB32(255), black = _RGB32(0), Wscreen = 400, Hscreen = 400
  3. Dim As Single Wsquare, Hsquare, a, Repeat, Left, Top, Sum
  4. Screen _NewImage(Wscreen, Hscreen, 32)
  5. Wsquare = Wscreen / 2
  6.  
  7. Sum = Wsquare ' <<<<<<<<<<<<<<<<<<<<<<<<<<<< fix this to work as TempodiBasic thinks it should
  8. Hsquare = Hscreen / 2
  9. Repeat = 1
  10.     For a = 1 To Repeat
  11.         Line (Left, Top + (Hsquare * (a - 1)))-(Left + Wsquare, Top + (Hsquare * a)), white, BF
  12.         ' Line (Left, Top + (Hsquare * a))-(Left + Wsquare, Top + (Hsquare * (a + 1))), black, BF
  13.         Top = Top + Hsquare
  14.     Next a
  15.     Top = 0
  16.     Repeat = Repeat * 2
  17.     Left = Left + Wsquare
  18.     Wsquare = Wsquare / 2
  19.     Hsquare = Hsquare / 2
  20.     Sum = Sum + Wsquare
  21.     Print Sum ' >>>>>>>>>>>>>>>>>>>>>>>>>>>> what's going on
  22. Loop While Sum <= Wscreen - 1 ' ??? WTH no beep yet????
  23.  

Yeah @TempodiBasic nothing fancy but gets the job done, unless expecting to do something after... ha, ha!

Oh hey! There is a big difference along the right hand side of the graph depending whether you comment out the 2nd  Line statement or not, that draws the Black rectangles.  Check this side by side comparison:
 
TempodiBasic.PNG
« Last Edit: November 22, 2021, 10:15:56 pm by bplus »

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Graphics Test #1 Are You Certifiable?
« Reply #14 on: November 24, 2021, 09:58:28 am »
Hi Bplus
thanks for giving a try to my code.

in it there is a Troy's horse: paradox of Zenone and mathematical concepts of limit and infinitesimal.
Here some explicative links:
https://en.wikipedia.org/wiki/Trojan_Horse
https://en.wikipedia.org/wiki/Zeno%27s_paradoxes#Dichotomy_paradox
https://en.wikipedia.org/wiki/Limit_(mathematics)
https://en.wikipedia.org/wiki/Calculus

but yes it is too visible with my mistake to not initialize a first time
Code: QB64: [Select]
  1. Sum = Wsquare
instead with this your correction it would be more hidden to not mathematical eyes
If you introduce in the DO---LOOP a counter you can see that the loop runs 24 times... but  looking at image we can see not more than 9 kind of graphic column!
With my mistake of not initialize Sum before DO---LOOP it is still running while I have written this post!
LOL math is fantastic but very dangerouse!
 
Zenone.PNG

the difference between Integer and Single variable is gross and its cause is clear.
The difference between drawing only White squares and drawing white and black squares, probably, is in the fact that we cannot draw less than a pixel on the screen.

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