Rotate function

This is so stupid, but we felt pretty clever making it. Pls no haet
This commit is contained in:
Daniel Løvbrøtte Olsen 2017-05-08 11:27:54 +02:00 committed by GitHub
parent 4424d237fb
commit 7bc6cdea78

View File

@ -3,6 +3,7 @@
#include "Arduino.h"
#include <FastLED.h>
#include <math.h>
struct LEDSelect {
byte side;
@ -55,6 +56,8 @@ void getNeighborLED(LEDSelect* origin, byte origin_dir, LEDSelect* Result);
void getRotNeighborLED(LEDSelect* origin, byte rot, LEDSelect* Result);
//
void translate(LEDSelect src, LEDSelect dst, CRGB* leds);
// Rotates a side, in given direction, 0 - Clockwise, 1 - Anticlockwise
void rotate(byte side, bool dir, byte n, CRGB* leds);
void initMap(void)
{
@ -352,6 +355,21 @@ void translate(LEDSelect src, LEDSelect dst, CRGB* leds){
leds[decodeLED(dst)] = leds[decodeLED(src)];
}
void rotate(byte side, bool direction, byte n, CRGB* leds)
{
byte cyclus[8]; = {0, 3, 6, 7, 8, 5, 2, 1};
for (byte i = 0; i < n; i++)
{
CRGB Saved = leds[cyclus[7 * direction]];
for(byte j = 8; j > 0; j--) {
leds[cyclus[j - (8 * !direction)]] =
leds[cyclus[j - (8 * !direction) + (1 * -direction)]];
}
leds[cyclus[7 - (4 * direction)]] = Saved;
}
}
bool setColor(LEDSelect selection, CRGB color, CRGB* leds)
{
if (selection.side == 255) {