Last active
January 5, 2024 12:18
-
-
Save hollyhockberry/fa1ff3dd0b737bfd020406080a719a68 to your computer and use it in GitHub Desktop.
fm-chan #スタックチャン
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) 2024 Inaba (@hollyhockberry) | |
// This software is released under the MIT License. | |
// http://opensource.org/licenses/mit-license.php | |
#include <M5Unified.h> | |
#include <Avatar.h> | |
using m5avatar::BoundingRect; | |
using m5avatar::DrawContext; | |
using m5avatar::Eye; | |
using m5avatar::Eyeblow; | |
class Mouth : public m5avatar::Drawable { | |
public: | |
void draw(M5Canvas *spi, BoundingRect rect, DrawContext* ctx) override { | |
spi->fillRect(0, 0, 320, 60, spi->color332(0, 160, 65)); | |
spi->fillRect(0, 180, 320, 240, spi->color332(0, 140, 214)); | |
const auto minWidth = 50; | |
const auto maxWidth = 90; | |
const auto minHeight = 4; | |
const auto maxHeight = 60; | |
uint16_t primaryColor = ctx->getColorDepth() == 1 ? 1 : ctx->getColorPalette()->get(COLOR_PRIMARY); | |
float breath = std::min(1.0f, ctx->getBreath()); | |
float openRatio = ctx->getMouthOpenRatio(); | |
int h = minHeight + (maxHeight - minHeight) * openRatio; | |
int w = minWidth + (maxWidth - minWidth) * (1 - openRatio); | |
int x = rect.getLeft() - w / 2; | |
int y = rect.getTop() - h / 2 + breath * 2; | |
spi->fillRect(x, y, w, h, primaryColor); | |
} | |
}; | |
m5avatar::Face face( | |
new Mouth(), new BoundingRect(148, 163), | |
new Eye(8, false), new BoundingRect(93, 90), | |
new Eye(8, true), new BoundingRect(96, 230), | |
new Eyeblow(32, 0, false), new BoundingRect(67, 96), | |
new Eyeblow(32, 0, true), new BoundingRect(72, 230)); | |
m5avatar::Avatar avatar(&face); | |
void setup() { | |
M5.begin(); | |
avatar.init(8); | |
auto cp = avatar.getColorPalette(); | |
cp.set(COLOR_PRIMARY, BLACK); | |
cp.set(COLOR_BACKGROUND, WHITE); | |
avatar.setColorPalette(cp); | |
} | |
void loop() { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment