summaryrefslogtreecommitdiff
path: root/AnimationObject.c
blob: 63594ced620971612b74e59a1362a780a2803e5e (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "AnimationObject.h"
#include <math.h>
#include <stdlib.h>

ARGB
AO_CheckerPattern(const Animation* anim, PixelRendererParams a) {
	struct AO_CheckerPattern chp = *(struct AO_CheckerPattern*)a.priv;

	a.row /= chp.squareSize;
	a.col /= chp.squareSize;

	if ((a.row + a.col) % 2 == 0) {
		ARGB_set(&a.pixel, 0xFF000000);
	}
	else {
		ARGB_set(&a.pixel, 0xFFFF00FF);
	}

	return a.pixel;
}

ARGB
AO_Square(const Animation* anim, PixelRendererParams a) {
	struct AO_Square* set = (struct AO_Square*)a.priv;

	if (0 <= a.row && a.row <= set->width && 0 <= a.col && a.col <= set->height) {
		ARGB_set(&a.pixel, set->color);
	}

	return a.pixel;
}

ARGB
AO_Circle(const Animation* anim, PixelRendererParams a) {
	struct AO_Circle* cir = (struct AO_Circle*)a.priv;

	if (a.row * a.row + a.col * a.col < cir->radius * cir->radius) {
		ARGB_set(&a.pixel, cir->color);
	}

	return a.pixel;
}

ARGB
AO_Image(const Animation* anim, PixelRendererParams a) {
	struct AO_Image img = *(struct AO_Image*)a.priv;

	if (img.noRepeat == true &&
		(a.col < 0 || img.img.width * img.zoom <= a.col ||
		 a.row < 0 || img.img.height * img.zoom <= a.row))
	{
		return a.pixel;
	}

	return *RGBImage_at(*(RGBImage*)a.priv, a.row / img.zoom, a.col / img.zoom);
}

ARGB
AO_Line(const Animation* anim, PixelRendererParams a) {
	struct AO_Line l = *(struct AO_Line*)a.priv;

	if (fabs(l.a * a.col + l.b * a.row + l.c) / sqrt(l.a * l.a + l.b * l.b) < l.width) {
		ARGB_set(&a.pixel, l.color);
	}

	return a.pixel;
}

ARGB
AO_HorSegment(const Animation* anim, PixelRendererParams a) {
	struct AO_HorSegment hs = *(struct AO_HorSegment*)a.priv;

	if (abs(a.row) <= hs.width && hs.left <= a.col && a.col <= hs.right) {
		ARGB_set(&a.pixel, hs.color);
	}

	return a.pixel;
}