Compare commits
No commits in common. "075f434997f01b709493ad1a636c1f6e01d6d5e8" and "937850c90adbe8e25ff5b38a5ab82c68fd1866b1" have entirely different histories.
075f434997
...
937850c90a
@ -3,16 +3,9 @@
|
||||
#include "config.h"
|
||||
#include "prototypes.h"
|
||||
|
||||
enum SubpixelRenderingMode {
|
||||
SUBPIXEL_RENDERING_SET,
|
||||
SUBPIXEL_RENDERING_ADD,
|
||||
SUBPIXEL_RENDERING_RAISE
|
||||
};
|
||||
|
||||
class Window {
|
||||
private:
|
||||
void _circle_point(int x0, int y0, int x1, int y1, CRGB* color);
|
||||
void _subpixel_render(uint8_t x, uint8_t y, CRGB* color, SubpixelRenderingMode m);
|
||||
public:
|
||||
const uint8_t x, y;
|
||||
const uint8_t width, height;
|
||||
@ -26,7 +19,7 @@ public:
|
||||
void clear();
|
||||
void clear(CRGB* color);
|
||||
void setPixel(uint8_t x, uint8_t y, CRGB* color);
|
||||
void setSubPixel(accum88 x, accum88 y, CRGB* color, SubpixelRenderingMode m = SUBPIXEL_RENDERING_ADD);
|
||||
void setSubPixel(accum88 x, accum88 y, CRGB* color);
|
||||
void setPixelByIndex(uint16_t index, CRGB* color);
|
||||
void raisePixel(uint8_t x, uint8_t y, CRGB* color);
|
||||
void line(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, CRGB* color);
|
||||
|
@ -8,9 +8,10 @@ private:
|
||||
CRGB _color_seconds = CRGB(0xFF0000);
|
||||
|
||||
void _draw_seconds();
|
||||
void _draw_border_pixel(uint8_t second, CRGB* color);
|
||||
void _draw_border_pixel(uint8_t second, uint8_t part, CRGB* color);
|
||||
|
||||
public:
|
||||
void loop();
|
||||
String get_name() override { return "big_clock"; }
|
||||
};
|
||||
|
||||
|
@ -54,7 +54,6 @@ void Window::drawSubText(Font* font, accum88 x, accum88 y, String text, CRGB* co
|
||||
}
|
||||
|
||||
void Window::drawChar(Font* font, accum88 xPos, accum88 yPos, const char c, CRGB* color, bool mask) {
|
||||
SubpixelRenderingMode mode = mask ? SUBPIXEL_RENDERING_SET : SUBPIXEL_RENDERING_ADD;
|
||||
if (!font->isCharAllowed(c)) return;
|
||||
uint16_t position = font->getCharPosition(c);
|
||||
uint8_t* data = new uint8_t[font->width];
|
||||
@ -63,7 +62,7 @@ void Window::drawChar(Font* font, accum88 xPos, accum88 yPos, const char c, CRGB
|
||||
for(uint8_t y=0; y<font->height; y++) for(uint8_t x=0; x<font->width; x++) {
|
||||
bool on = (data[x]>>(font->height - 1 - y) & 1) * 255;
|
||||
if (mask) on = !on;
|
||||
if (on) this->setSubPixel(xPos + (x<<8), yPos + (y<<8), color, mode);
|
||||
if (on) this->setSubPixel(xPos + (x<<8), yPos + (y<<8), color);
|
||||
}
|
||||
|
||||
free(data);
|
||||
@ -80,7 +79,7 @@ void Window::shift_down() {
|
||||
leds[coordsToGlobalIndex(x, y)] = leds[coordsToGlobalIndex(x, y-1)];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
clear_row(0);
|
||||
}
|
||||
|
||||
@ -154,12 +153,12 @@ void Window::line(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, CRGB* color) {
|
||||
// Bresenham algorithm
|
||||
int dx = x2-x1;
|
||||
int dy = y2-y1;
|
||||
|
||||
|
||||
int x = x1;
|
||||
int y = y1;
|
||||
|
||||
|
||||
int p = 2*dy - dx;
|
||||
|
||||
|
||||
while (x < x2) {
|
||||
if (p >= 0) {
|
||||
setPixel(x, y, color);
|
||||
@ -220,7 +219,7 @@ void Window::lineWithAngle(uint8_t x, uint8_t y, uint8_t angle, uint8_t startdis
|
||||
line(x1, y1, x2, y2, color);
|
||||
}
|
||||
|
||||
void Window::setSubPixel(accum88 x, accum88 y, CRGB* color, SubpixelRenderingMode mode) {
|
||||
void Window::setSubPixel(accum88 x, accum88 y, CRGB* color) {
|
||||
uint8_t px, py;
|
||||
// px = Part of next pixel to fill
|
||||
// x = "Origin pixel"
|
||||
@ -228,39 +227,31 @@ void Window::setSubPixel(accum88 x, accum88 y, CRGB* color, SubpixelRenderingMod
|
||||
py = y & 0xFF;
|
||||
x = x >> 8;
|
||||
y = y >> 8;
|
||||
|
||||
|
||||
CRGB c;
|
||||
c = CRGB(scale8( scale8( color->r, 255-py), 255-px),
|
||||
scale8( scale8( color->g, 255-py), 255-px),
|
||||
scale8( scale8( color->b, 255-py), 255-px));
|
||||
_subpixel_render(x, y, &c, mode);
|
||||
|
||||
this->addPixelColor(x, y, &c);
|
||||
|
||||
if (px) {
|
||||
c = CRGB(scale8( scale8( color->r, 255-py), px),
|
||||
scale8( scale8( color->g, 255-py), px),
|
||||
scale8( scale8( color->b, 255-py), px));
|
||||
_subpixel_render(x+1, y, &c, mode);
|
||||
this->addPixelColor(x+1, y, &c);
|
||||
}
|
||||
|
||||
|
||||
if (py) {
|
||||
c = CRGB(scale8( scale8( color->r, py), 255-px),
|
||||
c = CRGB(scale8( scale8( color->r, py), 255-px),
|
||||
scale8( scale8( color->g, py), 255-px),
|
||||
scale8( scale8( color->b, py), 255-px));
|
||||
_subpixel_render(x, y+1, &c, mode);
|
||||
this->addPixelColor(x, y+1, &c);
|
||||
}
|
||||
|
||||
|
||||
if (px || py) {
|
||||
c = CRGB(scale8( scale8( color->r, py), px),
|
||||
c = CRGB(scale8( scale8( color->r, py), px),
|
||||
scale8( scale8( color->g, py), px),
|
||||
scale8( scale8( color->b, py), px));
|
||||
_subpixel_render(x+1, y+1, &c, mode);
|
||||
}
|
||||
}
|
||||
|
||||
void Window::_subpixel_render(uint8_t x, uint8_t y, CRGB* color, SubpixelRenderingMode mode) {
|
||||
switch(mode) {
|
||||
case SUBPIXEL_RENDERING_ADD: addPixelColor(x, y, color); break;
|
||||
case SUBPIXEL_RENDERING_RAISE: raisePixel(x, y, color); break;
|
||||
case SUBPIXEL_RENDERING_SET: setPixel(x, y, color); break;
|
||||
this->addPixelColor(x+1, y+1, &c);
|
||||
}
|
||||
}
|
||||
|
@ -8,49 +8,50 @@ void BigClockEffect::loop() {
|
||||
uint8_t h = ntpClient.getHours();
|
||||
window->drawChar(&font_numbers3x5_blocky, 6<<8, 2<<8, '0' + (h / 10), &_color_font);
|
||||
window->drawChar(&font_numbers3x5_blocky, 11<<8, 2<<8, '0' + (h % 10), &_color_font);
|
||||
|
||||
|
||||
uint8_t m = ntpClient.getMinutes();
|
||||
window->drawChar(&font_numbers3x5_blocky, 6<<8, 9<<8, '0' + (m / 10), &_color_font);
|
||||
window->drawChar(&font_numbers3x5_blocky, 11<<8, 9<<8, '0' + (m % 10), &_color_font);
|
||||
|
||||
|
||||
uint8_t s = ntpClient.getSeconds();
|
||||
if (s & 1) {
|
||||
window->setPixel(3, 10, &_color_font);
|
||||
window->setPixel(3, 12, &_color_font);
|
||||
}
|
||||
|
||||
|
||||
_draw_seconds();
|
||||
}
|
||||
|
||||
void BigClockEffect::_draw_seconds() {
|
||||
uint8_t seconds = ntpClient.getSeconds();
|
||||
for (int i=1; i<=seconds; i++) {
|
||||
_draw_border_pixel(i, &_color_seconds);
|
||||
_draw_border_pixel(i, 0, &_color_seconds);
|
||||
}
|
||||
uint16_t millis = ntpClient.getEpochMillis() % 1000;
|
||||
if (millis > 0) {
|
||||
uint8_t part = 60 - ((60 - seconds) * millis / 1000);
|
||||
_draw_border_pixel(part, &_color_seconds);
|
||||
uint16_t position = ((60 - (60 - seconds) * millis) << 8) / 1000;
|
||||
//uint8_t position = 60 - ((60 - seconds) * millis / 1000);
|
||||
_draw_border_pixel(position>>8, position&0xFF, &_color_seconds);
|
||||
}
|
||||
}
|
||||
|
||||
void BigClockEffect::_draw_border_pixel(uint8_t i, CRGB* color) {
|
||||
uint8_t x, y;
|
||||
void BigClockEffect::_draw_border_pixel(uint8_t i, uint8_t part, CRGB* color) {
|
||||
accum88 x, y;
|
||||
if (i<=8) {
|
||||
x = 7 + i;
|
||||
x = (7 + i)<<8 | part;
|
||||
y = 0;
|
||||
} else if (i<=23) {
|
||||
x = 15;
|
||||
y = i - 8;
|
||||
x = 15 << 8;
|
||||
y = (i - 8) << 8 | (255 - part);
|
||||
} else if (i<= 38) {
|
||||
x = 15 - i + 23;
|
||||
y = 15;
|
||||
x = (15 - i + 23) << 8 | (255 - part);
|
||||
y = 15 << 8;
|
||||
} else if (i <= 53) {
|
||||
x = 0;
|
||||
y = 15 - i + 38;
|
||||
y = (15 - i + 38) << 8 | part;
|
||||
} else {
|
||||
x = i - 53;
|
||||
x = (i - 53) << 8 | part;
|
||||
y = 0;
|
||||
}
|
||||
window->setPixel(x, y, color);
|
||||
window->setSubPixel(x, y, color);
|
||||
}
|
||||
|
@ -5,18 +5,18 @@ boolean Blur2DEffect::can_be_shown_with_clock() {
|
||||
}
|
||||
|
||||
void Blur2DEffect::loop() {
|
||||
uint8_t blur_amount = dim8_raw(beatsin8(3, 128, 224));
|
||||
uint8_t blur_amount = dim8_raw(beatsin8(3, 64, 192));
|
||||
window->blur(blur_amount);
|
||||
|
||||
uint8_t x1 = beatsin8(7, 0, window->width-1);
|
||||
uint8_t y1 = beatsin8(11, 0, window->height-1);
|
||||
|
||||
uint8_t x2 = beatsin8(13, 0, window->width-1);
|
||||
uint8_t y2 = beatsin8(8, 0, window->height-1);
|
||||
|
||||
uint8_t x3 = beatsin8(11, 0, window->width-1);
|
||||
uint8_t y3 = beatsin8(13, 0, window->height-1);
|
||||
|
||||
|
||||
uint8_t x1 = beatsin8(5, 0, window->width-1);
|
||||
uint8_t y1 = beatsin8(8, 0, window->height-1);
|
||||
|
||||
uint8_t x2 = beatsin8(8, 0, window->width-1);
|
||||
uint8_t y2 = beatsin8(3, 0, window->height-1);
|
||||
|
||||
uint8_t x3 = beatsin8(4, 0, window->width-1);
|
||||
uint8_t y3 = beatsin8(7, 0, window->height-1);
|
||||
|
||||
uint16_t ms = millis();
|
||||
CRGB c1 = CHSV(ms / 29, 200, 255);
|
||||
CRGB c2 = CHSV(ms / 41, 200, 255);
|
||||
|
@ -13,7 +13,7 @@ void NightClockEffect::loop() {
|
||||
//uint8_t y = minutes % ((window->height - 5) * 2 - 2);
|
||||
//if (y > window->height - 5) y = 2*window->height - 2*y;
|
||||
uint8_t y = minutes % 10;
|
||||
ClockEffect::loop(false, CRGB(0x200000), CRGB(0x000000), y);
|
||||
ClockEffect::loop(false, CRGB(0x880000), CRGB(0x000000), y);
|
||||
}
|
||||
|
||||
void ClockEffect::loop() {
|
||||
@ -34,7 +34,7 @@ void ClockEffect::loop(boolean invert, CRGB fg_color, CRGB bg_color, uint8_t yPo
|
||||
// Manually clear the needed parts
|
||||
for(int y=0; y<6; y++) {
|
||||
window->setPixel(3, yPos+y, &bg_color);
|
||||
if (y!=1 && y!=3) {
|
||||
if (y!=2 && y!=4) {
|
||||
window->setPixel(7, yPos+y, &bg_color);
|
||||
}
|
||||
window->setPixel(8, yPos+y, &bg_color);
|
||||
|
@ -7,7 +7,7 @@ FireworkEffectDot::FireworkEffectDot(Window* w, FireworkEffect* e) {
|
||||
show = 0;
|
||||
type = FIREWORK_DOT_NONE;
|
||||
_x = 0;
|
||||
_y = _window->height - 1;
|
||||
_y = 0;
|
||||
_xv = 0;
|
||||
_yv = 0;
|
||||
_r = 0;
|
||||
@ -35,7 +35,7 @@ void FireworkEffectDot::draw() {
|
||||
_screenscale(_y, _window->height, iy, ye);
|
||||
xc = 255 - xe;
|
||||
yc = 255 - ye;
|
||||
|
||||
|
||||
CRGB c00 = CRGB(dim8_video( scale8( scale8( _color.r, yc), xc)),
|
||||
dim8_video( scale8( scale8( _color.g, yc), xc)),
|
||||
dim8_video( scale8( scale8( _color.b, yc), xc)));
|
||||
@ -59,8 +59,8 @@ void FireworkEffectDot::move() {
|
||||
_yv -= EFFECT_FIREWORK_GRAVITY;
|
||||
_xv = _scale15by8_local(_xv, EFFECT_FIREWORK_DRAG);
|
||||
_yv = _scale15by8_local(_yv, EFFECT_FIREWORK_DRAG);
|
||||
|
||||
if (type == FIREWORK_DOT_SPARK) {
|
||||
|
||||
if (type == FIREWORK_DOT_SPARK) {
|
||||
_xv = _scale15by8_local(_xv, EFFECT_FIREWORK_DRAG);
|
||||
_yv = _scale15by8_local(_yv, EFFECT_FIREWORK_DRAG);
|
||||
_color.nscale8(255);
|
||||
@ -68,9 +68,9 @@ void FireworkEffectDot::move() {
|
||||
show = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Bounce if we hit the ground
|
||||
if (_xv < 0 && _y - _window->height < (-_yv)) {
|
||||
if (_xv < 0 && _y < (-_yv)) {
|
||||
if (type == FIREWORK_DOT_SPARK) {
|
||||
show = 0;
|
||||
} else {
|
||||
@ -81,10 +81,10 @@ void FireworkEffectDot::move() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (_yv < 300) {
|
||||
if (type == FIREWORK_DOT_SHELL) {
|
||||
if (_y < (uint16_t)0x8000) {
|
||||
if (_y > (uint16_t)0x8000) {
|
||||
// boom
|
||||
CRGB white(0xFFFFFF);
|
||||
_window->clear(&white);
|
||||
@ -93,7 +93,7 @@ void FireworkEffectDot::move() {
|
||||
_main->skyburst(_x, _y, _xv, _yv, _color);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (type == FIREWORK_DOT_SPARK) {
|
||||
if ((_xv > 0 && _x>_xv) || (_xv < 0 && _x<(0xFFFF+_xv))) {
|
||||
_x += _xv;
|
||||
@ -103,7 +103,7 @@ void FireworkEffectDot::move() {
|
||||
} else {
|
||||
_x += _xv;
|
||||
}
|
||||
_y -= _yv;
|
||||
_y += _yv;
|
||||
}
|
||||
|
||||
void FireworkEffectDot::ground_launch() {
|
||||
@ -157,7 +157,7 @@ void FireworkEffect::loop() {
|
||||
launch_countdown--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (_skyburst) {
|
||||
int nsparks = random8(EFFECT_FIREWORK_SPARKS / 2, EFFECT_FIREWORK_SPARKS + 1);
|
||||
for (int i=0; i<nsparks; i++) {
|
||||
|
Loading…
Reference in New Issue
Block a user