Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A single line function to modify MOD for better pattern recognition....
#3
Thumbs Up 
Well Steve posted while I was about to...

Testing Pete's in a very common situation for us hobbyists:
Code: (Select All)
_Title "MOD versus modx test Petes new thing ;-))" ' b+ 2022-11-28
Screen _NewImage(800, 600, 32)
x = 300: y = 300: dx = -5
Do
    Cls
    Print "spacebar to exit this first screen, I want circle to exit stage left and enter stage right..."
    Circle (x, y), 20
    x = (x + dx) Mod _Width ' head left loop around and head left???
    _Display 'no blinking
    _Limit 10 ' 10 xs per sec
Loop Until _KeyDown(32)
Cls
Locate 15, 20: Print "That sucks, I am talking about normal MOD for negative numbers."
Print
Locate 17, 20: Print "   OK try Pete's new and improved super dupper modx(), zzz..."
_Display
Sleep
_KeyClear
Cls

x = 300: y = 300: dx = -5
Do
    Cls
    Print "escape to quit, circle should leave screen on left and return on right"
    Circle (x, y), 20
    x = modx(x + dx, _Width) ' head left loop around and head left???
    If x > 400 Then
        Locate 30, 30: Print "It works! It works! Holy crap it works!"
    End If
    _Display 'no blinking
    _Limit 10 ' 10 xs per sec
Loop Until _KeyDown(27)

Function modx (i, j)
    modx = (Abs(i) - Abs(j) * ((Abs(i) \ Abs(j)) + (1 - Sgn(i)) \ 2)) * Sgn(i Mod j)
End Function

This is actual situation that comes up and you wish there was a better way. 

Steve's thing should work fine for this but Pete takes on Negative Modulus! What a guy!

Negative Modulus sounds to me like a psychologist looking for business.

OK Pete does this hold pattern for a Modulus of a negative _Float?

2 points for anyone who can come up with some example where a modulus of negative float would be needed.

I confess I am still getting over doing negative integers with MOD let alone floats positive or negative!
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply


Messages In This Thread
RE: A single line function to modify MOD for better pattern recognition.... - by bplus - 11-28-2022, 10:14 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Function IsWord%(test$) bplus 5 240 02-26-2026, 02:51 PM
Last Post: mdijkens
  A hybrid pattern-based data compressor Dav 2 377 12-24-2025, 12:06 PM
Last Post: Dav
  Sample program using the new _Files$ function eoredson 30 9,347 09-29-2025, 02:55 PM
Last Post: dakra137
  Another Dir/File compare function. eoredson 0 528 01-11-2025, 03:48 AM
Last Post: eoredson
  Button rack or hotkey function OldMoses 6 1,502 01-09-2025, 08:20 PM
Last Post: Jack002

Forum Jump:


Users browsing this thread: 1 Guest(s)