#include "effect_snake.h" #include "functions.h" void SnakeEffect::loop() { if (run++ % EFFECT_SNAKE_SLOWDOWN == 0) { // Change the coordinates only on every n-th run. uint8_t r = random8(EFFECT_SNAKE_DIRECTION_CHANGE); if (r==0 && valid_position(update_position(this->coords, direction+1))) { direction++; } else if (r==1 && valid_position(update_position(this->coords, direction-1))) { direction--; } else if (!valid_position(update_position(this->coords, direction))) { if (valid_position(update_position(this->coords, direction+1))) { direction++; } else if (valid_position(update_position(this->coords, direction-1))) { direction--; } } this->coords = update_position(this->coords, direction); } fadeToBlackBy(leds, LED_COUNT, 2); setPixel(window, this->coords.x, this->coords.y, CHSV(hue, 200, 255)); hue++; } Coords SnakeEffect::update_position(Coords original, uint8_t direction) { direction = direction % 4; if (direction == 0) original.y--; else if (direction == 1) original.x++; else if (direction == 2) original.y++; else if (direction == 3) original.x--; return original; } boolean SnakeEffect::valid_position(Coords c) { return c.x