summaryrefslogtreecommitdiff
path: root/AnimationMove.c
blob: 487d2206373242f9289e88d34bb84db421208327 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "AnimationMove.h"
#include <math.h>

ARGB
AM_MoveLinear(const Animation* anim, u32 frameIndex, ARGB pixel, i32 r, i32 c, void* priv) {
	struct AM_MoveLinear ml = *(struct AM_MoveLinear*)priv;

	r = (r - ml.startRow - (i32)(frameIndex * ml.dRow));
	c = (c - ml.startCol - (i32)(frameIndex * ml.dCol));

	if (ml.wrapCoordinates == true) {
		r %= anim->width;
		c %= anim->height;
	}

	return ml.callback(anim, frameIndex, pixel, r, c, ml.priv);
}

ARGB
AM_MoveSpin(const Animation* anim, u32 frameIndex, ARGB pixel, i32 r, i32 c, void* priv) {
	struct AM_MoveSpin ms = *(struct AM_MoveSpin*)priv;

	double radius = sqrt(r * r + c * c);
	double phi = atan2(c, r);

	phi += ms.theta * frameIndex;

	r = (ms.centerRow + (i32)(radius * cos(phi)));
	c = (ms.centerCol + (i32)(radius * sin(phi)));

	return ms.callback(anim, frameIndex, pixel, r, c, ms.priv);
}