11-29-2022, 12:29 AM
Well Steve fixed his and it has much less use of ABS:
BTW don't save file from _title if ;-)) in _title
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 = Steve_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
Function Steve_ModX (num1, num2)
Steve_ModX = ((num1 Mod num2) + Abs(num2)) Mod num2 ' fixed for neg modulus with ABS
End Function
BTW don't save file from _title if ;-)) in _title
b = b + ...