Skip to content

Commit

Permalink
add 'dunes' effect
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleRus committed May 26, 2022
1 parent f107622 commit 0973480
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
1 change: 1 addition & 0 deletions main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ idf_component_register(
effects/spaceships.c
effects/fireflies.c
effects/tunnel.c
effects/dunes.c

EMBED_TXTFILES
${EMBED}/web/jquery.js
Expand Down
2 changes: 2 additions & 0 deletions main/effect.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "effects/spaceships.h"
#include "effects/fireflies.h"
#include "effects/tunnel.h"
#include "effects/dunes.h"

const effect_descriptor_t effects[] = {
DESCR_EFFECT_LAMP,
Expand Down Expand Up @@ -67,6 +68,7 @@ const effect_descriptor_t effects[] = {
DESCR_EFFECT_SPACESHIPS,
DESCR_EFFECT_FIREFLIES,
DESCR_EFFECT_TUNNEL,
DESCR_EFFECT_DUNES,
};

const size_t effects_count = sizeof(effects) / sizeof(effect_descriptor_t);
Expand Down
51 changes: 51 additions & 0 deletions main/effects/dunes.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Colored dunes (AA lines)
*
* Author: costyn (https://wokwi.com/projects/284541784463245837)
*/
#include "effects/dunes.h"

#include <lib8tion.h>
#include "palettes.h"

#define P_SPEED 0
#define P_PALETTE 1

EFFECT_PARAMS(dunes, 2) = {
DECL_PARAM(P_SPEED, "Speed", 1, 40, 5),
DECL_PARAM(P_PALETTE, "Palette", 0, PALETTE_MAX - 1, PALETTE_WOOD_FIRE),
};

esp_err_t effect_dunes_run(framebuffer_t *fb)
{
CHECK(fb_begin(fb));

uint32_t ms = esp_timer_get_time() / 1000 * PARAM_VAL(dunes, P_SPEED) / 10;

uint32_t y_hue_delta = (int32_t)sin16(ms * 11) / 128;
uint32_t x_hue_delta = (int32_t)cos16(ms * 11) / 128;
uint32_t start_hue = ms << 8;
uint32_t line_start_hue = start_hue - (fb->height + 1) / 2 * y_hue_delta;
int16_t yd2 = sin16(ms * 3) / 32;
int16_t xd2 = sin16(ms * 7) / 32;
for (size_t y = 0; y < fb->height; y++)
{
uint32_t pixel_hue = line_start_hue - (fb->width + 1) / 2 * x_hue_delta;
uint32_t xhd = x_hue_delta;
line_start_hue += y_hue_delta;
y_hue_delta += yd2;
for (size_t x = 0; x < fb->width; x++)
{
//rgb_t c = color_from_palette_rgb(palette, palette_size, pixel_hue >> 8, 255, true);
rgb_t c = color_from_palette_rgb(
palettes[PARAM_VAL(dunes, P_PALETTE)].palette,
palettes[PARAM_VAL(dunes, P_PALETTE)].size,
pixel_hue >> 8, 255, true);
fb_set_pixel_rgb(fb, x, y, c);
pixel_hue += xhd;
xhd += xd2;
}
}

return fb_end(fb);
}
17 changes: 17 additions & 0 deletions main/effects/dunes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Colored dunes (AA lines)
*
* Author: costyn (https://wokwi.com/projects/284541784463245837)
*/
#ifndef __EFFECTS_DUNES_H__
#define __EFFECTS_DUNES_H__

#include "effect.h"

extern EFFECT_PARAMS(dunes, 2);

esp_err_t effect_dunes_run(framebuffer_t *fb);

#define DESCR_EFFECT_DUNES DECL_EFFECT_SHORT(dunes, "Colored dunes")

#endif /* __EFFECTS_DUNES_H__ */

0 comments on commit 0973480

Please sign in to comment.