BlitzCoder Essentials
•
Home Page
•
About BlitzCoder
•
Contributors
•
Terms of Use
•
Email Us
Main Areas
•
BlitzCoder Chat
•
Discussions
•
Articles/Tutorials
•
Code Database
•
Link Database
•
Showcase Area
•
Worklogs
•
Competitions
Special Areas
•
Undocumented
Other Blitz Sites
•
Blitz Basic Home
•
Blitz Showcase
•
BlitzPlay Library
Forum Login
Username:
Password:
•
Register Now!
BlitzCoder Code Archives Page
Main Codes Page
"RangeValue function"
, by thechange
Returns capped/warped/shifted value between a minimum and maximum range.
Code
; ; If you find any faster way of doing this, I'd be very happy to find out about it :) ; ; Have fun! =) ; ; ; ------------------------------------------------------------------------------------------------------------------------------ ; ; RangeValue function ; ------------------------------------------------------------------------------------------------------------------------------ ; ; Function RangeValue ( Value , Minimum , Maximum ) Range = Maximum - Minimum If Value < Minimum Then Value = ( Value - Maximum ) Mod ( Range + 1 ) + Maximum Return ( Value - Minimum ) Mod ( Range + 1 ) + Minimum End Function ; ; ------------------------------------------------------------------------------------------------------------------------------ ; ; Demo program ; ------------------------------------------------------------------------------------------------------------------------------ ; ; Graphics 200 , 600 , 0 , 2 ;= Range/caption Minimum = -5 Maximum = 5 ;= Display For Value = -20 To 20 Print Value + " = " + RangeValue ( Value , Minimum , Maximum ) Next WaitKey End ;--> ; ; And indeed there are faster ways; ; Here's a couple of absolutely *stunning* functions by the great Halo. ; Who seems to have vanished :( ; Function WrapAngle% (Value%) ;Halo's function to wrap any angle to 0-360 Local a% = value/360 a = value - a * 360 If Sgn(a) = -1 Then a = a + 360 Return a End Function ;WrapAngle() by halo Function wrapangle#(value#) a#=Floor(value/360) Return value-a*360 End Function ; It's so small and so fast, it just ain't funny anymore! :D :D :D ; ; A big smooch to Halo ;)
Copyright(c) 2000-2004, BlitzCoder. All Rights Reserved.
Code software created by Krylar's Kreations