-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGFX.ino
More file actions
134 lines (103 loc) · 4.64 KB
/
GFX.ino
File metadata and controls
134 lines (103 loc) · 4.64 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
void intro() {
// MAGENTA => VERT
// FFFF => bleu
// 000 => noir
// 0F0 => bleu
// FFF => bleu fort
// TFT_NAVY => NOIR
image_in_memory.fillScreen(TFT_WHITE);
image_in_memory.setFont(&fonts::FreeMonoBold24pt7b);
image_in_memory.setTextSize(1);
image_in_memory.setTextColor(TFT_BLUE);
image_in_memory.setCursor(5, 30);
image_in_memory.println("BOTTLE");
image_in_memory.setTextColor(TFT_RED);
image_in_memory.setCursor(5, 100);
image_in_memory.println("FILLER");
image_in_memory.pushSprite(0, 0);
bottle_position_x = 250, bottle_position_y = 100;
bottle_scaling = 1.7;
beer_in_memory.createSprite(1 + 24 * bottle_scaling, 1 + bottle_scaling * (72));
// Remplissage virtuel
for (int i = 0; i < 100; i++) {
draw_beer_bottle(bottle_position_x, bottle_position_y, i, 100, TFT_BEER, TFT_BLACK, false);
delay(20);
}
delay(1000);
// Clear intro screen
image_in_memory.fillScreen(TFT_BLACK);
image_in_memory.pushSprite(0, 0);
appState = STATE_MAIN_MENU;
drawMenu();
}
void draw_beer_bottle(int x_position, int y_position, int poids_actuel, int poids_final, uint32_t liquid_color, uint32_t bottle_color, boolean menu) {
// A D2 B
// 0 b ----------
// | |
// H2 | |
// H | | C
// / \
// HG / \
// / \
// G | | D
// | |
// H1 | |
// | |
// | |
// F ---------------- E
// D1
// x_sprite_dimension = 1+ 24 * bottle_scaling
// y_sprite_dimension = 1+ bottle_scaling * ( 72);
// bottle_scaling = 1 -> sprite de 25x73
// bottle_scaling = 1.7 -> sprite de 41x124
// bottle_scaling = 2.5 -> sprite de 61x181
D1 = 24 * bottle_scaling;
D2 = 9 * bottle_scaling;
H1 = 45 * bottle_scaling;
HG = 18 * bottle_scaling;
H2 = 9 * bottle_scaling;
b = (D1 - D2) / 2, ax = b, ay = 0, bx = b + D2, by = 0, cx = bx, cy = H2, dx = D1;
dy = H2 + HG, ex = D1, ey = H1 + HG + H2, fx = 0, fy = H1 + HG + H2, gx = 0, gy = H2 + HG, hx = ax, hy = H2;
if ((poids_actuel <= poids_final) && (poids_actuel >= 0)) {
new_beer_height = poids_actuel * (H1 + HG) / poids_final;
if (new_beer_height >= old_beer_height) {
// Create a 8 bit sprite 80 pixels wide, 35 high (2800 bytes of RAM needed)
// beer_in_memory.createSprite(D1 + 1, H1 + HG + H2 + 1);
// Fill it with black (this will be the transparent colour this time)
beer_in_memory.setColorDepth(16);
beer_in_memory.fillSprite(transparent_color);
// beer rectangle
beer_in_memory.fillRect(0, H1 + H2 + HG - new_beer_height, D1, new_beer_height, liquid_color);
// Dessin de la forme negative de la bouteille
beer_in_memory.fillRect(0, 0, ax, hy, transparent_color);
beer_in_memory.fillRect(bx, by, b + 2, hy, transparent_color);
beer_in_memory.fillTriangle(0, hy, gx, gy, hx, hy, transparent_color);
beer_in_memory.fillTriangle(cx, cy, dx, dy, ex, cy, transparent_color);
// Bouteille
beer_in_memory.drawLine(ax + 1, ay, bx - 1, by, bottle_color);
beer_in_memory.drawLine(bx - 1, by, cx - 1, cy, bottle_color);
beer_in_memory.drawLine(cx - 1, cy, dx - 1, dy, bottle_color);
beer_in_memory.drawLine(dx - 1, dy, ex - 1, ey, bottle_color);
beer_in_memory.drawLine(ex, ey - 1, fx + 1, fy - 1, bottle_color);
beer_in_memory.drawLine(fx + 1, fy, gx + 1, gy, bottle_color);
beer_in_memory.drawLine(gx + 1, gy, hx, hy, bottle_color);
beer_in_memory.drawLine(hx, hy, ax, ay, bottle_color);
// double ligne
beer_in_memory.drawLine(ax + 1, ay + 1, bx - 1, by + 1, bottle_color);
beer_in_memory.drawLine(bx, by - 1, cx, cy, bottle_color);
beer_in_memory.drawLine(cx, cy, dx, dy, bottle_color);
beer_in_memory.drawLine(dx, dy, ex, ey + 1, bottle_color);
beer_in_memory.drawLine(ex, ey, fx + 1, fy, bottle_color);
beer_in_memory.drawLine(fx, fy + 1, gx, gy, bottle_color);
beer_in_memory.drawLine(gx, gy, hx - 1, hy, bottle_color);
beer_in_memory.drawLine(hx - 1, hy, ax - 1, ay, bottle_color);
// Push sprite to TFT screen CGRAM at coordinate x,y (top left corner)
// Specify what colour is to be treated as transparent.
if (menu == false) {
beer_in_memory.pushSprite(x_position, y_position, transparent_color);
} else {
beer_in_memory.pushSprite(&image_in_memory, x_position, y_position, transparent_color);
}
}
}
}