Skip to content

Commit 80bac29

Browse files
author
botamochi6277
committed
Add SimpleFace
1 parent 97b8564 commit 80bac29

4 files changed

Lines changed: 54 additions & 37 deletions

File tree

src/DrawingUtils.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ void rotatePointAround(float &x, float &y, float angle, float cx, float cy) {
1818
}
1919

2020
void fillRotatedRect(M5Canvas *canvas, uint16_t cx, uint16_t cy, uint16_t w,
21-
u_int16_t h, float angle, uint16_t color) {
21+
uint16_t h, float angle, uint16_t color) {
2222
float top_left_x = cx - w / 2;
2323
float top_left_y = cy - h / 2;
2424

@@ -45,8 +45,8 @@ void fillRotatedRect(M5Canvas *canvas, uint16_t cx, uint16_t cy, uint16_t w,
4545

4646
void fillRectRotatedAround(M5Canvas *canvas, float top_left_x, float top_left_y,
4747
float bottom_right_x, float bottom_right_y,
48-
float angle, uint16_t cx, u_int16_t cy,
49-
u_int16_t color) {
48+
float angle, uint16_t cx, uint16_t cy,
49+
uint16_t color) {
5050
float top_right_x = bottom_right_x;
5151
float top_right_y = top_left_y;
5252

src/DrawingUtils.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ void rotatePoint(float &x, float &y, float angle);
2222
void rotatePointAround(float &x, float &y, float angle, float cx, float cy);
2323

2424
void fillRotatedRect(M5Canvas *canvas, uint16_t cx, uint16_t cy, uint16_t w,
25-
u_int16_t h, float angle, uint16_t color);
25+
uint16_t h, float angle, uint16_t color);
2626

2727
void fillRectRotatedAround(M5Canvas *canvas, float top_left_x, float top_left_y,
2828
float bottom_right_x, float bottom_right_y,
29-
float angle, uint16_t cx, u_int16_t cy,
30-
u_int16_t color);
29+
float angle, uint16_t cx, uint16_t cy,
30+
uint16_t color);
3131

3232
} // namespace m5avatar
3333

src/Eyes.cpp

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ void EllipseEye::draw(M5Canvas *canvas, BoundingRect rect, DrawContext *ctx) {
5252
this->width_ / 2 - thickness,
5353
this->height_ / 4 + thickness, background_color_);
5454
canvas->fillRect(shifted_x_ - this->width_ / 2,
55-
wink_base_y + thickness / 2, this->width_,
56-
this->height_ / 4, background_color_);
55+
wink_base_y + thickness / 2, this->width_ + 1,
56+
this->height_ / 4 + 1, background_color_);
5757
return;
5858
}
5959

@@ -104,13 +104,14 @@ void GirlyEye::drawEyeLid(M5Canvas *canvas) {
104104
auto upper_eyelid_y = shifted_y_ - 0.8f * height_ / 2 +
105105
(1.0f - open_ratio_) * this->height_ * 0.6;
106106

107-
float el_x0, el_y0, el_x1, el_y1, el_x2, el_y2;
108-
el_x0 = this->is_left_ ? shifted_x_ + 22 : shifted_x_ - 22;
109-
el_y0 = upper_eyelid_y - 27;
110-
el_x1 = this->is_left_ ? shifted_x_ + 26 : shifted_x_ - 26;
111-
el_y1 = upper_eyelid_y;
112-
el_x2 = this->is_left_ ? shifted_x_ - 10 : shifted_x_ + 10;
113-
el_y2 = upper_eyelid_y;
107+
float eyelash_x0, eyelash_y0, eyelash_x1, eyelash_y1, eyelash_x2,
108+
eyelash_y2;
109+
eyelash_x0 = this->is_left_ ? shifted_x_ + 22 : shifted_x_ - 22;
110+
eyelash_y0 = upper_eyelid_y - 27;
111+
eyelash_x1 = this->is_left_ ? shifted_x_ + 26 : shifted_x_ - 26;
112+
eyelash_y1 = upper_eyelid_y;
113+
eyelash_x2 = this->is_left_ ? shifted_x_ - 10 : shifted_x_ + 10;
114+
eyelash_y2 = upper_eyelid_y;
114115

115116
float tilt = 0.0f;
116117
float ref_tilt = open_ratio_ * M_PI / 6.0f;
@@ -145,17 +146,17 @@ void GirlyEye::drawEyeLid(M5Canvas *canvas) {
145146
eyelid_bottom_right_x, eyelid_bottom_right_y,
146147
tilt, shifted_x_, upper_eyelid_y, primary_color_);
147148

148-
el_x0 += bias;
149-
el_x1 += bias;
150-
el_x2 += bias;
149+
eyelash_x0 += bias;
150+
eyelash_x1 += bias;
151+
eyelash_x2 += bias;
151152
}
152153

153154
// eyelash
154-
rotatePointAround(el_x0, el_y0, tilt, shifted_x_, upper_eyelid_y);
155-
rotatePointAround(el_x1, el_y1, tilt, shifted_x_, upper_eyelid_y);
156-
rotatePointAround(el_x2, el_y2, tilt, shifted_x_, upper_eyelid_y);
157-
canvas->fillTriangle(el_x0, el_y0, el_x1, el_y1, el_x2, el_y2,
158-
primary_color_);
155+
rotatePointAround(eyelash_x0, eyelash_y0, tilt, shifted_x_, upper_eyelid_y);
156+
rotatePointAround(eyelash_x1, eyelash_y1, tilt, shifted_x_, upper_eyelid_y);
157+
rotatePointAround(eyelash_x2, eyelash_y2, tilt, shifted_x_, upper_eyelid_y);
158+
canvas->fillTriangle(eyelash_x0, eyelash_y0, eyelash_x1, eyelash_y1,
159+
eyelash_x2, eyelash_y2, primary_color_);
159160
}
160161

161162
void GirlyEye::overwriteOpenRatio() {
@@ -219,13 +220,14 @@ void PinkDemonEye::drawEyeLid(M5Canvas *canvas) {
219220
auto upper_eyelid_y = shifted_y_ - 0.8f * height_ / 2 +
220221
(1.0f - open_ratio_) * this->height_ * 0.6;
221222

222-
float el_x0, el_y0, el_x1, el_y1, el_x2, el_y2;
223-
el_x0 = this->is_left_ ? shifted_x_ + 22 : shifted_x_ - 22;
224-
el_y0 = upper_eyelid_y - 27;
225-
el_x1 = this->is_left_ ? shifted_x_ + 26 : shifted_x_ - 26;
226-
el_y1 = upper_eyelid_y;
227-
el_x2 = this->is_left_ ? shifted_x_ - 10 : shifted_x_ + 10;
228-
el_y2 = upper_eyelid_y;
223+
float eyelash_x0, eyelash_y0, eyelash_x1, eyelash_y1, eyelash_x2,
224+
eyelash_y2;
225+
eyelash_x0 = this->is_left_ ? shifted_x_ + 22 : shifted_x_ - 22;
226+
eyelash_y0 = upper_eyelid_y - 27;
227+
eyelash_x1 = this->is_left_ ? shifted_x_ + 26 : shifted_x_ - 26;
228+
eyelash_y1 = upper_eyelid_y;
229+
eyelash_x2 = this->is_left_ ? shifted_x_ - 10 : shifted_x_ + 10;
230+
eyelash_y2 = upper_eyelid_y;
229231

230232
float tilt = 0.0f;
231233
float ref_tilt = open_ratio_ * M_PI / 6.0f;
@@ -260,15 +262,15 @@ void PinkDemonEye::drawEyeLid(M5Canvas *canvas) {
260262
eyelid_bottom_right_x, eyelid_bottom_right_y,
261263
tilt, shifted_x_, upper_eyelid_y, primary_color_);
262264

263-
el_x0 += bias;
264-
el_x1 += bias;
265-
el_x2 += bias;
265+
eyelash_x0 += bias;
266+
eyelash_x1 += bias;
267+
eyelash_x2 += bias;
266268
}
267269

268270
// eyelash
269-
rotatePointAround(el_x0, el_y0, tilt, shifted_x_, upper_eyelid_y);
270-
rotatePointAround(el_x1, el_y1, tilt, shifted_x_, upper_eyelid_y);
271-
rotatePointAround(el_x2, el_y2, tilt, shifted_x_, upper_eyelid_y);
271+
rotatePointAround(eyelash_x0, eyelash_y0, tilt, shifted_x_, upper_eyelid_y);
272+
rotatePointAround(eyelash_x1, eyelash_y1, tilt, shifted_x_, upper_eyelid_y);
273+
rotatePointAround(eyelash_x2, eyelash_y2, tilt, shifted_x_, upper_eyelid_y);
272274
}
273275

274276
void PinkDemonEye::overwriteOpenRatio() {

src/faces/FaceTemplates.hpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,22 @@
77
#include "Mouths.hpp"
88

99
namespace m5avatar {
10-
10+
/**
11+
* @brief face template for "o_o"
12+
*
13+
*/
14+
class SimpleFace : public Face {
15+
public:
16+
SimpleFace()
17+
: Face(new RectMouth(50, 90, 4, 60), new BoundingRect(148, 163),
18+
// right eye, second eye arg is center position of eye in (y,x)
19+
new EllipseEye(16, 16, false), new BoundingRect(93, 90),
20+
// left eye
21+
new EllipseEye(16, 16, true), new BoundingRect(96, 230),
22+
// hide eye brows with setting these height zero
23+
new EllipseEyebrow(0, 0, false), new BoundingRect(67, 96),
24+
new EllipseEyebrow(0, 0, true), new BoundingRect(72, 230)) {}
25+
};
1126
/**
1227
* @brief face template for "OωO" face
1328
*

0 commit comments

Comments
 (0)