Skip to content

Commit 981f319

Browse files
author
botamochi6277
committed
Add faces to face-and-color.ino
1 parent 80bac29 commit 981f319

2 files changed

Lines changed: 63 additions & 62 deletions

File tree

Lines changed: 61 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,79 @@
1-
#include <M5Unified.h>
21
#include <Avatar.h>
3-
#include <faces/DogFace.h>
2+
#include <M5Unified.h>
3+
4+
#include <faces/FaceTemplates.hpp>
45

56
using namespace m5avatar;
67

78
Avatar avatar;
89

9-
Face* faces[2];
10-
const int facesSize = sizeof(faces) / sizeof(Face*);
11-
int faceIdx = 0;
10+
Face* faces[5];
11+
const int num_faces = sizeof(faces) / sizeof(Face*);
12+
int face_idx = 0; // face index
1213

13-
const Expression expressions[] = {
14-
Expression::Angry,
15-
Expression::Sleepy,
16-
Expression::Happy,
17-
Expression::Sad,
18-
Expression::Doubt,
19-
Expression::Neutral
20-
};
21-
const int expressionsSize = sizeof(expressions) / sizeof(Expression);
14+
const Expression expressions[] = {Expression::Angry, Expression::Sleepy,
15+
Expression::Happy, Expression::Sad,
16+
Expression::Doubt, Expression::Neutral};
17+
const int num_expressions = sizeof(expressions) / sizeof(Expression);
2218
int idx = 0;
2319

24-
ColorPalette* cps[4];
25-
const int cpsSize = sizeof(cps) / sizeof(ColorPalette*);
26-
int cpsIdx = 0;
20+
ColorPalette* color_palettes[5];
21+
const int num_palettes = sizeof(color_palettes) / sizeof(ColorPalette*);
22+
int palette_idx = 0;
2723

2824
bool isShowingQR = false;
2925

30-
void setup()
31-
{
32-
M5.begin();
33-
M5.Lcd.setBrightness(30);
34-
M5.Lcd.clear();
26+
void setup() {
27+
M5.begin();
28+
M5.Lcd.setBrightness(30);
29+
M5.Lcd.clear();
3530

36-
faces[0] = avatar.getFace();
37-
faces[1] = new DogFace();
31+
faces[0] = avatar.getFace(); // native face
32+
faces[1] = new DoggyFace();
33+
faces[2] = new OmegaFace();
34+
faces[3] = new GirlyFace();
35+
faces[4] = new PinkDemonFace();
3836

39-
cps[0] = new ColorPalette();
40-
cps[1] = new ColorPalette();
41-
cps[2] = new ColorPalette();
42-
cps[3] = new ColorPalette();
43-
cps[1]->set(COLOR_PRIMARY, TFT_YELLOW);
44-
cps[1]->set(COLOR_BACKGROUND, TFT_DARKCYAN);
45-
cps[2]->set(COLOR_PRIMARY, TFT_DARKGREY);
46-
cps[2]->set(COLOR_BACKGROUND, TFT_WHITE);
47-
cps[3]->set(COLOR_PRIMARY, TFT_RED);
48-
cps[3]->set(COLOR_BACKGROUND, TFT_PINK);
37+
color_palettes[0] = new ColorPalette();
38+
color_palettes[1] = new ColorPalette();
39+
color_palettes[2] = new ColorPalette();
40+
color_palettes[3] = new ColorPalette();
41+
color_palettes[4] = new ColorPalette();
42+
color_palettes[1]->set(COLOR_PRIMARY,
43+
M5.Lcd.color24to16(0x383838)); // eye
44+
color_palettes[1]->set(COLOR_BACKGROUND,
45+
M5.Lcd.color24to16(0xfac2a8)); // skin
46+
color_palettes[1]->set(COLOR_SECONDARY,
47+
TFT_PINK); // cheek
48+
color_palettes[2]->set(COLOR_PRIMARY, TFT_YELLOW);
49+
color_palettes[2]->set(COLOR_BACKGROUND, TFT_DARKCYAN);
50+
color_palettes[3]->set(COLOR_PRIMARY, TFT_DARKGREY);
51+
color_palettes[3]->set(COLOR_BACKGROUND, TFT_WHITE);
52+
color_palettes[4]->set(COLOR_PRIMARY, TFT_RED);
53+
color_palettes[4]->set(COLOR_BACKGROUND, TFT_PINK);
4954

50-
avatar.init();
51-
avatar.setColorPalette(*cps[0]);
55+
avatar.init(8); // start drawing w/ 8bit color mode
56+
avatar.setColorPalette(*color_palettes[0]);
5257
}
5358

54-
void loop()
55-
{
56-
M5.update();
57-
if (M5.BtnA.wasPressed())
58-
{
59-
avatar.setFace(faces[faceIdx]);
60-
faceIdx = (faceIdx + 1) % facesSize;
61-
}
62-
if (M5.BtnB.wasPressed())
63-
{
64-
avatar.setColorPalette(*cps[cpsIdx]);
65-
cpsIdx = (cpsIdx + 1) % cpsSize;
66-
}
67-
if (M5.BtnC.wasPressed())
68-
{
69-
avatar.setExpression(expressions[idx]);
70-
idx = (idx + 1) % expressionsSize;
71-
}
59+
void loop() {
60+
M5.update();
61+
// M5Stack Core's button layout:
62+
// -----------
63+
// | |
64+
// | |
65+
// -----------
66+
// [A] [B] [C]
67+
if (M5.BtnA.wasPressed()) {
68+
avatar.setFace(faces[face_idx]);
69+
face_idx = (face_idx + 1) % num_faces; // loop index
70+
}
71+
if (M5.BtnB.wasPressed()) {
72+
avatar.setColorPalette(*color_palettes[palette_idx]);
73+
palette_idx = (palette_idx + 1) % num_palettes;
74+
}
75+
if (M5.BtnC.wasPressed()) {
76+
avatar.setExpression(expressions[idx]);
77+
idx = (idx + 1) % num_expressions;
78+
}
7279
}

src/Eyes.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,11 @@ void PinkDemonEye::drawEyeLid(M5Canvas *canvas) {
231231

232232
float tilt = 0.0f;
233233
float ref_tilt = open_ratio_ * M_PI / 6.0f;
234-
float bias;
235234
if (expression_ == Expression::Angry) {
236235
tilt = this->is_left_ ? -ref_tilt : ref_tilt;
237236
} else if (expression_ == Expression::Sad) {
238237
tilt = this->is_left_ ? ref_tilt : -ref_tilt;
239238
}
240-
bias = 0.2f * width_ * tilt / (M_PI / 6.0f);
241239

242240
if ((open_ratio_ < 0.99f) || (abs(tilt) > 0.1f)) {
243241
// mask
@@ -253,18 +251,14 @@ void PinkDemonEye::drawEyeLid(M5Canvas *canvas) {
253251
shifted_x_, upper_eyelid_y, background_color_);
254252

255253
// eyelid
256-
float eyelid_top_left_x = shifted_x_ - (this->width_ / 2) + bias;
254+
float eyelid_top_left_x = shifted_x_ - (this->width_ / 2);
257255
float eyelid_top_left_y = upper_eyelid_y - 4;
258-
float eyelid_bottom_right_x = shifted_x_ + (this->width_ / 2) + bias;
256+
float eyelid_bottom_right_x = shifted_x_ + (this->width_ / 2);
259257
float eyelid_bottom_right_y = upper_eyelid_y;
260258

261259
fillRectRotatedAround(canvas, eyelid_top_left_x, eyelid_top_left_y,
262260
eyelid_bottom_right_x, eyelid_bottom_right_y,
263261
tilt, shifted_x_, upper_eyelid_y, primary_color_);
264-
265-
eyelash_x0 += bias;
266-
eyelash_x1 += bias;
267-
eyelash_x2 += bias;
268262
}
269263

270264
// eyelash

0 commit comments

Comments
 (0)