-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimate.c
67 lines (57 loc) · 1.94 KB
/
animate.c
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
#include <unistd.h>
#include "animate.h"
///=============================================================================
///==== Outside-In Animation, with specified time per frame ====================
///=============================================================================
void outsideInAnimation(int time, Display d, int isColor, Color color) {
createFrame('#', d, color);
buildDisplay(d, isColor);
usleep(time*1000);
int h = getMinHalf(d);
for(int i = 0; i <= h; i+=2){
createBox('#', d, i, i, d.size.columns - i,d.size.lines - i, color);
buildDisplay(d, isColor);
usleep(time*1000);
}
}
///=============================================================================
///==== Inside-out Animation, with specified time per frame ====================
///=============================================================================
void insideOutAnimation(int time, Display d, int isColor, Color color) {
createFrame('#', d, color);
buildDisplay(d, isColor);
usleep(time*1000);
int halfC = d.size.columns / 2;
int halfL = d.size.lines / 2;
int h = getMaxHalf(d);
for(int i = 0; i <= h; i+=2){
createBox('#', d, halfC - i, halfL - i, halfC + i ,halfL + i, color);
buildDisplay(d, isColor);
usleep(time*1000);
}
}
///=============================================================================
///==== Helper functions for getting bigger/smaller half from display size =====
///=============================================================================
int getMaxHalf(Display d) {
int halfC = d.size.columns / 2;
int halfL = d.size.lines / 2;
int h;
if(halfC>halfL){
h = halfC;
} else {
h = halfL;
}
return h;
}
int getMinHalf(Display d) {
int halfC = d.size.columns / 2;
int halfL = d.size.lines / 2;
int h;
if(halfC<halfL){
h = halfC;
} else {
h = halfL;
}
return h;
}