MathForTruants: Difference between revisions
No edit summary |
(No difference)
|
Revision as of 17:18, 4 November 2010
Math for truants
Purpose
This site is meant as a cookbook for people who skipped math classes in favour of Rock'n'Roll but might find some formulas handy for graphical or animation work.
This is not meant to be super accurate or political correct, but as a cheat sheet which is easy to remember.
Modulo
Modulo or "mod" in most scripting languages "%" returns the remaining number of a division. For example:
25 / 25 = 1 -> 0 remains
So:
25 % 25 = 0
... while:
26 / 25 = 1.xx -> 1 remains (25*1 + 1 = 26)
So:
26 % 25 = 1
... while:
27 / 25 = 1.xx -> 2 remains (25*1 + 2 = 27)
So:
27 % 25 = 2
Purpose
Loops
Let's say you have 5 images and want to loop through them. frame defines the current frame: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ... imageframe is the frame we will use as frame for the current looped image.
imageframe = frame % 5
Results:
frame = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ...
... while:
imageframe = 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2 ...
Now we can use imageframe as frame for the image to have a infinite loop of 5 frames. If you need to offset the result just add or subtract your offset.
Keep in Mind
For loops:
imageframe = (frame % totalframes) + offset
Sine / Cosine
Keep in Mind
For repeating patterns:
(sin((frame+timeoffset)*frequency)*amplitude)+offset
For circular motion: