QB64 Phoenix Edition
I must be missing something obvious with this code - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3)
+---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10)
+---- Thread: I must be missing something obvious with this code (/showthread.php?tid=3035)



I must be missing something obvious with this code - Dav - 09-15-2024

I was adding a screen flipping effect to a program, and don't see why CLS is needed to remove the edge LINE before the last _PUTIMAGE is called.  I'm putimaging the whole screen at the end, shouldn't that remove the LINE?

- Dav

Code: (Select All)
'==============
'FLIPSCREENHZ.BAS
'==============

Screen _NewImage(1000, 700, 32)

'=== draw stuff
For t = 1 To 50
    Line (Rnd * _Width, Rnd * _Height)-Step(15 + (Rnd * 100), 15 + (Rnd * 100)), _RGB(Rnd * 255, Rnd * 255, Rnd * 255), BF
    Circle (Rnd * _Width, Rnd * _Height), 15 + (Rnd * 100), _RGB(Rnd * 255, Rnd * 255, Rnd * 255)
Next

Locate 12, 12: Print "PRESS ANY KEY TO FILP ME";
'kep pressing any key to flip screen
'ESC exits

Do
    a$ = Input$(1)
    If a$ = Chr$(27) Then End

    FlipScreen

Loop

Sub FlipScreen

    'Flips current screen horizontally

    displayStatus%% = _AutoDisplay 'get current display status

    _Display 'turn off auto screen updates

    scrn& = _CopyImage(_Display)

    x1 = 0: x2 = _Width
    y1 = 0: y2 = _Height

    Do
        'draw screen image
        Cls: _PutImage (x1, y1)-(x2, y2), scrn&

        'draw edge line around it for extra effect
        Line (x1, y1)-(x2, y2), _RGB(128, 128, 128), B

        x1 = x1 + 45: If x1 > _Width Then x1 = _Width
        x2 = x2 - 45: If x2 < 0 Then x2 = 0

        _Display
        _Limit 30
    Loop Until x1 = _Width And x2 = 0

    'Shouldn't _PUTIMAGE below fit the whole screen and remove the edge LINE without needing CLS?
    'CLS

    _PutImage (_Width, 0)-(0, _Height), scrn&
    _Display
    _FreeImage scrn&

    If displayStatus%% = -1 Then _AutoDisplay 'restore previous

End Sub



RE: I must be missing something obvious with this code - SMcNeill - 09-15-2024

Set a variable W and H and make them = Width - 1 and Height - 1.

Your screen dimensions are 0 to Width - 1, not 0 to Width.  Wink


RE: I must be missing something obvious with this code - Dav - 09-15-2024

(09-15-2024, 01:21 PM)SMcNeill Wrote: Set a variable W and H and make them = Width - 1 and Height - 1.

Your screen dimensions are 0 to Width - 1, not 0 to Width.  Wink

Ahhh,  Thanks, Steve.

Woo hoo!  I won the idiot of the day award before 9:30am.  Big Grin 

- Dav


RE: I must be missing something obvious with this code - PhilOfPerth - 09-16-2024

(09-15-2024, 01:31 PM)Dav Wrote:
(09-15-2024, 01:21 PM)SMcNeill Wrote: Set a variable W and H and make them = Width - 1 and Height - 1.

Your screen dimensions are 0 to Width - 1, not 0 to Width.  Wink

Ahhh,  Thanks, Steve.

Woo hoo!  I won the idiot of the day award before 9:30am.  Big Grin 

- Dav

Ok, I'll return my cup; I'll miss it though.  Big Grin


RE: I must be missing something obvious with this code - JRace - 09-16-2024

The off-by-one error is so common that the ISO has considered making it a required standard error.


RE: I must be missing something obvious with this code - TerryRitchie - 09-16-2024

(09-16-2024, 09:43 AM)JRace Wrote: The off-by-one error is so common that the ISO has considered making it a required standard error.
If I had a dollar for every time the off by one error has befuddled me I would be funding flights on a SpaceX Dragon.


RE: I must be missing something obvious with this code - Dimster - 09-16-2024

Steve could likely listen to your car engine and diagnosis an efficiency just by the sound. In fact, I suspect there are a lot of engine whispers on this forum.


RE: I must be missing something obvious with this code - TerryRitchie - 09-16-2024

(09-16-2024, 05:31 PM)Dimster Wrote: Steve could likely listen to your car engine and diagnosis an efficiency just by the sound. In fact, I suspect there are a lot of engine whispers on this forum.
My grandpa (a life-long farmer) definitely had this skill. His Chalmers, Masseys, Fords, and Olivers always ran in perfect condition. Hell, the Alliis Chalmers he used as a cultivator and you had to hand crank that puppy. More than once that damn thing kicked back on me and sent me flying.


RE: I must be missing something obvious with this code - Pete - 09-16-2024

Wait, I missed out on the Idiot of the Day award? Dammit, now I'll have to figure out when the next competition starts! Big Grin Big Grin Big Grin

Pete