Skip to content

Commit 9da9801

Browse files
author
botamochi6277
committed
Add doggy components
1 parent 6e52efd commit 9da9801

5 files changed

Lines changed: 102 additions & 36 deletions

File tree

src/Eyes.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,4 +312,20 @@ void PinkDemonEye::draw(M5Canvas *canvas, BoundingRect rect, DrawContext *ctx) {
312312
this->drawEyeLid(canvas);
313313
}
314314

315+
void DoggyEye::draw(M5Canvas *canvas, BoundingRect rect, DrawContext *ctx) {
316+
this->update(canvas, rect, ctx);
317+
318+
if (this->open_ratio_ == 0) {
319+
// eye closed
320+
canvas->fillRect(center_x_ - 15, center_y_ - 2, 30, 4, primary_color_);
321+
return;
322+
}
323+
canvas->fillEllipse(center_x_, center_y_, 30, 25, primary_color_);
324+
canvas->fillEllipse(center_x_, center_y_, 28, 23, background_color_);
325+
326+
canvas->fillEllipse(shifted_x_, shifted_y_, 18, 18, primary_color_);
327+
canvas->fillEllipse(shifted_x_ - 3, shifted_y_ - 3, 3, 3,
328+
background_color_);
329+
}
330+
315331
} // namespace m5avatar

src/Eyes.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ class PinkDemonEye : public BaseEye {
6363
void overwriteOpenRatio();
6464
void draw(M5Canvas *canvas, BoundingRect rect, DrawContext *ctx);
6565
};
66+
67+
class DoggyEye : public BaseEye {
68+
public:
69+
using BaseEye::BaseEye;
70+
void draw(M5Canvas *canvas, BoundingRect rect, DrawContext *ctx);
71+
};
6672
} // namespace m5avatar
6773

6874
#endif

src/Mouths.cpp

Lines changed: 54 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ BaseMouth::BaseMouth(uint16_t min_width, uint16_t max_width,
1010
min_height_{min_height},
1111
max_height_{max_height} {}
1212

13-
void BaseMouth::update(M5Canvas *spi, BoundingRect rect, DrawContext *ctx) {
13+
void BaseMouth::update(M5Canvas *canvas, BoundingRect rect, DrawContext *ctx) {
1414
primary_color_ = ctx->getColorDepth() == 1
1515
? 1
1616
: ctx->getColorPalette()->get(COLOR_PRIMARY);
@@ -25,57 +25,82 @@ void BaseMouth::update(M5Canvas *spi, BoundingRect rect, DrawContext *ctx) {
2525
open_ratio_ = ctx->getMouthOpenRatio();
2626
}
2727

28-
void OmegaMouth::draw(M5Canvas *spi, BoundingRect rect, DrawContext *ctx) {
29-
this->update(spi, rect, ctx); // update drawing cache
28+
void OmegaMouth::draw(M5Canvas *canvas, BoundingRect rect, DrawContext *ctx) {
29+
this->update(canvas, rect, ctx); // update drawing cache
3030
uint32_t h = min_height_ + (max_height_ - min_height_) * open_ratio_;
3131
uint32_t w = min_width_ + (max_width_ - min_width_) * (1 - open_ratio_);
3232

3333
// inner mouse
34-
spi->fillEllipse(center_x_, center_y_ - max_height_ / 2, max_width_ / 4,
35-
static_cast<int32_t>(max_height_ * open_ratio_),
36-
primary_color_);
34+
canvas->fillEllipse(center_x_, center_y_ - max_height_ / 2, max_width_ / 4,
35+
static_cast<int32_t>(max_height_ * open_ratio_),
36+
primary_color_);
3737

3838
// omega
39-
spi->fillEllipse(center_x_ - 16, center_y_ - max_height_ / 2, 20, 15,
40-
primary_color_); // outer
41-
spi->fillEllipse(center_x_ + 16, center_y_ - max_height_ / 2, 20, 15,
42-
primary_color_);
43-
spi->fillEllipse(center_x_ - 16, center_y_ - max_height_ / 2, 18, 13,
44-
background_color_); // inner
45-
spi->fillEllipse(center_x_ + 16, center_y_ - max_height_ / 2, 18, 13,
46-
background_color_);
39+
canvas->fillEllipse(center_x_ - 16, center_y_ - max_height_ / 2, 20, 15,
40+
primary_color_); // outer
41+
canvas->fillEllipse(center_x_ + 16, center_y_ - max_height_ / 2, 20, 15,
42+
primary_color_);
43+
canvas->fillEllipse(center_x_ - 16, center_y_ - max_height_ / 2, 18, 13,
44+
background_color_); // inner
45+
canvas->fillEllipse(center_x_ + 16, center_y_ - max_height_ / 2, 18, 13,
46+
background_color_);
4747
// mask for omega
48-
spi->fillRect(center_x_ - max_width_ / 2, center_y_ - max_height_ * 1.5,
49-
max_width_, max_height_, background_color_);
48+
canvas->fillRect(center_x_ - max_width_ / 2, center_y_ - max_height_ * 1.5,
49+
max_width_, max_height_, background_color_);
5050

5151
// cheek
52-
spi->fillEllipse(center_x_ - 132, center_y_ - 23, 24, 10, secondary_color_);
53-
spi->fillEllipse(center_x_ + 132, center_y_ - 23, 24, 10, secondary_color_);
52+
canvas->fillEllipse(center_x_ - 132, center_y_ - 23, 24, 10,
53+
secondary_color_);
54+
canvas->fillEllipse(center_x_ + 132, center_y_ - 23, 24, 10,
55+
secondary_color_);
5456
}
5557

56-
void UShapeMouth::draw(M5Canvas *spi, BoundingRect rect, DrawContext *ctx) {
57-
this->update(spi, rect, ctx); // update drawing cache
58+
void UShapeMouth::draw(M5Canvas *canvas, BoundingRect rect, DrawContext *ctx) {
59+
this->update(canvas, rect, ctx); // update drawing cache
5860
uint32_t h = min_height_ + (max_height_ - min_height_) * open_ratio_;
5961
uint32_t w = min_width_ + (max_width_ - min_width_) * (1 - open_ratio_);
6062

6163
auto ellipse_center_y = center_y_ - max_height_ / 2;
6264
uint16_t thickness = 6;
6365

6466
// back
65-
spi->fillEllipse(center_x_, ellipse_center_y, max_width_ / 2, max_height_,
66-
primary_color_);
67+
canvas->fillEllipse(center_x_, ellipse_center_y, max_width_ / 2,
68+
max_height_, primary_color_);
6769
// rect mask
68-
spi->fillRect(center_x_ - max_width_ / 2, ellipse_center_y - max_height_,
69-
max_width_ + 1, max_height_, background_color_);
70+
canvas->fillRect(center_x_ - max_width_ / 2, ellipse_center_y - max_height_,
71+
max_width_ + 1, max_height_, background_color_);
7072

7173
// inner mouse
72-
spi->fillEllipse(center_x_, ellipse_center_y, max_width_ / 2 - thickness,
73-
(max_height_ - thickness) * (1.0f - open_ratio_),
74-
background_color_);
74+
canvas->fillEllipse(center_x_, ellipse_center_y, max_width_ / 2 - thickness,
75+
(max_height_ - thickness) * (1.0f - open_ratio_),
76+
background_color_);
7577

7678
// cheek
77-
spi->fillEllipse(center_x_ - 132, center_y_ - 23, 24, 10, secondary_color_);
78-
spi->fillEllipse(center_x_ + 132, center_y_ - 23, 24, 10, secondary_color_);
79+
canvas->fillEllipse(center_x_ - 132, center_y_ - 23, 24, 10,
80+
secondary_color_);
81+
canvas->fillEllipse(center_x_ + 132, center_y_ - 23, 24, 10,
82+
secondary_color_);
83+
}
84+
85+
void DoggyMouth::draw(M5Canvas *canvas, BoundingRect rect, DrawContext *ctx) {
86+
this->update(canvas, rect, ctx);
87+
88+
uint32_t h = min_height_ + (max_height_ - min_height_) * open_ratio_;
89+
uint32_t w = min_width_ + (max_width_ - min_width_) * (1 - open_ratio_);
90+
if (h > min_height_) {
91+
canvas->fillEllipse(center_x_, center_y_, w / 2, h / 2, primary_color_);
92+
canvas->fillEllipse(center_x_, center_y_, w / 2 - 4, h / 2 - 4,
93+
TFT_RED);
94+
canvas->fillRect(center_x_ - w / 2, center_y_ - h / 2, w, h / 2,
95+
background_color_);
96+
}
97+
canvas->fillEllipse(center_x_, center_y_ - 15, 10, 6, primary_color_);
98+
canvas->fillEllipse(center_x_ - 28, center_y_, 30, 15, primary_color_);
99+
canvas->fillEllipse(center_x_ + 28, center_y_, 30, 15, primary_color_);
100+
canvas->fillEllipse(center_x_ - 29, center_y_ - 4, 27, 15,
101+
background_color_);
102+
canvas->fillEllipse(center_x_ + 29, center_y_ - 4, 27, 15,
103+
background_color_);
79104
}
80105

81106
} // namespace m5avatar

src/Mouths.hpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,25 @@ class BaseMouth : public Drawable {
3939
BaseMouth(uint16_t min_width, uint16_t max_width, uint16_t min_height,
4040
uint16_t max_height);
4141

42-
void update(M5Canvas *spi, BoundingRect rect, DrawContext *ctx);
42+
void update(M5Canvas *canvas, BoundingRect rect, DrawContext *ctx);
4343
};
4444

4545
class OmegaMouth : public BaseMouth {
4646
public:
4747
using BaseMouth::BaseMouth;
48-
void draw(M5Canvas *spi, BoundingRect rect, DrawContext *ctx);
48+
void draw(M5Canvas *canvas, BoundingRect rect, DrawContext *ctx);
4949
};
5050

5151
class UShapeMouth : public BaseMouth {
5252
public:
5353
using BaseMouth::BaseMouth;
54-
void draw(M5Canvas *spi, BoundingRect rect, DrawContext *ctx);
54+
void draw(M5Canvas *canvas, BoundingRect rect, DrawContext *ctx);
55+
};
56+
57+
class DoggyMouth : public BaseMouth {
58+
public:
59+
using BaseMouth::BaseMouth;
60+
void draw(M5Canvas *canvas, BoundingRect rect, DrawContext *ctx);
5561
};
5662

5763
} // namespace m5avatar

src/faces/FaceTemplates.hpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ class OmegaFace : public Face {
2121
// left eye
2222
new EllipseEye(true), new BoundingRect(165, 84 + 154),
2323
// hide eye brows with setting these height zero
24-
new EllipseEyebrow(15, 0, false), new BoundingRect(67, 96),
25-
new EllipseEyebrow(15, 0, true), new BoundingRect(72, 230)) {}
24+
new EllipseEyebrow(0, 0, false), new BoundingRect(67, 96),
25+
new EllipseEyebrow(0, 0, true), new BoundingRect(72, 230)) {}
2626
};
2727

2828
class GirlyFace : public Face {
@@ -68,8 +68,21 @@ class PinkDemonFace : public Face {
6868
new PinkDemonEye(52, 134, true), new BoundingRect(134, 218),
6969

7070
// hide eye brows with setting these height zero
71-
new Eyeblow(15, 0, false), new BoundingRect(67, 96),
72-
new Eyeblow(15, 0, true), new BoundingRect(72, 230)) {}
71+
new EllipseEyebrow(15, 0, false), new BoundingRect(67, 96),
72+
new EllipseEyebrow(15, 0, true), new BoundingRect(72, 230)) {}
73+
};
74+
75+
class DoggyFace : public Face {
76+
public:
77+
DoggyFace()
78+
: Face(new DoggyMouth(50, 90, 4, 60), new BoundingRect(168, 163),
79+
// right eye, second eye arg is center position of eye
80+
new DoggyEye(false), new BoundingRect(103, 80),
81+
// left eye
82+
new DoggyEye(true), new BoundingRect(106, 240),
83+
// hide eye brows with setting these height zero
84+
new RectEyebrow(15, 2, false), new BoundingRect(67, 96),
85+
new RectEyebrow(15, 2, true), new BoundingRect(72, 230)) {}
7386
};
7487

7588
} // namespace m5avatar

0 commit comments

Comments
 (0)