This information is all available elsewhere, but I thought it might be helpful to put as much of it together in one place as possible.
I am hoping other people will contribute to this article with their own suggestions of formulae to include (or corrections).
Contents
Floats & Integers
Odd & Even
Left/Right Substrings
Random Numbers/Positions
Lowest/Highest Values
Distances & Angles
Custom Movements
Circles
Built-In Movements
Rectangular Grids
RGB/System Colors
Units of Time
Floats & Integers
Much of the time MMF will automatically convert floats (values with a decimal point) to integers (whole numbers). To force MMF to use floats, you can enter a value with a .0 on the end.
eg.
4 / 3 * 2 = 2
4 / 3.0 * 2 = 2.66667
When retrieving values from objects, it is not possible to do this (you obviously can't say Alterable Value A.o). Instead, you can add 0.0 to the values.
eg. Value.A / (0.0 + Value.B)
Also, X- and Y-positions are always integers. When using custom movements, you should always store an object's X- and Y- positions in alterable values rather than setting them directly. This will make the movement much smoother, as alterable values can store floats and not just integers. The same applies to angles.
Occasionally, you may want integers instead of floats. For this, you can use MMFs built-in conversion function Int().
Differentiate Between Odd & Even
if N mod 2 = 0 , N is Even
if N mod 2 = 1 , N is Odd
Or, for a version that you can copy and paste straight into MMF (just change Point A and Point B);
Angle = Abs(360*Min(Max(Y( Point A )-Y( Point B )+1, 0), 1)-(ASin((X( Point B )-X( Point A ))/Sqr((X( Point A )-X( Point B )) pow 2+((Y( Point A ))-Y( Point B )) pow 2))+270))
Difference Between Two Angles
Returns the difference between two angles, in the range -180 to +180. When rotating an object towards a direction, the sign of this value tells you whether to rotate clockwise or anticlockwise.
System Color Index = Red + (Green * 256) + (Blue * 65536)
Red = abs(((System.index mod 65536) mod 256))
Green = abs((System.index mod 65536) / 256)
Blue = abs(System.index / 65536)
Time
Days = int(Seconds) / 34560
Hours = int(((Seconds) mod 86400) / 1440) mod 24
Minutes = int((Seconds) mod 1440) / 60
Seconds = int(((Seconds) mod 86400) mod 3600) mod 60
The int() is there incase you want to use fractions of seconds (ie. if Seconds is a float).
To create a single string in the format HH:MM.SS (Day D), you can use;
Right$(00+Str$(((Int(value( Seconds )) mod 86400)/1440) mod 24),2)+:+Right$(00+Str$((Int(value( Seconds )) mod 1440)/60), 2)+.+Right$(00+Str$(((Int(value( Seconds )) mod 86400) mod 3600) mod 60), 2)+ (Day +Str$(Int((value( Seconds ))/34560)+1)+)
Formula for animation speed would be good to include here.
And there is a simple(?kinda) formula for angle between objects, it's just trig. Hopefully someone else comes along and posts the formula because I can't see very well on this phone.
Also, is "Angle Between Two Points" method really faster than e.g. Advanced Direction Object? The answer is: no.
I created 10k objects and always set one of their alterable values to angle. I set maximum FPS to 1000 and measured average FPS.
ADO: 66,9
Your formula: 45,4
I also tried that with distance stuff:
ADO: 67,3
Pythagoras: 57,5
Straight-line: 58,5
My bet is that MMF2 interpreter is extremely inefficient Comment edited by RomanX on 7/9/2008
DeadmanDines : Thanks for the suggestion. I've added it to the article.
RomanX : Thanks for going to all the effort - that's useful to know. I didn't mean to suggest that the complicated formula was better than an extension. There are a some people though, who for whatever reason, don't like to use extensions unless they can't do something any other way. Plus I didn't think the article would be complete without it.
With regards speeds; I read it was 6 in an article somewhere (mmf physics or somthing?), and didn't question it. However, since reading your comment I have done some tests. I have come to the conclusion that the correct figure is infact 6.25. To see what I mean, try this;
No, not 8.8, just 8. I meant "It's 8." as separate expression Typical framerate is 50 FPS and if you Always> Set X position to X pos. + 1 for one object, and set speed 8 for another one, they're moving at the same speed.
I can't check your mfa at the moment, so I won't comment it, sorry
We're both right - don't you love it when that happens! (reminds me of an argument I recently had with someone about teenage mutant hero/ninja turtles)
Anyways...
This was my formaula;
Pixels per Second = (Speed * 6.25) * (Framerate / 50)
This is your formula;
Pixels per frame = Speed / 8
This is where the confusion came in (for me at least) - I'm dealing in seconds while you're using frames.
Anyway, using your formula;
Suppose we say Speed is 10.
Pixels per frame = 10 / 8 = 1.25
So now we say "always: add 1.25 to X"
We then use a timer event to check how far the object has moved after 10 secs.
It turns out that it will move 625 pixels in 10 secs (at 50fps).
This is obviously a speed of 62.5 pps, which is what you get from my formula.
I've updated the article to include the formula for pixels-per-frame aswell as pixels-per-second, so thanks for that - it may well be usful to someone. Comment edited by Sketchy on 7/17/2008