|
1 | | -#include <M5Unified.h> |
2 | 1 | #include <Avatar.h> |
3 | | -#include <faces/DogFace.h> |
| 2 | +#include <M5Unified.h> |
| 3 | + |
| 4 | +#include <faces/FaceTemplates.hpp> |
4 | 5 |
|
5 | 6 | using namespace m5avatar; |
6 | 7 |
|
7 | 8 | Avatar avatar; |
8 | 9 |
|
9 | | -Face* faces[2]; |
10 | | -const int facesSize = sizeof(faces) / sizeof(Face*); |
11 | | -int faceIdx = 0; |
| 10 | +Face* faces[6]; |
| 11 | +const int num_faces = sizeof(faces) / sizeof(Face*); |
| 12 | +int face_idx = 0; // face index |
12 | 13 |
|
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); |
22 | 18 | int idx = 0; |
23 | 19 |
|
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; |
27 | 23 |
|
28 | 24 | bool isShowingQR = false; |
29 | 25 |
|
30 | | -void setup() |
31 | | -{ |
32 | | - M5.begin(); |
33 | | - M5.Lcd.setBrightness(30); |
34 | | - M5.Lcd.clear(); |
| 26 | +// an example of customizing |
| 27 | +class MyCustomFace : public Face { |
| 28 | + public: |
| 29 | + MyCustomFace() |
| 30 | + : Face(new UShapeMouth(44, 44, 0, 16), new BoundingRect(222, 160), |
| 31 | + // right eye, second eye arg is center position of eye |
| 32 | + new EllipseEye(32, 32, false), new BoundingRect(163, 64), |
| 33 | + // left eye |
| 34 | + new EllipseEye(32, 32, true), new BoundingRect(163, 256), |
| 35 | + // right eyebrow |
| 36 | + // BowEyebrow's origin is the center of bow (arc) |
| 37 | + new BowEyebrow(64, 20, false), |
| 38 | + new BoundingRect(163, 64), // (y,x) |
| 39 | + // left eyebrow |
| 40 | + new BowEyebrow(64, 20, true), new BoundingRect(163, 256)) {} |
| 41 | +}; |
| 42 | + |
| 43 | +void setup() { |
| 44 | + M5.begin(); |
| 45 | + M5.Lcd.setBrightness(30); |
| 46 | + M5.Lcd.clear(); |
35 | 47 |
|
36 | | - faces[0] = avatar.getFace(); |
37 | | - faces[1] = new DogFace(); |
| 48 | + faces[0] = avatar.getFace(); // native face |
| 49 | + faces[1] = new DoggyFace(); |
| 50 | + faces[2] = new OmegaFace(); |
| 51 | + faces[3] = new GirlyFace(); |
| 52 | + faces[4] = new PinkDemonFace(); |
| 53 | + faces[5] = new MyCustomFace(); |
38 | 54 |
|
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); |
| 55 | + color_palettes[0] = new ColorPalette(); |
| 56 | + color_palettes[1] = new ColorPalette(); |
| 57 | + color_palettes[2] = new ColorPalette(); |
| 58 | + color_palettes[3] = new ColorPalette(); |
| 59 | + color_palettes[4] = new ColorPalette(); |
| 60 | + color_palettes[1]->set(COLOR_PRIMARY, |
| 61 | + M5.Lcd.color24to16(0x383838)); // eye |
| 62 | + color_palettes[1]->set(COLOR_BACKGROUND, |
| 63 | + M5.Lcd.color24to16(0xfac2a8)); // skin |
| 64 | + color_palettes[1]->set(COLOR_SECONDARY, |
| 65 | + TFT_PINK); // cheek |
| 66 | + color_palettes[2]->set(COLOR_PRIMARY, TFT_YELLOW); |
| 67 | + color_palettes[2]->set(COLOR_BACKGROUND, TFT_DARKCYAN); |
| 68 | + color_palettes[3]->set(COLOR_PRIMARY, TFT_DARKGREY); |
| 69 | + color_palettes[3]->set(COLOR_BACKGROUND, TFT_WHITE); |
| 70 | + color_palettes[4]->set(COLOR_PRIMARY, TFT_RED); |
| 71 | + color_palettes[4]->set(COLOR_BACKGROUND, TFT_PINK); |
49 | 72 |
|
50 | | - avatar.init(); |
51 | | - avatar.setColorPalette(*cps[0]); |
| 73 | + avatar.init(8); // start drawing w/ 8bit color mode |
| 74 | + avatar.setColorPalette(*color_palettes[0]); |
52 | 75 | } |
53 | 76 |
|
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 | | - } |
| 77 | +void loop() { |
| 78 | + M5.update(); |
| 79 | + // M5Stack Core's button layout: |
| 80 | + // ----------- |
| 81 | + // | | |
| 82 | + // | | |
| 83 | + // ----------- |
| 84 | + // [A] [B] [C] |
| 85 | + if (M5.BtnA.wasPressed()) { |
| 86 | + avatar.setFace(faces[face_idx]); |
| 87 | + face_idx = (face_idx + 1) % num_faces; // loop index |
| 88 | + } |
| 89 | + if (M5.BtnB.wasPressed()) { |
| 90 | + avatar.setColorPalette(*color_palettes[palette_idx]); |
| 91 | + palette_idx = (palette_idx + 1) % num_palettes; |
| 92 | + } |
| 93 | + if (M5.BtnC.wasPressed()) { |
| 94 | + avatar.setExpression(expressions[idx]); |
| 95 | + idx = (idx + 1) % num_expressions; |
| 96 | + } |
72 | 97 | } |
0 commit comments