Jump to content

MathForTruants: Difference between revisions

From Parasol
No edit summary
 
 
Line 60: Line 60:
==Sine / Cosine==
==Sine / Cosine==
=====Keep in Mind=====
=====Keep in Mind=====
For repeating patterns:
For repeating animation:
 
=== (sin((frame+timeoffset)*frequency)*amplitude)+offset ===
=== (sin((frame+timeoffset)*frequency)*amplitude)+offset ===


For circular motion:
For circular motion:
=== X = sin(time) and Y = cos(time) ===
=== X = sin(time) and Y = cos(time) ===

Latest revision as of 10:38, 5 November 2010

Math for truants

[edit]

Purpose

[edit]

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

[edit]

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

[edit]

Loops

[edit]

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
[edit]

For loops:

imageframe = (frame % totalframes) + offset

[edit]

Sine / Cosine

[edit]
Keep in Mind
[edit]

For repeating animation:

(sin((frame+timeoffset)*frequency)*amplitude)+offset

[edit]

For circular motion:

X = sin(time) and Y = cos(time)

[edit]