-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSmiley.h
More file actions
91 lines (67 loc) · 2.78 KB
/
Copy pathSmiley.h
File metadata and controls
91 lines (67 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#ifndef SMILEY_H
#define SMILEY_H
#include <Arduino.h>
#include <Arduino_GFX_Library.h>
class Smiley {
public:
// Constructor with width, height, and smile curvature sequence
// curvature: 0 = straight, -100 = max sorrow, 100 = max smile
Smiley(int width, int height, const int8_t* curvatureSequence, int sequenceLength);
~Smiley();
// Initialize - must be called before draw/update
// Pass the GFX object and center position (centerX, centerY)
// fgColor and bgColor are RGB565 format
// Returns false if memory allocation fails
bool begin(Arduino_GFX* gfx, int centerX, int centerY, uint16_t fgColor = 0xFFFF, uint16_t bgColor = 0x0000);
// Draw current frame to display
void draw();
// Advance to next frame and draw
void update();
// Set current frame index
void setFrame(int frameIndex);
// Set curvature directly (-100 to 100) and draw
void setCurvature(int curvature);
// Get dimensions
int getWidth() const { return _width; }
int getHeight() const { return _height; }
int getFrameCount() const { return _sequenceLength; }
int getCurrentFrame() const { return _currentFrame; }
// Get/set position
int getX() const { return _x; }
int getY() const { return _y; }
void setPosition(int x, int y) { _x = x; _y = y; }
// Buffer size in pixels
int getPixelCount() const { return _width * _height; }
private:
int _width;
int _height;
const int8_t* _curvatureSequence;
int _sequenceLength;
int _currentFrame;
int _x; // Draw position X
int _y; // Draw position Y
int _innerRadius; // Inner radius of circle for scaling features
uint16_t _fgColor;
uint16_t _bgColor;
Arduino_GFX* _gfx;
uint16_t* _baseBuffer; // Contains eyes (static)
uint16_t* _frameBuffer; // Contains full frame (eyes + current smile)
// Render frame buffer with given curvature
void renderFrame(int curvature);
// Helper to set a pixel in the RGB565 buffer
void setPixel(uint16_t* buffer, int x, int y, bool foreground);
// Clear a rectangular region to background
void clearRect(uint16_t* buffer, int x, int y, int w, int h);
// Draw filled ellipse
void drawFilledEllipse(uint16_t* buffer, int cx, int cy, int rx, int ry);
// Draw the smile/frown arc based on curvature (-100 to 100)
void drawSmile(uint16_t* buffer, int curvature);
// Draw thick arc (smile with thickness)
void drawThickArc(uint16_t* buffer, int cx, int cy, int rx, int ry,
int thickness, int curvature, bool isSmile);
// Get smile region bounds
void getSmileRegion(int& x, int& y, int& w, int& h);
// Draw circle outline with thickness
void drawCircle(uint16_t* buffer, int cx, int cy, int radius, int thickness);
};
#endif