Skip to content

Instantly share code, notes, and snippets.

@jpro56
Created November 18, 2018 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpro56/55c00724a724ae5ea6ca6d2e6f437b53 to your computer and use it in GitHub Desktop.
Save jpro56/55c00724a724ae5ea6ca6d2e6f437b53 to your computer and use it in GitHub Desktop.
My latest cube sketch
#define USE_OCTOWS2811
#include<OctoWS2811.h>
#include <FastLED.h>
#include <Math.h>
#define CUBE_SIZE 8
#define NUM_LEDS 513 // One extra LED added to take care of invalid LED addresses !!
#define LEDS_PER_PIN 64 // Only used within setup to define the physical aspect of the led array
CRGB leds[NUM_LEDS];
uint8_t orientation = 0; // Used to reassign the x,y,z such that animation orientation can be changed
uint16_t start_brightness = 0;
uint16_t target_brightness = 255;
unsigned long start; // For a millis timer to cycle through the animations
unsigned int finish = 60000; // Number of milliseconds duration for all animations 60,000 = 1 minute
// Global variables and constants specific to the bloc animation
#define max_number_of_blocs 7
uint8_t available_positions[8] = {7, 7, 7, 7, 7, 7, 7, 7}; // Contains the number of the bloc that currently occupies it, 7 and up implies an empty position
typedef struct {
uint8_t current_position = 0;
uint8_t previous_position = 0;
uint8_t color = 0;
}
blocs;
blocs bloc[max_number_of_blocs];
// End of global variables and constants specific to the bloc animation
// Global variables and constants specific to the noise animation
typedef enum {X_LAYER, Y_LAYER, Z_LAYER} LAYER;
typedef enum {UP, DOWN} DIRECTION;
DIRECTION fillDirection = UP; // Dictates the direction of the frames
LAYER layer = Y_LAYER; // Which axis are we filling the frames
int nFillFrame; // Which frame number gets the new noise data
static uint16_t x; // The 16 bit version of our coordinates
static uint16_t y;
static uint16_t z;
uint16_t speed = 1; // speed is set dynamically once we've started up
uint16_t scale = 30; // scale is set dynamically once we've started up
uint8_t noise[CUBE_SIZE][CUBE_SIZE]; // This is the array that we keep our computed noise values in
CRGBPalette16 currentPalette( LavaColors_p );
uint8_t colorLoop = 1;
// End of global variables and constants specific to the noise animation
// Global variables and constants specific to the Carbon_Atom, dough_hook and propellers animations
#define PIXRES 256 // Constant for 'Fractions of a pixel' determines the precision of the animations
#define MAX_POS 1792 // Maximum position or address of a pixel = 7 * PIXRES
#define CENTER 896 // Center position = MAX_POS/2
#define E_RADIUS 832 // Electrons radius = 3.25 * PIXRES. Maximum orbit, that does not extend beyound cube.
#define H_RADIUS 896 // Dough hook radius = PIXRES. Maximum orbit, that does not conflict with electrons.
#define OFFSET_MIN 200 // Determines the range of change to the particle rotation plane
#define OFFSET_MAX 300
#define SPEED_MIN 200 // Determines the range of change to the particle speed
#define SPEED_MAX 300
#define FADE 250 // Sets the global dimming ratio (FADE/256) for all LEDs. Effectively creates a trail behind moving particle
#define NUM_ELECTRONS 6 // Number of electrons
#define NUM_HOOKS 48 // Number of particles used in Hook animation
#define NUM_PROP 9 // Number of CW and CCW propeller type particles; Center + 4 blades of 2 pixel each
#define NUM_PART 200 // Number of particles that make up the earth and/or the balloon animations
CRGB nucleous[2] = {CRGB::Black, CRGB::White};
const CRGB NucleousColor(2, 2, 2);
// End of global variables and constants specific to the Carbon_Atom AND dough_hook animations
void LED(uint8_t z, uint8_t y, uint8_t x, uint8_t red, uint8_t green, uint8_t blue) { //*****Original LED routine from Kevin Darrah*****Original LED routine from Kevin Darrah*****
uint16_t i = 512;
if (x >= 0 && x <= 7 && y >= 0 && y <= 7 && z >= 0 && z <= 7) { // Only if x,y,z are valid otherwise 'i' remains set to 512 (outside of cube)
if (z & 1) i = 8 * ((x * 8) + z) + 7 - y; // Check for odd numbered vertical layers
else i = 8 * ((x * 8) + z) + y; // to take care of cube's zig-zag wiring
}
leds[i] = CRGB(red * 16, green * 16, blue * 16); // Multiply by 16 as Kevin's code has brightness = 0-15 !
}//****end of LED Routine****end of LED Routine****end of LED Routine****end of LED Routine****end of LED Routine****end of LED Routine
uint16_t XYZ ( uint8_t x, uint8_t y, uint8_t z) { //****XYZ Routine****XYZ Routine****XYZ Routine****XYZ Routine*****XYZ Routine****XYZ Routine****XYZ Routine****
uint16_t i = 512;
uint8_t xx = 0; // Internal references to simplify copying process ( no temp variable required )
uint8_t yy = 0;
uint8_t zz = 0;
if (orientation > 23) orientation = 0;
if (x >= 0 && x <= 7 && y >= 0 && y <= 7 && z >= 0 && z <= 7) { // Only if x,y,z are valid otherwise 'i' remains set to 512 (outside of cube)
switch (orientation) { // Based on all possible orientations of a single dice (while 1 on top, dice can be rotated 4 times with either 2,3,4,5 facing us)
case 0: xx = 7 - x; yy = 7 - y; zz = z; break; // Axis = Down --> Up
case 1: xx = 7 - y; yy = x; zz = z; break;
case 2: xx = x; yy = y; zz = z; break;
case 3: xx = y; yy = 7 - x; zz = z; break;
case 4: xx = 7 - y; yy = 7 - x; zz = 7 - z; break; // Axis = Up --> Down
case 5: xx = 7 - x; yy = y; zz = 7 - z; break;
case 6: xx = y; yy = x; zz = 7 - z; break;
case 7: xx = x; yy = 7 - y; zz = 7 - z; break;
case 8: xx = z; yy = x; zz = y; break; // Axis = Right --> Left
case 9: xx = z; yy = 7 - x; zz = 7 - y; break;
case 10: xx = z; yy = y; zz = 7 - x; break;
case 11: xx = z; yy = 7 - y; zz = x; break;
case 12: xx = 7 - z; yy = 7 - y; zz = 7 - x; break; // Axis = Left --> Right
case 13: xx = 7 - z; yy = x; zz = 7 - y; break;
case 14: xx = 7 - z; yy = 7 - x; zz = y; break;
case 15: xx = 7 - z; yy = y; zz = x; break;
case 16: xx = y; yy = z; zz = x; break; // Axis = Back --> Front
case 17: xx = x; yy = z; zz = 7 - y; break;
case 18: xx = 7 - y; yy = z; zz = 7 - x; break;
case 19: xx = 7 - x; yy = z; zz = y; break;
case 20: xx = x; yy = 7 - z; zz = y; break; // Axis = Front --> Back
case 21: xx = 7 - x; yy = 7 - z; zz = 7 - y; break;
case 22: xx = y; yy = 7 - z; zz = 7 - x; break;
case 23: xx = 7 - y; yy = 7 - z; zz = x; break;
default: xx = x; yy = y; zz = 7 - z; break; // Axis = Down --> Up for out of range values !!
}
if (zz & 1) i = 8 * ((xx * 8) + zz) + 7 - yy; // Check for odd numbered vertical layers
else i = 8 * ((xx * 8) + zz) + yy; // to take care of cube's zig-zag wiring
}
return i;
}//****end of XYZ Routine****end of XYZ Routine****end of XYZ Routine****end of XYZ Routine****end of XYZ Routine****end of XYZ Routine
void Slowly_fade_off() {
for (uint8_t fader = 0; fader < 30; fader++) {
fadeToBlackBy( leds, NUM_LEDS, 50);
FastLED.show();
delay(50);
}
}
void Set_all_to_black() {
fill_solid(leds, NUM_LEDS, CRGB(0, 0, 0) ); // All pixels set to black (OFF)
FastLED.show();
}
void bugs() { //*****bugs*****bugs*****bugs*****bugs*****bugs*****bugs*****bugs*****bugs
start_brightness = 0;
uint8_t num_bugs = random(4, 8);
int bug_x_pos[num_bugs], bug_y_pos[num_bugs], bug_z_pos[num_bugs];
boolean bug_x_dir[num_bugs], bug_y_dir[num_bugs], bug_z_dir[num_bugs]; // True = positive movement; false = negative movement
uint8_t bug_color[num_bugs], bug_select, bug_direction;
uint8_t base_color = random(256), hue_step = 255 / num_bugs; // spread the bugs colors evenly accross the rainbow spectrum ;
for (bug_select = 0; bug_select < num_bugs; bug_select++) {
bug_color[bug_select] = base_color + (bug_select * hue_step);
bug_x_pos[bug_select] = random(8);
bug_y_pos[bug_select] = random(8);
bug_z_pos[bug_select] = random(8);
bug_x_dir[num_bugs] = true;
bug_y_dir[num_bugs] = true;
bug_z_dir[num_bugs] = true;
}
start = millis();
while (millis() - start < finish) {
Set_all_to_black(); //turns all pixels to black
for (bug_select = 0; bug_select < num_bugs; bug_select++) {
leds[XYZ(bug_x_pos[bug_select], bug_y_pos[bug_select], bug_z_pos[bug_select])] = CHSV(bug_color[bug_select], 255, 255);
leds[XYZ(bug_x_pos[bug_select] + 1, bug_y_pos[bug_select], bug_z_pos[bug_select])] = CHSV(bug_color[bug_select], 255, 255);
leds[XYZ(bug_x_pos[bug_select] - 1, bug_y_pos[bug_select], bug_z_pos[bug_select])] = CHSV(bug_color[bug_select], 255, 255);
leds[XYZ(bug_x_pos[bug_select], bug_y_pos[bug_select] + 1, bug_z_pos[bug_select])] = CHSV(bug_color[bug_select], 255, 255);
leds[XYZ(bug_x_pos[bug_select], bug_y_pos[bug_select] - 1, bug_z_pos[bug_select])] = CHSV(bug_color[bug_select], 255, 255);
leds[XYZ(bug_x_pos[bug_select], bug_y_pos[bug_select], bug_z_pos[bug_select] + 1)] = CHSV(bug_color[bug_select], 255, 255);
leds[XYZ(bug_x_pos[bug_select], bug_y_pos[bug_select], bug_z_pos[bug_select] - 1)] = CHSV(bug_color[bug_select], 255, 255);
}
start_brightness += 5; // Will slowly bring brightness to max
if (start_brightness > 100) start_brightness = 100;
FastLED.setBrightness(start_brightness);
FastLED.show();
delay(75);
for (bug_select = 0; bug_select < num_bugs; bug_select++) {
bug_direction = random(3); // selects if the bug changes in the x,y or z direction
if (bug_direction == 0) {
if (bug_x_dir[bug_select]) {
bug_x_pos[bug_select]++;
}
else {
bug_x_pos[bug_select]--;
}
}
if (bug_direction == 1) {
if (bug_y_dir[bug_select]) {
bug_y_pos[bug_select]++;
}
else {
bug_y_pos[bug_select]--;
}
}
if (bug_direction == 2) {
if (bug_z_dir[bug_select]) {
bug_z_pos[bug_select]++;
}
else {
bug_z_pos[bug_select]--;
}
}
if (bug_x_pos[bug_select] < 0) { // If bug is moving below position 0 (Invalid position)
bug_x_pos[bug_select] = 0; // Reset x position to 0
bug_x_dir[bug_select] = true; // Set increasing movements
}
if (bug_x_pos[bug_select] > 7) { // If bug is moving above position 7 (Invalid position)
bug_x_pos[bug_select] = 7; // Reset x position to 0
bug_x_dir[bug_select] = false; // Set decreasing movements
}
if (bug_y_pos[bug_select] < 0) { // If bug is moving below position 0 (Invalid position)
bug_y_pos[bug_select] = 0; // Reset y position to 0
bug_y_dir[bug_select] = true; // Set increasing movements
}
if (bug_y_pos[bug_select] > 7) { // If bug is moving above position 7 (Invalid position)
bug_y_pos[bug_select] = 7; // Reset y position to 0
bug_y_dir[bug_select] = false; // Set decreasing movements
}
if (bug_z_pos[bug_select] < 0) { // If bug is moving below position 0 (Invalid position)
bug_z_pos[bug_select] = 0; // Reset z position to 0
bug_z_dir[bug_select] = true; // Set increasing movements
}
if (bug_z_pos[bug_select] > 7) { // If bug is moving above position 7 (Invalid position)
bug_z_pos[bug_select] = 7; // Reset z position to 0
bug_z_dir[bug_select] = false; // Set decreasing movements
}
}
}//while
Slowly_fade_off();
}//wipeout
void rain() { //****rain****rain****rain****rain****rain
uint8_t max_num_drops = 32;
boolean drop_active[max_num_drops]; // Indicates that a specific drop number drop is active (unavailable for a new drop)
boolean xy_free[8][8]; // True indicates the XY location is available for a new drop
orientation = 0; // Alternately set to random(24);
Set_all_to_black();
start_brightness = 0;
target_brightness = 255;
FastLED.setBrightness(start_brightness);
for (uint8_t d = 0; d < max_num_drops; d++) drop_active[d] = false; // Initialize all drops to be inactive
for (uint8_t x = 0; x < 8; x++) { // Initialize all XY positions to be free for a new drop
for (uint8_t y = 0; y < 8; y++) {
xy_free[x][y] = true;
}
}
uint8_t drop_from_x[max_num_drops];
uint8_t drop_from_y[max_num_drops];
uint8_t drop_color[max_num_drops];
uint16_t drop_position[max_num_drops];
uint16_t time_interval[max_num_drops];
uint8_t base_pixel_number[max_num_drops];
uint8_t frac_pixel_number[max_num_drops];
uint8_t base_pixel_brightness[max_num_drops];
uint8_t frac_pixel_brightness[max_num_drops];
uint8_t pixel_fraction[max_num_drops];
start = millis();
while (millis() - start < finish) { // Stay in this loop for 20 seconds
start_brightness++; // Will slowly bring brightness to max
if (start_brightness > target_brightness) start_brightness = target_brightness;
FastLED.setBrightness(start_brightness);
static uint8_t this_hue = random(256);
if (random(16) < 2) { // Probability to start a new drop
uint8_t temp_x = random(8); // Randomly pick a new XY location to start a new drop
uint8_t temp_y = random(8);
if (xy_free[temp_x][temp_y]) { // If no drops in the random XY
for (uint8_t this_drop = 0; this_drop < max_num_drops; this_drop++) { // Try to find an inactive drop
if (!drop_active[this_drop]) {
drop_active[this_drop] = true;
drop_from_x[this_drop] = temp_x;
drop_from_y[this_drop] = temp_y;
drop_color[this_drop] = this_hue += 7; // Alternately random(256);
drop_position[this_drop] = 16383;
time_interval[this_drop] = 0;
xy_free[temp_x][temp_y] = false;
break;
}
}
}
}
for (uint8_t next_drop = 0; next_drop < max_num_drops; next_drop++) {
if (drop_active[next_drop] == true) {
base_pixel_number[next_drop] = drop_position[next_drop] >> 11; // convert from pos to raw pixel number
frac_pixel_number[next_drop] = base_pixel_number[next_drop] - 1;
pixel_fraction[next_drop] = (drop_position[next_drop] >> 3) & 255; // extract the 'fractional' part of the position
base_pixel_brightness[next_drop] = pixel_fraction[next_drop];
frac_pixel_brightness[next_drop] = 255 - base_pixel_brightness[next_drop];
if (base_pixel_number[next_drop]) { // For any base_pixel_number that is not = 0
leds[XYZ(drop_from_x[next_drop], drop_from_y[next_drop], base_pixel_number[next_drop])] = CHSV( drop_color[next_drop], 255, base_pixel_brightness[next_drop]);
leds[XYZ(drop_from_x[next_drop], drop_from_y[next_drop], frac_pixel_number[next_drop])] = CHSV( drop_color[next_drop], 255, frac_pixel_brightness[next_drop]);
}
time_interval[next_drop]++;
drop_position[next_drop] = 16383 - (time_interval[next_drop] * time_interval[next_drop]);
if ((time_interval[next_drop] * time_interval[next_drop]) >= 16383) { // Reached the end of the position counter
drop_active[next_drop] = false;
xy_free[drop_from_x[next_drop]][drop_from_y[next_drop]] = true;
}
}
}
FastLED.show();
delay(10); // Should be (10) to approximate real gravity
fadeToBlackBy( leds, NUM_LEDS, 1);
/*
if (drop_from_x[next_drop] == 7 && drop_from_y[next_drop] == 7){
for (uint8_t test = 0; test < max_num_drops; test++) {
Serial.print("X = ");
Serial.print(drop_from_x[test]);
Serial.print(" Y = ");
Serial.print(drop_from_y[test]);
Serial.print(" Pos = ");
Serial.print(drop_position[test]);
Serial.print(" Fr = ");
Serial.print(pixel_fraction[test]);
Serial.print(" Time = ");
Serial.print(time_interval[test]);
Serial.print(" BP = ");
Serial.print(base_pixel_number[test]);
Serial.print(" FP = ");
Serial.print(frac_pixel_number[test]);
Serial.print(" BB = ");
Serial.print(base_pixel_brightness[test]);
Serial.print(" FB = ");
Serial.print(frac_pixel_brightness[test]);
Serial.print(" Drop = ");
Serial.print(test);
Serial.print(" xy_free[7][7] = ");
Serial.println(xy_free[7][7]);
}
}
*/
}//while
Slowly_fade_off();
}//rainv2
void draw_face(uint8_t face, uint8_t hue) { //****usedbyfolder****usedbyfolder****usedbyfolder****usedbyfolder****usedbyfolder****usedbyfolder****
fill_solid(leds, NUM_LEDS, CRGB(0, 0, 0) );
uint8_t xx = 0, yy = 0, zz = 0; // Counters for x,y,z
uint8_t fx = 0, fy = 0, fz = 0, tx = 0, ty = 0, tz = 0; // 'from' x,y,z and 'to' x,y,z
switch (face) {
case 1: fx = 0; tx = 7; fy = 0; ty = 7; fz = 7; tz = 7; break; // Top
case 2: fx = 0; tx = 0; fy = 0; ty = 7; fz = 0; tz = 7; break; // Right
case 3: fx = 0; tx = 7; fy = 0; ty = 0; fz = 0; tz = 7; break; // Back
case 4: fx = 0; tx = 7; fy = 7; ty = 7; fz = 0; tz = 7; break; // Front
case 5: fx = 7; tx = 7; fy = 0; ty = 7; fz = 0; tz = 7; break; // Left
case 6: fx = 0; tx = 7; fy = 0; ty = 7; fz = 0; tz = 0; break; // Bottom
}
for (xx = fx; xx <= tx; xx++) {
for (yy = fy; yy <= ty; yy++) {
for (zz = fz; zz <= tz; zz++) {
leds[XYZ(xx, yy, zz)] = CHSV( hue, 255, 255);
}
}
}
} // End of draw_face function
void fold_face(uint8_t from, uint8_t to, uint8_t hue) { //****usedbyfolder****usedbyfolder****usedbyfolder****usedbyfolder****usedbyfolder****usedbyfolder****
uint8_t fx, fy, fz, tx, ty, tz; // 'from' x,y,z and 'to' x,y,z
uint16_t newXYZ[8][8][8]; // Array to store the physical addresses of the re-positionned cube
switch (from) {
case 6: // Bottom
if (to == 2) { // From bottom to Right
for (fx = 0; fx < 8; fx++) {
for (fy = 0; fy < 8; fy++) {
for (fz = 0; fz < 8; fz++) {
tx = 7 - fy; ty = fx; tz = fz; newXYZ[tx][ty][tz] = XYZ(fx, fy, fz);
}
}
}
}
if (to == 4) { // From bottom to Front
for (fx = 0; fx < 8; fx++) {
for (fy = 0; fy < 8; fy++) {
for (fz = 0; fz < 8; fz++) {
tx = 7 - fx; ty = 7 - fy; tz = fz; newXYZ[tx][ty][tz] = XYZ(fx, fy, fz);
}
}
}
}
if (to == 5) { // From bottom to Left
for (fx = 0; fx < 8; fx++) {
for (fy = 0; fy < 8; fy++) {
for (fz = 0; fz < 8; fz++) {
tx = fy; ty = 7 - fx; tz = fz; newXYZ[tx][ty][tz] = XYZ(fx, fy, fz);;
}
}
}
}
if (to == 3) { // From bottom to Back
for (fx = 0; fx < 8; fx++) {
for (fy = 0; fy < 8; fy++) {
for (fz = 0; fz < 8; fz++) {
tx = fx; ty = fy; tz = fz; newXYZ[tx][ty][tz] = XYZ(fx, fy, fz);
}
}
}
}
break; // End of From Bottom
case 2: // Right
if (to == 1) { // From Right to Top
for (fx = 0; fx < 8; fx++) {
for (fy = 0; fy < 8; fy++) {
for (fz = 0; fz < 8; fz++) {
tx = 7 - fy; ty = 7 - fz; tz = fx; newXYZ[tx][ty][tz] = XYZ(fx, fy, fz);
}
}
}
}
if (to == 3) { // From Right to Back
for (fx = 0; fx < 8; fx++) {
for (fy = 0; fy < 8; fy++) {
for (fz = 0; fz < 8; fz++) {
tx = 7 - fz; ty = fy; tz = fx; newXYZ[tx][ty][tz] = XYZ(fx, fy, fz);
}
}
}
}
if (to == 4) { // From Right to Front
for (fx = 0; fx < 8; fx++) {
for (fy = 0; fy < 8; fy++) {
for (fz = 0; fz < 8; fz++) {
tx = fz; ty = 7 - fy; tz = fx; newXYZ[tx][ty][tz] = XYZ(fx, fy, fz);
}
}
}
}
if (to == 6) { // From Right to Bottom
for (fx = 0; fx < 8; fx++) {
for (fy = 0; fy < 8; fy++) {
for (fz = 0; fz < 8; fz++) {
tx = fy; ty = fz; tz = fx; newXYZ[tx][ty][tz] = XYZ(fx, fy, fz);
}
}
}
}
break; // End of From Right
case 4: // Front
if (to == 1) { // From Front to Top
for (fx = 0; fx < 8; fx++) {
for (fy = 0; fy < 8; fy++) {
for (fz = 0; fz < 8; fz++) {
tx = 7 - fx; ty = 7 - fz; tz = 7 - fy; newXYZ[tx][ty][tz] = XYZ(fx, fy, fz);
}
}
}
}
if (to == 2) { // From Front to Right
for (fx = 0; fx < 8; fx++) {
for (fy = 0; fy < 8; fy++) {
for (fz = 0; fz < 8; fz++) {
tx = 7 - fz; ty = fx; tz = 7 - fy; newXYZ[tx][ty][tz] = XYZ(fx, fy, fz);
}
}
}
}
if (to == 5) { // From Front to Left
for (fx = 0; fx < 8; fx++) {
for (fy = 0; fy < 8; fy++) {
for (fz = 0; fz < 8; fz++) {
tx = fz; ty = 7 - fx; tz = 7 - fy; newXYZ[tx][ty][tz] = XYZ(fx, fy, fz);
}
}
}
}
if (to == 6) { // From Front to Bottom
for (fx = 0; fx < 8; fx++) {
for (fy = 0; fy < 8; fy++) {
for (fz = 0; fz < 8; fz++) {
tx = fx; ty = fz; tz = 7 - fy; newXYZ[tx][ty][tz] = XYZ(fx, fy, fz);
}
}
}
}
break; // End of From Front
case 1: // Top
if (to == 2) { // From Top to Right
for (fx = 0; fx < 8; fx++) {
for (fy = 0; fy < 8; fy++) {
for (fz = 0; fz < 8; fz++) {
tx = fy; ty = fx; tz = 7 - fz; newXYZ[tx][ty][tz] = XYZ(fx, fy, fz);
}
}
}
}
if (to == 3) { // From Top to Back
for (fx = 0; fx < 8; fx++) {
for (fy = 0; fy < 8; fy++) {
for (fz = 0; fz < 8; fz++) {
tx = 7 - fx; ty = fy; tz = 7 - fz; newXYZ[tx][ty][tz] = XYZ(fx, fy, fz);
}
}
}
}
if (to == 4) { // From Top to Front
for (fx = 0; fx < 8; fx++) {
for (fy = 0; fy < 8; fy++) {
for (fz = 0; fz < 8; fz++) {
tx = fx; ty = 7 - fy; tz = 7 - fz; newXYZ[tx][ty][tz] = XYZ(fx, fy, fz);
}
}
}
}
if (to == 5) { // From Top to Left
for (fx = 0; fx < 8; fx++) {
for (fy = 0; fy < 8; fy++) {
for (fz = 0; fz < 8; fz++) {
tx = 7 - fy; ty = 7 - fx; tz = 7 - fz; newXYZ[tx][ty][tz] = XYZ(fx, fy, fz);
}
}
}
}
break; // End of From Top
case 5: // Left
if (to == 1) { // From Left to Top
for (fx = 0; fx < 8; fx++) {
for (fy = 0; fy < 8; fy++) {
for (fz = 0; fz < 8; fz++) {
tx = fy; ty = 7 - fz; tz = 7 - fx; newXYZ[tx][ty][tz] = XYZ(fx, fy, fz);
}
}
}
}
if (to == 3) { // From Left to Back
for (fx = 0; fx < 8; fx++) {
for (fy = 0; fy < 8; fy++) {
for (fz = 0; fz < 8; fz++) {
tx = fz; ty = fy; tz = 7 - fx; newXYZ[tx][ty][tz] = XYZ(fx, fy, fz);
}
}
}
}
if (to == 4) { // From Left to Front
for (fx = 0; fx < 8; fx++) {
for (fy = 0; fy < 8; fy++) {
for (fz = 0; fz < 8; fz++) {
tx = 7 - fz; ty = 7 - fy; tz = 7 - fx; newXYZ[tx][ty][tz] = XYZ(fx, fy, fz);
}
}
}
}
if (to == 6) { // From Left to Bottom
for (fx = 0; fx < 8; fx++) {
for (fy = 0; fy < 8; fy++) {
for (fz = 0; fz < 8; fz++) {
tx = 7 - fy; ty = fz; tz = 7 - fx; newXYZ[tx][ty][tz] = XYZ(fx, fy, fz);
}
}
}
}
break; // End of From Left
case 3: // Back
if (to == 1) { // From Back to Top
for (fx = 0; fx < 8; fx++) {
for (fy = 0; fy < 8; fy++) {
for (fz = 0; fz < 8; fz++) {
tx = fx; ty = 7 - fz; tz = fy; newXYZ[tx][ty][tz] = XYZ(fx, fy, fz);
}
}
}
}
if (to == 2) { // From Back to Right
for (fx = 0; fx < 8; fx++) {
for (fy = 0; fy < 8; fy++) {
for (fz = 0; fz < 8; fz++) {
tx = fz; ty = fx; tz = fy; newXYZ[tx][ty][tz] = XYZ(fx, fy, fz);
}
}
}
}
if (to == 5) { // From Back to Left
for (fx = 0; fx < 8; fx++) {
for (fy = 0; fy < 8; fy++) {
for (fz = 0; fz < 8; fz++) {
tx = 7 - fz; ty = 7 - fx; tz = fy; newXYZ[tx][ty][tz] = XYZ(fx, fy, fz);
}
}
}
}
if (to == 6) { // From Back to Bottom
for (fx = 0; fx < 8; fx++) {
for (fy = 0; fy < 8; fy++) {
for (fz = 0; fz < 8; fz++) {
tx = 7 - fx; ty = fz; tz = fy; newXYZ[tx][ty][tz] = XYZ(fx, fy, fz);
}
}
}
}
break; // End of From Back
} // End of the Case !!!!
for (uint8_t seq = 0; seq < 7; seq++) {
for (uint8_t line = 0; line <= seq; line++) {
ty = 7 - seq + line;
tz = line;
for (tx = 0; tx < 8; tx++) leds[newXYZ[tx][ty][tz]] = CHSV( hue, 255, 0);
tz = line + 1;
for (tx = 0; tx < 8; tx++) leds[newXYZ[tx][ty][tz]] = CHSV( hue, 255, 255);
}
FastLED.show();
delay(100);
}
for (uint8_t seq = 7; seq > 0; seq--) {
for (uint8_t line = 0; line <= seq - 1; line++) {
ty = seq - line;
tz = 7 - line;
for (tx = 0; tx < 8; tx++) leds[newXYZ[tx][ty][tz]] = CHSV( hue, 255, 0);
ty = seq - line - 1;
for (tx = 0; tx < 8; tx++) leds[newXYZ[tx][ty][tz]] = CHSV( hue, 255, 255);
}
FastLED.show();
delay(100);
}
} // End of fold_face function
void folder() { //****folder****folder****folder****folder****folder****folder****folder****folder****folder
uint8_t current_face;
uint8_t target_face;
uint8_t current_hue;
start_brightness = 0;
target_brightness = 120;
// top=1, right=2, back=3, front=4, left=5, bottom=6; Using arbitrary dice numbers
current_face = random(6) + 1; // Selects a number between 1 and 6
//current_face = 4;
target_face = random(6) + 1; // Selects a number between 1 and 6
//target_face = 3; // Selects a number between 1 and 6
current_hue = random();
start = millis();
while (millis() - start < finish) {
while (target_face == current_face || (target_face + current_face) == 7) {
target_face = random(6) + 1; // Re-selects a number between 1 and 6
// Serial.print("In while loop... current_face = ");
// Serial.print(current_face);
// Serial.print(" , target_face = ");
// Serial.println(target_face);
}
//target_face = 2;
for (uint8_t temp = 0; temp < 80; temp++) {
draw_face(current_face, current_hue);
start_brightness += 10; // Will slowly bring brightness to max
if (start_brightness > target_brightness) start_brightness = target_brightness;
FastLED.setBrightness(start_brightness);
FastLED.show();
delay(25);
current_hue ++;
}
// Serial.print("After... current_face = ");
// Serial.print(current_face);
// Serial.print(" , target_face = ");
// Serial.println(target_face);
fold_face(current_face, target_face, current_hue);
current_face = target_face;
}
Slowly_fade_off();
} //*****End of Folder********End of Folder********End of Folder********End of Folder********End of Folder*****
void snake() { //****snake****snake****snake****snake****snake****snake****snake*****
start_brightness = 0;
target_brightness = 200;
uint8_t num_snakes = random(2, 5); // Select any number from 2 to 4
uint8_t snake_length = 15;
int snake_x_pos[snake_length][num_snakes], snake_y_pos[snake_length][num_snakes], snake_z_pos[snake_length][num_snakes];
boolean snake_x_dir[num_snakes], snake_y_dir[num_snakes], snake_z_dir[num_snakes]; // True = positive movement; false = negative movement
uint8_t snake_color[num_snakes], snake_select, snake_section, snake_direction;
uint8_t base_color = random(256), hue_step = 255 / num_snakes; // spread the snakes colors evenly accross the rainbow spectrum ;
for (snake_select = 0; snake_select < num_snakes; snake_select++) {
snake_color[snake_select] = base_color + (snake_select * hue_step);
snake_x_pos[0][snake_select] = random(8); // Random starting point for all snakes
snake_y_pos[0][snake_select] = random(8);
snake_z_pos[0][snake_select] = random(8);
snake_x_dir[num_snakes] = true; // Start all directions as increasing
snake_y_dir[num_snakes] = true;
snake_z_dir[num_snakes] = true;
for (snake_section = 1; snake_section < snake_length; snake_section++) {
snake_x_pos[snake_section][snake_select] = 8; // make all other snake sections void positions
snake_y_pos[snake_section][snake_select] = 8;
snake_z_pos[snake_section][snake_select] = 8;
}
}
start = millis();
while (millis() - start < finish) {
Set_all_to_black();
snake_direction = random(3); // Selects if snake moves in x,y or z direction
for (snake_select = 0; snake_select < num_snakes; snake_select++) { // draw all snakes sections
for (snake_section = 0; snake_section < snake_length; snake_section++) {
leds[XYZ(snake_x_pos[snake_section][snake_select], snake_y_pos[snake_section][snake_select], snake_z_pos[snake_section][snake_select])] = CHSV(snake_color[snake_select], 255, 255);
}
// Select a slightly different color just for the snake's head
leds[XYZ(snake_x_pos[0][snake_select], snake_y_pos[0][snake_select], snake_z_pos[0][snake_select])] = CHSV(snake_color[snake_select] + 20, 255, 255);
}
start_brightness += 50; // Will slowly bring brightness to max
if (start_brightness > target_brightness) start_brightness = target_brightness;
FastLED.setBrightness(start_brightness);
FastLED.show();
delay(200);
for (snake_select = 0; snake_select < num_snakes; snake_select++) { // moves all snakes by one position
for (snake_section = snake_length - 1; snake_section > 0; snake_section--) {
snake_x_pos[snake_section][snake_select] = snake_x_pos[snake_section - 1][snake_select] ; // make all other snake sections void positions
snake_y_pos[snake_section][snake_select] = snake_y_pos[snake_section - 1][snake_select];
snake_z_pos[snake_section][snake_select] = snake_z_pos[snake_section - 1][snake_select];
}
}
for (snake_select = 0; snake_select < num_snakes; snake_select++) {
snake_direction = random(3); // selects if the snake changes in the x,y or z direction
if (snake_direction == 0) {
if (snake_x_dir[snake_select]) {
snake_x_pos[0][snake_select]++;
}
else {
snake_x_pos[0][snake_select]--;
}
}
if (snake_direction == 1) {
if (snake_y_dir[snake_select]) {
snake_y_pos[0][snake_select]++;
}
else {
snake_y_pos[0][snake_select]--;
}
}
if (snake_direction == 2) {
if (snake_z_dir[snake_select]) {
snake_z_pos[0][snake_select]++;
}
else {
snake_z_pos[0][snake_select]--;
}
}
if (snake_x_pos[0][snake_select] < 0) { // If snake is moving below position 0 (Invalid position)
snake_x_pos[0][snake_select] = 0; // Reset x position to 0
snake_x_dir[snake_select] = true; // Set increasing movements
}
if (snake_x_pos[0][snake_select] > 7) { // If snake is moving above position 7 (Invalid position)
snake_x_pos[0][snake_select] = 7; // Reset x position to 0
snake_x_dir[snake_select] = false; // Set decreasing movements
}
if (snake_y_pos[0][snake_select] < 0) { // If snake is moving below position 0 (Invalid position)
snake_y_pos[0][snake_select] = 0; // Reset y position to 0
snake_y_dir[snake_select] = true; // Set increasing movements
}
if (snake_y_pos[0][snake_select] > 7) { // If snake is moving above position 7 (Invalid position)
snake_y_pos[0][snake_select] = 7; // Reset y position to 0
snake_y_dir[snake_select] = false; // Set decreasing movements
}
if (snake_z_pos[0][snake_select] < 0) { // If snake is moving below position 0 (Invalid position)
snake_z_pos[0][snake_select] = 0; // Reset z position to 0
snake_z_dir[snake_select] = true; // Set increasing movements
}
if (snake_z_pos[0][snake_select] > 7) { // If snake is moving above position 7 (Invalid position)
snake_z_pos[0][snake_select] = 7; // Reset z position to 0
snake_z_dir[snake_select] = false; // Set decreasing movements
}
}
}//while
Slowly_fade_off();
}//****snake****
void sine_wave() { //*****sine_wave*****sine_wave*****sine_wave*****sine_wave*****sine_wave*****sine_wave
start_brightness = 0;
target_brightness = 64;
int sinewavearray[8], addr, sinemult[8], rr = 0, gg = 0, bb = 0;
int sinewavearrayOLD[8], select, subT = 7, multi = 0; //random(-1, 2);
sinewavearray[0] = 0;
sinemult[0] = 1;
sinewavearray[1] = 1;
sinemult[1] = 1;
sinewavearray[2] = 2;
sinemult[2] = 1;
sinewavearray[3] = 3;
sinemult[3] = 1;
sinewavearray[4] = 4;
sinemult[4] = 1;
sinewavearray[5] = 5;
sinemult[5] = 1;
sinewavearray[6] = 6;
sinemult[6] = 1;
sinewavearray[7] = 7;
sinemult[7] = 1;
start = millis();
while (millis() - start < finish) {
for (addr = 0; addr < 8; addr++) {
if (sinewavearray[addr] == 7) {
sinemult[addr] = -1;
}
if (sinewavearray[addr] == 0) {
sinemult[addr] = 1;
}
sinewavearray[addr] = sinewavearray[addr] + sinemult[addr];
}//addr
if (sinewavearray[0] == 7) { // Once at the end of a complete cycle
select = random(3);
if (select == 0) {
rr = random(1, 16);
gg = random(1, 16);
bb = 0;
}
if (select == 1) {
rr = random(1, 16);
gg = 0;
bb = random(1, 16);
}
if (select == 2) {
rr = 0;
gg = random(1, 16);
bb = random(1, 16);
}
}
for (addr = 0; addr < 8; addr++) {
LED(sinewavearrayOLD[addr], addr, 0, 0, 0, 0);
LED(sinewavearrayOLD[addr], 0, addr, 0, 0, 0);
LED(sinewavearrayOLD[addr], subT - addr, 7, 0, 0, 0);
LED(sinewavearrayOLD[addr], 7, subT - addr, 0, 0, 0);
LED(sinewavearray[addr], addr, 0, rr, gg, bb);
LED(sinewavearray[addr], 0, addr, rr, gg, bb);
LED(sinewavearray[addr], subT - addr, 7, rr, gg, bb);
LED(sinewavearray[addr], 7, subT - addr, rr, gg, bb);
}
for (addr = 1; addr < 7; addr++) {
LED(sinewavearrayOLD[addr + multi * 1], addr, 1, 0, 0, 0);
LED(sinewavearrayOLD[addr + multi * 1], 1, addr, 0, 0, 0);
LED(sinewavearrayOLD[addr + multi * 1], subT - addr, 6, 0, 0, 0);
LED(sinewavearrayOLD[addr + multi * 1], 6, subT - addr, 0, 0, 0);
LED(sinewavearray[addr + multi * 1], addr, 1, rr, gg, bb);
LED(sinewavearray[addr + multi * 1], 1, addr, rr, gg, bb);
LED(sinewavearray[addr + multi * 1], subT - addr, 6, rr, gg, bb);
LED(sinewavearray[addr + multi * 1], 6, subT - addr, rr, gg, bb);
}
for (addr = 2; addr < 6; addr++) {
LED(sinewavearrayOLD[addr + multi * 2], addr, 2, 0, 0, 0);
LED(sinewavearrayOLD[addr + multi * 2], 2, addr, 0, 0, 0);
LED(sinewavearrayOLD[addr + multi * 2], subT - addr, 5, 0, 0, 0);
LED(sinewavearrayOLD[addr + multi * 2], 5, subT - addr, 0, 0, 0);
LED(sinewavearray[addr + multi * 2], addr, 2, rr, gg, bb);
LED(sinewavearray[addr + multi * 2], 2, addr, rr, gg, bb);
LED(sinewavearray[addr + multi * 2], subT - addr, 5, rr, gg, bb);
LED(sinewavearray[addr + multi * 2], 5, subT - addr, rr, gg, bb);
}
for (addr = 3; addr < 5; addr++) {
LED(sinewavearrayOLD[addr + multi * 3], addr, 3, 0, 0, 0);
LED(sinewavearrayOLD[addr + multi * 3], 3, addr, 0, 0, 0);
LED(sinewavearrayOLD[addr + multi * 3], subT - addr, 4, 0, 0, 0);
LED(sinewavearrayOLD[addr + multi * 3], 4, subT - addr, 0, 0, 0);
LED(sinewavearray[addr + multi * 3], addr, 3, rr, gg, bb);
LED(sinewavearray[addr + multi * 3], 3, addr, rr, gg, bb);
LED(sinewavearray[addr + multi * 3], subT - addr, 4, rr, gg, bb);
LED(sinewavearray[addr + multi * 3], 4, subT - addr, rr, gg, bb);
}
for (addr = 0; addr < 8; addr++)
sinewavearrayOLD[addr] = sinewavearray[addr];
start_brightness += 5; // Will slowly bring brightness to max
if (start_brightness > target_brightness) start_brightness = target_brightness;
FastLED.setBrightness(start_brightness);
FastLED.show();
delay(200);
}//while
Slowly_fade_off();
}//SinewaveTwo
void color_swipes() { //*****color_swipes*****color_swipes*****color_swipes*****color_swipes*****color_swipes
start_brightness = 16;
target_brightness = 64;
FastLED.setBrightness(start_brightness);
// diag_array contains the valid {X,Y} positions of pixels in the 15 possible diagonals of the cube
uint8_t diag_array[][8][2] = {{{0,0},{8,8},{8,8},{8,8},{8,8},{8,8},{8,8},{8,8}},
{{0,1},{1,0},{8,8},{8,8},{8,8},{8,8},{8,8},{8,8}},
{{0,2},{2,0},{1,1},{8,8},{8,8},{8,8},{8,8},{8,8}},
{{0,3},{3,0},{1,2},{2,1},{8,8},{8,8},{8,8},{8,8}},
{{0,4},{4,0},{1,3},{3,1},{2,2},{8,8},{8,8},{8,8}},
{{0,5},{5,0},{1,4},{4,1},{2,3},{3,2},{8,8},{8,8}},
{{0,6},{6,0},{1,5},{5,1},{2,4},{4,2},{3,3},{8,8}},
{{0,7},{7,0},{1,6},{6,1},{2,5},{5,2},{3,4},{4,3}},
{{1,7},{7,1},{2,6},{6,2},{3,5},{5,3},{4,4},{8,8}},
{{2,7},{7,2},{3,6},{6,3},{4,5},{5,4},{8,8},{8,8}},
{{3,7},{7,3},{4,6},{6,4},{5,5},{8,8},{8,8},{8,8}},
{{4,7},{7,4},{5,6},{6,5},{8,8},{8,8},{8,8},{8,8}},
{{5,7},{7,5},{6,6},{8,8},{8,8},{8,8},{8,8},{8,8}},
{{6,7},{7,6},{8,8},{8,8},{8,8},{8,8},{8,8},{8,8}},
{{7,7},{8,8},{8,8},{8,8},{8,8},{8,8},{8,8},{8,8}}};
uint8_t spiral_array[][2] = {{0,0},{0,1},{0,2},{0,3},{0,4},{0,5},{0,6},{0,7},
{1,7},{2,7},{3,7},{4,7},{5,7},{6,7},{7,7},{7,6},
{7,5},{7,4},{7,3},{7,2},{7,1},{7,0},{6,0},{5,0},
{4,0},{3,0},{2,0},{1,0},{1,1},{1,2},{1,3},{1,4},
{1,5},{1,6},{2,6},{3,6},{4,6},{5,6},{6,6},{6,5},
{6,4},{6,3},{6,2},{6,1},{5,1},{4,1},{3,1},{2,1},
{2,2},{2,3},{2,4},{2,5},{3,5},{4,5},{5,5},{5,4},
{5,3},{5,2},{4,2},{3,2},{3,3},{3,4},{4,4},{4,3}};
uint8_t xx, yy, zz;
uint16_t del = 100;
start = millis();
while (millis() - start < finish) {
orientation = random(24); // Will select a random face from which to start the swiping
CRGB random_color = CRGB (random(2, 256), random(2, 256), random(2, 256)); // Select a new random color
uint8_t select = random(8); // Selects various wiping patterns
start_brightness +=4; // Will slowly bring brightness to max
if (start_brightness > target_brightness) start_brightness = target_brightness;
FastLED.setBrightness(start_brightness);
switch(select){
case 0:
for (xx = 0; xx < 8; xx++) {
for (yy = 0; yy < 8; yy++) {
for (zz = 0; zz < 8; zz++) {
leds[XYZ(xx, yy, zz)] = random_color;
}
}
FastLED.show();
delay(del*2);
}
delay(1000);
break;
case 1:
for (xx = 0; xx < 4; xx++) {
for (yy = 0; yy < 8; yy++) {
for (zz = 0; zz < 8; zz++) {
leds[XYZ(xx, yy, zz)] = random_color;
leds[XYZ(7-xx, yy, zz)] = random_color;
}
}
FastLED.show();
delay(del*4);
}
delay(1000);
break;
case 2:
for (xx = 0; xx < 4; xx++) {
for (yy = 0; yy < 8; yy++) {
for (zz = 0; zz < 8; zz++) {
leds[XYZ(xx+4, yy, zz)] = random_color;
leds[XYZ(3-xx, yy, zz)] = random_color;
}
}
FastLED.show();
delay(del*4);
}
delay(1000);
break;
case 3:
for (xx = 0; xx < 15; xx++) {
for (yy = 0; yy < 8; yy++) {
for (zz = 0; zz < 8; zz++) {
leds[XYZ(diag_array[xx][yy][0], diag_array[xx][yy][1], zz)] = random_color;
}
}
FastLED.show();
delay(del);
}
delay(1000);
break;
case 4:
for (xx = 0; xx < 8; xx++) {
for (yy = 0; yy < 8; yy++) {
for (zz = 0; zz < 8; zz++) {
leds[XYZ(diag_array[7+xx][yy][0], diag_array[7+xx][yy][1], zz)] = random_color;
leds[XYZ(diag_array[7-xx][yy][0], diag_array[7-xx][yy][1], zz)] = random_color;
}
}
FastLED.show();
delay(del*2);
}
delay(1000);
break;
case 5:
for (xx = 0; xx < 8; xx++) {
for (yy = 0; yy < 8; yy++) {
for (zz = 0; zz < 8; zz++) {
leds[XYZ(diag_array[xx][yy][0], diag_array[xx][yy][1], zz)] = random_color;
leds[XYZ(diag_array[14-xx][yy][0], diag_array[14-xx][yy][1], zz)] = random_color;
}
}
FastLED.show();
delay(del*2);
}
delay(1000);
break;
case 6:
for (xx = 0; xx < 64; xx++) {
for (zz = 0; zz < 8; zz++) {
leds[XYZ(spiral_array[xx][0], spiral_array[xx][1], zz)] = random_color;
}
FastLED.show();
delay(25);
}
delay(1000);
break;
default:
for (xx = 0; xx < 64; xx++) {
for (zz = 0; zz < 8; zz++) {
leds[XYZ(spiral_array[63-xx][0], spiral_array[63-xx][1], zz)] = random_color;
}
FastLED.show();
delay(25);
}
delay(1000);
break;
} // End of switch case
}//while
Slowly_fade_off();
}//End of color_swipes
void harlem_shake() { //*****Harlem Shake*****Harlem Shake*****Harlem Shake*****Harlem Shake*****Harlem Shake*****Harlem Shake*****
start_brightness = 0;
target_brightness = 200;
int greenx = 7, greeny = 7, bluex = 7, bluey = 7, redx = 7, redy = 7;
// int greenx = 4, greeny = 4, bluex = 4, bluey = 4, redx = 4, redy = 4;
//int greenx = random(2,6), greeny = random(2,6), bluex = random(2,6), bluey = random(2,6), redx = random(2,6), redy = random(2,6);
int greenmultx = 1, bluemultx = 1, redmultx = 1, greenmulty = 1, bluemulty = 1, redmulty = 1;
int oredx = 0, oredy = 0, obluex = 0, obluey = 0, ogreenx = 0, ogreeny = 0;
int counter, i;
for (counter = 0; counter < 75; counter++) { // Red only
for (i = 0; i < 8; i++) {
LED(i, oredy, oredx, 0, 0, 0); // clears old red
LED(i, redy, redx, 15, 0, 0); // Redraws red
}
oredx = redx;
oredy = redy;
start_brightness += 10; // Will slowly bring brightness to max
if (start_brightness > target_brightness) start_brightness = target_brightness;
FastLED.setBrightness(start_brightness);
FastLED.show();
delay(200);
if (redy > 6 || redy < 1) redmulty = redmulty * -1;
if (redx > 6 || redx < 1) redmultx = redmultx * -1;
redy = redy + redmulty;
redx = redx + redmultx;
}//Red counter
for (counter = 0; counter < 75; counter++) { // Red and Green
for (i = 0; i < 8; i++) {
LED(i, oredy, oredx, 0, 0, 0);
LED(ogreenx, i, ogreeny, 0, 0, 0);
LED(i, redy, redx, 15, 0, 0);
LED(greenx, i, greeny, 0, 15, 0);
}
ogreenx = greenx;
ogreeny = greeny;
oredx = redx;
oredy = redy;
FastLED.show();
delay(200);
if (greeny > 6 || greeny < 1) greenmulty = greenmulty * -1;
if (redy > 6 || redy < 1) redmulty = redmulty * -1;
if (greenx > 6 || greenx < 1) greenmultx = greenmultx * -1;
if (redx > 6 || redx < 1) redmultx = redmultx * -1;
greenx = greenx + greenmultx;
greeny = greeny + greenmulty;
redy = redy + redmulty;
redx = redx + redmultx;
}// Red Green counter
for (counter = 0; counter < 75; counter++) { // All 3 colors slowy
for (i = 0; i < 8; i++) {
LED(i, oredy, oredx, 0, 0, 0);
LED(obluey, obluex, i, 0, 0, 0);
LED(ogreenx, i, ogreeny, 0, 0, 0);
LED(i, redy, redx, 15, 0, 0);
LED(bluey, bluex, i, 0, 0, 15);
LED(greenx, i, greeny, 0, 15, 0);
}
ogreenx = greenx;
ogreeny = greeny;
obluex = bluex;
obluey = bluey;
oredx = redx;
oredy = redy;
FastLED.show();
delay(200);
if (greeny > 6 || greeny < 1) greenmulty = greenmulty * -1;
if (bluey > 6 || bluey < 1) bluemulty = bluemulty * -1;
if (redy > 6 || redy < 1) redmulty = redmulty * -1;
if (greenx > 6 || greenx < 1) greenmultx = greenmultx * -1;
if (bluex > 6 || bluex < 1) bluemultx = bluemultx * -1;
if (redx > 6 || redx < 1) redmultx = redmultx * -1;
greenx = greenx + greenmultx;
greeny = greeny + greenmulty;
redy = redy + redmulty;
redx = redx + redmultx;
bluex = bluex + bluemultx;
bluey = bluey + bluemulty;
}//Red Green Blue counter
for (counter = 0; counter < 90; counter++) { // All 3 colors speeding up
for (i = 0; i < 8; i++) {
LED(i, oredy, oredx, 0, 0, 0);
LED(obluey, obluex, i, 0, 0, 0);
LED(ogreenx, i, ogreeny, 0, 0, 0);
LED(i, redy, redx, 15, 0, 0);
LED(bluey, bluex, i, 0, 0, 15);
LED(greenx, i, greeny, 0, 15, 0);
}
ogreenx = greenx;
ogreeny = greeny;
obluex = bluex;
obluey = bluey;
oredx = redx;
oredy = redy;
FastLED.show();
delay(200 - counter * 2);
if (greeny > 6 || greeny < 1) greenmulty = greenmulty * -1;
if (bluey > 6 || bluey < 1) bluemulty = bluemulty * -1;
if (redy > 6 || redy < 1) redmulty = redmulty * -1;
if (greenx > 6 || greenx < 1) greenmultx = greenmultx * -1;
if (bluex > 6 || bluex < 1) bluemultx = bluemultx * -1;
if (redx > 6 || redx < 1) redmultx = redmultx * -1;
greenx = greenx + greenmultx;
greeny = greeny + greenmulty;
redy = redy + redmulty;
redx = redx + redmultx;
bluex = bluex + bluemultx;
bluey = bluey + bluemulty;
}//Red Green Blue counter
for (counter = 0; counter < 90; counter++) { // All 3 colors slowing down
for (i = 0; i < 8; i++) {
LED(i, oredy, oredx, 0, 0, 0);
LED(obluey, obluex, i, 0, 0, 0);
LED(ogreenx, i, ogreeny, 0, 0, 0);
LED(i, redy, redx, 15, 0, 0);
LED(bluey, bluex, i, 0, 0, 15);
LED(greenx, i, greeny, 0, 15, 0);
}
ogreenx = greenx;
ogreeny = greeny;
obluex = bluex;
obluey = bluey;
oredx = redx;
oredy = redy;
FastLED.show();
delay(50 + counter * 2);
if (greeny > 6 || greeny < 1) greenmulty = greenmulty * -1;
if (bluey > 6 || bluey < 1) bluemulty = bluemulty * -1;
if (redy > 6 || redy < 1) redmulty = redmulty * -1;
if (greenx > 6 || greenx < 1) greenmultx = greenmultx * -1;
if (bluex > 6 || bluex < 1) bluemultx = bluemultx * -1;
if (redx > 6 || redx < 1) redmultx = redmultx * -1;
greenx = greenx + greenmultx;
greeny = greeny + greenmulty;
redy = redy + redmulty;
redx = redx + redmultx;
bluex = bluex + bluemultx;
bluey = bluey + bluemulty;
}//Red Green Blue counter
Slowly_fade_off();
} // Harlem shake
void moving_walls() { //*****moving_walls*****moving_walls*****moving_walls*****moving_walls*****moving_walls*****moving_walls*****
Set_all_to_black();
start_brightness = 128;
target_brightness = 128;
FastLED.setBrightness(start_brightness);
FastLED.show();
uint8_t wall_x = random(1, 7), wall_y = random(1, 7), wall_z = random(1, 7); // Start 3 perpendicular walls but not on edges to begin
int move_x_pos = wall_x + 1, move_x_neg = wall_x - 1, move_y_pos = wall_y + 1, move_y_neg = wall_y - 1, move_z_pos = wall_z + 1, move_z_neg = wall_z - 1;
uint8_t next_x = wall_x + 1, next_y = wall_y + 1, next_z = wall_z + 1;
boolean x_dir = true, y_dir = true, z_dir = true; // Where true means positive movement from pixel 0 to pixel 7
for (uint8_t br = 0; br < 128; br++) { // Start with a single red pixel at XYZ
leds[XYZ(wall_x, wall_y, wall_z)] += CRGB (2, 0, 0);
FastLED.show();
}
while (move_y_pos < 8 || move_y_neg >= 0) { // Extend a red line from the single pixel along Y axis
for (uint8_t br = 0; br < 128; br++) {
if (move_y_pos <= 7) leds[XYZ(wall_x, move_y_pos, wall_z)] += CRGB (2, 0, 0);
if (move_y_neg >= 0) leds[XYZ(wall_x, move_y_neg, wall_z)] += CRGB (2, 0, 0);
FastLED.show();
}
move_y_pos++;
move_y_neg--;
}
while (move_z_pos < 8 || move_z_neg >= 0) { // Extend a red plane from the red line along Z axis
for (uint8_t br = 0; br < 128; br++) {
if (move_z_pos <= 7) {
for (uint8_t yy = 0; yy < 8; yy++) leds[XYZ(wall_x, yy, move_z_pos)] += CRGB (2, 0, 0);
}
if (move_z_neg >= 0) {
for (uint8_t yy = 0; yy < 8; yy++) leds[XYZ(wall_x, yy, move_z_neg)] += CRGB (2, 0, 0);
}
FastLED.show();
}
move_z_pos++;
move_z_neg--;
}
for (uint8_t br = 0; br < 128; br++) { // Slowly add green to the single pixel at XYZ
leds[XYZ(wall_x, wall_y, wall_z)] += CRGB (0, 2, 0);
FastLED.show();
}
move_y_pos = wall_y + 1; // Reset initial values
move_y_neg = wall_y - 1;
move_z_pos = wall_z + 1; // Reset initial values
move_z_neg = wall_z - 1;
while (move_z_pos < 8 || move_z_neg >= 0) { // Extend a green line from the single pixel along Z axis
for (uint8_t br = 0; br < 128; br++) {
if (move_z_pos <= 7) leds[XYZ(wall_x, wall_y, move_z_pos)] += CRGB (0, 2, 0);
if (move_z_neg >= 0) leds[XYZ(wall_x, wall_y, move_z_neg )] += CRGB (0, 2, 0);
FastLED.show();
}
move_z_pos++;
move_z_neg--;
}
while (move_x_pos < 8 || move_x_neg >= 0) { // Extend a green plane from the green line along X axis
for (uint8_t br = 0; br < 128; br++) {
if (move_x_pos <= 7) {
for (uint8_t zz = 0; zz < 8; zz++) leds[XYZ(move_x_pos, wall_y, zz)] += CRGB (0, 2, 0);
}
if (move_x_neg >= 0) {
for (uint8_t zz = 0; zz < 8; zz++) leds[XYZ(move_x_neg, wall_y, zz)] += CRGB (0, 2, 0);
}
FastLED.show();
}
move_x_pos++;
move_x_neg--;
}
for (uint8_t br = 0; br < 128; br++) { // Slowly add blue to the single pixel at XYZ
leds[XYZ(wall_x, wall_y, wall_z)] += CRGB (0, 0, 2);
FastLED.show();
}
move_x_pos = wall_x + 1; // Reset initial values
move_x_neg = wall_x - 1;
move_z_pos = wall_z + 1; // Reset initial values
move_z_neg = wall_z - 1;
while (move_x_pos < 8 || move_x_neg >= 0) { // Extend a blue line from the single pixel along X axis
for (uint8_t br = 0; br < 128; br++) {
if (move_x_pos <= 7) leds[XYZ(move_x_pos, wall_y, wall_z)] += CRGB (0, 0, 2);
if (move_x_neg >= 0) leds[XYZ(move_x_neg, wall_y, wall_z )] += CRGB (0, 0, 2);
FastLED.show();
}
move_x_pos++;
move_x_neg--;
}
while (move_y_pos < 8 || move_y_neg >= 0) { // Extend a blue plane from the blue line along Y axis
for (uint8_t br = 0; br < 128; br++) {
if (move_y_pos <= 7) {
for (uint8_t xx = 0; xx < 8; xx++) leds[XYZ(xx, move_y_pos, wall_z)] += CRGB (0, 0, 2);
}
if (move_y_neg >= 0) {
for (uint8_t xx = 0; xx < 8; xx++) leds[XYZ(xx, move_y_neg, wall_z)] += CRGB (0, 0, 2);
}
FastLED.show();
}
move_y_pos++;
move_y_neg--;
}
delay(1000); // Just hang there a bit before we move things around...
uint16_t count = 0;
uint8_t pix_fract = 8;
start = millis();
while (millis() - start < finish) {
count++;
if (!(count % 11)) { // Time to update Z direction
for (uint8_t xx = 0; xx < 8; xx++) { // move X-Y plane in the Z direction
for (uint8_t yy = 0; yy < 8; yy++) {
leds[XYZ(xx, yy, wall_z)] -= CRGB (0, 0, pix_fract);
leds[XYZ(xx, yy, next_z)] += CRGB (0, 0, pix_fract);
}
}
if (!leds[XYZ(0, 0, wall_z)].b){ // Check if we have completely moved by one whole pixel
if (z_dir) { // If we are moving in the positive direction
wall_z++;
next_z++;
if (next_z == 8) { // We reached the end
z_dir = false; // so change direction
next_z = 6;
}
}
else {
wall_z--;
next_z--;
if (wall_z == 0) { // We reached the end
z_dir = true; // so change direction
next_z = 1;
}
}
}
}
if (!(count % 12)) { // Time to update Y direction
for (uint8_t xx = 0; xx < 8; xx++) { // move X-Z plane in the Y direction
for (uint8_t zz = 0; zz < 8; zz++) {
leds[XYZ(xx, wall_y, zz)] -= CRGB (0, pix_fract, 0);
leds[XYZ(xx, next_y, zz)] += CRGB (0, pix_fract, 0);
}
}
if (!leds[XYZ(0, wall_y, 0)].g){ // Check if we have completely moved by one whole pixel
if (y_dir) { // If we are moving in the positive direction
wall_y++;
next_y++;
if (next_y == 8) { // We reached the end
y_dir = false; // so change direction
next_y = 6;
}
}
else {
wall_y--;
next_y--;
if (wall_y == 0) { // We reached the end
y_dir = true; // so change direction
next_y = 1;
}
}
}
}
if (!(count % 13)) { // Time to update X direction
for (uint8_t yy = 0; yy < 8; yy++) { // move Y-Z plane in the X direction
for (uint8_t zz = 0; zz < 8; zz++) {
leds[XYZ(wall_x, yy, zz)] -= CRGB (pix_fract, 0, 0);
leds[XYZ(next_x, yy, zz)] += CRGB (pix_fract, 0, 0);
}
}
if (!leds[XYZ(wall_x, 0, 0)].r){ // Check if we have completely moved by one whole pixel
if (x_dir) { // If we are moving in the positive direction
wall_x++;
next_x++;
if (next_x == 8) { // We reached the end
x_dir = false; // so change direction
next_x = 6;
}
}
else {
wall_x--;
next_x--;
if (wall_x == 0) { // We reached the end
x_dir = true; // so change direction
next_x = 1;
}
}
}
}
FastLED.show();
}
Slowly_fade_off();
} // moving_walls
void pyramids() { //*****pyramids*****pyramids*****pyramids*****pyramids*****pyramids*****pyramids*****pyramids*****
uint8_t tiny[] = {8, 0, 1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 1, 0, 8, 8, 8, 8, 8, 8, 8, 8}; // Z height of square for each valid step
uint8_t small[] = {8, 8, 8, 0, 1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 1, 0, 8, 8, 8, 8, 8, 8};
uint8_t medium[] = {8, 8, 8, 8, 8, 0, 1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 1, 0, 8, 8, 8, 8};
uint8_t large[] = {8, 8, 8, 8, 8, 8, 8, 0, 1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 1, 0, 8, 8};
uint8_t count = 0;
start_brightness = 64;
target_brightness = 64;
FastLED.setBrightness(start_brightness);
FastLED.show();
start = millis();
while (millis() - start < finish) {
uint8_t hue = random(256); // Select a new random color
uint8_t brightness = 255;
uint8_t prev_brightness = 0;
orientation = random(24);
for (count = 1; count < 24; count++) {
Set_all_to_black();
for (int br = 0; br < 256; br+=8) {
brightness = br;
prev_brightness = 255 - br;
for (uint8_t i = 3; i < 5; i++) { // Draw a tiny 2X2 square at a given Z posistion
leds[XYZ(tiny[count], i, 3)] = CHSV (hue, 255, brightness);
leds[XYZ(tiny[count], 3, i)] = CHSV (hue, 255, brightness);
leds[XYZ(tiny[count], i, 4)] = CHSV (hue, 255, brightness);
leds[XYZ(tiny[count], 4, i)] = CHSV (hue, 255, brightness);
}
for (uint8_t i = 2; i < 6; i++) { // Draw a small 4X4 square at a given Z posistion
leds[XYZ(small[count], i, 2)] = CHSV (hue, 255, brightness);
leds[XYZ(small[count], 2, i)] = CHSV (hue, 255, brightness);
leds[XYZ(small[count], i, 5)] = CHSV (hue, 255, brightness);
leds[XYZ(small[count], 5, i)] = CHSV (hue, 255, brightness);
}
for (uint8_t i = 1; i < 7; i++) { // Draw a medium 6X6 square at a given Z posistion
leds[XYZ(medium[count], i, 1)] = CHSV (hue, 255, brightness);
leds[XYZ(medium[count], 1, i)] = CHSV (hue, 255, brightness);
leds[XYZ(medium[count], i, 6)] = CHSV (hue, 255, brightness);
leds[XYZ(medium[count], 6, i)] = CHSV (hue, 255, brightness);
}
for (uint8_t i = 0; i < 8; i++) { // Draw a large 8X8 square at a given Z posistion
leds[XYZ(large[count], i, 0)] = CHSV (hue, 255, brightness);
leds[XYZ(large[count], 0, i)] = CHSV (hue, 255, brightness);
leds[XYZ(large[count], i, 7)] = CHSV (hue, 255, brightness);
leds[XYZ(large[count], 7, i)] = CHSV (hue, 255, brightness);
}
for (uint8_t i = 3; i < 5; i++) { // Draw a tiny 2X2 square at a given Z posistion
leds[XYZ(tiny[count - 1], i, 3)] = CHSV (hue, 255, prev_brightness);
leds[XYZ(tiny[count - 1], 3, i)] = CHSV (hue, 255, prev_brightness);
leds[XYZ(tiny[count - 1], i, 4)] = CHSV (hue, 255, prev_brightness);
leds[XYZ(tiny[count - 1], 4, i)] = CHSV (hue, 255, prev_brightness);
}
for (uint8_t i = 2; i < 6; i++) { // Draw a small 4X4 square at a given Z posistion
leds[XYZ(small[count - 1], i, 2)] = CHSV (hue, 255, prev_brightness);
leds[XYZ(small[count - 1], 2, i)] = CHSV (hue, 255, prev_brightness);
leds[XYZ(small[count - 1], i, 5)] = CHSV (hue, 255, prev_brightness);
leds[XYZ(small[count - 1], 5, i)] = CHSV (hue, 255, prev_brightness);
}
for (uint8_t i = 1; i < 7; i++) { // Draw a medium 6X6 square at a given Z posistion
leds[XYZ(medium[count - 1], i, 1)] = CHSV (hue, 255, prev_brightness);
leds[XYZ(medium[count - 1], 1, i)] = CHSV (hue, 255, prev_brightness);
leds[XYZ(medium[count - 1], i, 6)] = CHSV (hue, 255, prev_brightness);
leds[XYZ(medium[count - 1], 6, i)] = CHSV (hue, 255, prev_brightness);
}
for (uint8_t i = 0; i < 8; i++) { // Draw a large 8X8 square at a given Z posistion
leds[XYZ(large[count - 1], i, 0)] = CHSV (hue, 255, prev_brightness);
leds[XYZ(large[count - 1], 0, i)] = CHSV (hue, 255, prev_brightness);
leds[XYZ(large[count - 1], i, 7)] = CHSV (hue, 255, prev_brightness);
leds[XYZ(large[count - 1], 7, i)] = CHSV (hue, 255, prev_brightness);
}
FastLED.show();
} // For br loop
} // For count loop
} //while loop
}//pyramids
void set_bloc(uint8_t what_bloc) { // *****set_bloc*****set_bloc*****set_bloc*****set_bloc*****set_bloc*****set_bloc*****set_bloc*****
uint8_t x = 0;
uint8_t y = 0;
uint8_t z = 0;
switch (what_bloc) {
case 0:
x = 0;
y = 0;
z = 0;
break;
case 1:
x = 0;
y = 4;
z = 0;
break;
case 2:
x = 4;
y = 4;
z = 0;
break;
case 3:
x = 4;
y = 0;
z = 0;
break;
case 4:
x = 0;
y = 0;
z = 4;
break;
case 5:
x = 0;
y = 4;
z = 4;
break;
case 6:
x = 4;
y = 4;
z = 4;
break;
}
available_positions[what_bloc] = what_bloc; //Start by putting bloc[0] in position[0], bloc[1] in position[1] etc... etc...
for (int a = x; a < x + 4; a++) {
for (int b = y; b < y + 4; b++) {
for (int c = z; c < z + 4; c++) {
leds[XYZ(a, b, c)] = CHSV(bloc[what_bloc].color, 255, 255);
}
}
}
}// End set_bloc
void move_bloc( uint8_t from, uint8_t to) {
// move_bloc is a function that moves a 4X4X4 bloc with it's back, right, lower corner at position (x,y,z) in the direction specified by Direct
// Direct (0=left, 1=right, 2=forward, 3=back, 4=up, 4=down)
int move_direction = 0;
uint8_t fade_step = 8; // increment-decrement steps for antialiased, smooth movement, 1 = slowest, 255 = fastest
int x = 0;
int y = 0;
int z = 0;
switch (from) {
case 0:
x = 0;
y = 0;
z = 0;
if (to == 1) move_direction = 2;
if (to == 3) move_direction = 0;
if (to == 4) move_direction = 4;
break;
case 1:
x = 0;
y = 4;
z = 0;
if (to == 0) move_direction = 3;
if (to == 2) move_direction = 0;
if (to == 5) move_direction = 4;
break;
case 2:
x = 4;
y = 4;
z = 0;
if (to == 1) move_direction = 1;
if (to == 3) move_direction = 3;
if (to == 6) move_direction = 4;
break;
case 3:
x = 4;
y = 0;
z = 0;
if (to == 0) move_direction = 1;
if (to == 2) move_direction = 2;
if (to == 7) move_direction = 4;
break;
case 4:
x = 0;
y = 0;
z = 4;
if (to == 0) move_direction = 5;
if (to == 5) move_direction = 2;
if (to == 7) move_direction = 0;
break;
case 5:
x = 0;
y = 4;
z = 4;
if (to == 1) move_direction = 5;
if (to == 4) move_direction = 3;
if (to == 6) move_direction = 0;
break;
case 6:
x = 4;
y = 4;
z = 4;
if (to == 2) move_direction = 5;
if (to == 5) move_direction = 1;
if (to == 7) move_direction = 3;
break;
case 7:
x = 4;
y = 0;
z = 4;
if (to == 3) move_direction = 5;
if (to == 4) move_direction = 1;
if (to == 6) move_direction = 2;
break;
}
switch (move_direction) {
case 0: // Move Left
for (int a = 0; a < 4; a++) { // Repeat fading for all 4 pixels
for (int b = 0; b < 256; b += fade_step) { // Fade pixels from 255 to 0
for (int c = z; c < z + 4; c++) {
for (int d = y; d < y + 4; d++) {
leds[XYZ(a, d, c)] = CHSV(bloc[available_positions[from]].color, 255, 255 - b);
leds[XYZ(a + 4, d, c)] = CHSV(bloc[available_positions[from]].color, 255, b);
}
}
FastLED.show();
}
}
break;
case 1: // Move Right
for (int a = 4; a > 0; a--) { // Repeat fading for all 4 pixels
for (int b = 0; b < 256; b += fade_step) { // Fade pixels from 255 to 0
for (int c = z; c < z + 4; c++) {
for (int d = y; d < y + 4; d++) {
leds[XYZ(a + 3, d, c)] = CHSV(bloc[available_positions[from]].color, 255, 255 - b);
leds[XYZ(a - 1, d, c)] = CHSV(bloc[available_positions[from]].color, 255, b);
}
}
FastLED.show();
}
}
break;
case 2: // Move Forward
for (int a = 0; a < 4; a++) { // Repeat fading for all 4 pixels
for (int b = 0; b < 256; b += fade_step) { // Fade pixels from 255 to 0
for (int c = z; c < z + 4; c++) {
for (int d = x; d < x + 4; d++) {
leds[XYZ(d, a, c)] = CHSV(bloc[available_positions[from]].color, 255, 255 - b);
leds[XYZ(d, a + 4, c)] = CHSV(bloc[available_positions[from]].color, 255, b);
}
}
FastLED.show();
}
}
break;
case 3: // Move Back
for (int a = 4; a > 0; a--) { // Repeat fading for all 4 pixels
for (int b = 0; b < 256; b += fade_step) { // Fade pixels from 255 to 0
for (int c = z; c < z + 4; c++) {
for (int d = x; d < x + 4; d++) {
leds[XYZ(d, a + 3, c)] = CHSV(bloc[available_positions[from]].color, 255, 255 - b);
leds[XYZ(d, a - 1, c)] = CHSV(bloc[available_positions[from]].color, 255, b);
}
}
FastLED.show();
}
}
break;
case 4: // Move Up
for (int a = 0; a < 4; a++) { // Repeat fading for all 4 pixels
for (int b = 0; b < 256; b += fade_step) { // Fade pixels from 255 to 0
for (int c = y; c < y + 4; c++) {
for (int d = x; d < x + 4; d++) {
leds[XYZ(d, c, a)] = CHSV(bloc[available_positions[from]].color, 255, 255 - b);
leds[XYZ(d, c, a + 4)] = CHSV(bloc[available_positions[from]].color, 255, b);
}
}
FastLED.show();
}
}
break;
case 5: // Move Down
for (int a = 4; a > 0; a--) { // Repeat fading for all 4 pixels
for (int b = 0; b < 256; b += fade_step) { // Fade pixels from 255 to 0
for (int c = y; c < y + 4; c++) {
for (int d = x; d < x + 4; d++) {
leds[XYZ(d, c, a + 3)] = CHSV(bloc[available_positions[from]].color, 255, 255 - b);
leds[XYZ(d, c, a - 1)] = CHSV(bloc[available_positions[from]].color, 255, b);
}
}
FastLED.show();
}
}
break;
}
available_positions[to] = available_positions[from];
available_positions[from] = 7;
bloc[available_positions[to]].previous_position = bloc[available_positions[to]].current_position;
bloc[available_positions[to]].current_position = to;
} // End move_block
void blocks() { //*****blocs*****blocs*****blocs*****blocs*****blocs*****blocs*****blocs*****blocs*****blocs*****blocs*****blocs*****
start_brightness = 16;
target_brightness = 64;
uint8_t number_of_blocs = random(3, 7);
uint8_t hue_step = 255 / number_of_blocs; // spread the bloc colors evenly accross the rainbow spectrum
fill_solid(leds, NUM_LEDS, CRGB(0, 0, 0));
for (uint8_t i = 0; i < 8; i++) available_positions[i] = 7; // 7 and up implies an empty position
for (int count = 0; count < number_of_blocs; count++) { // Initialise the number of blocs specified by 'number_of_blocs'
bloc[count].current_position = count;
bloc[count].previous_position = count;
bloc[count].color = count * hue_step;
set_bloc(count);
FastLED.setBrightness(start_brightness);
FastLED.show();
FastLED.delay (500);
}
while (start_brightness < target_brightness) {
start_brightness += 5;
FastLED.setBrightness(start_brightness);
FastLED.show();
FastLED.delay (50);
}
start = millis();
while (millis() - start < finish) {
int to = random(8); // Random number from 0 - 7 corresponding to available_positions
int from = random(8); // Random number from 0 - 7 corresponding to available_positions
boolean valid_move = false;
if (available_positions[to] == 7) { // Check if target position is empty
switch (to) { // Checks that the bloc to be moved is adjacent to the target position
case 0:
if ((from == 1 || from == 3 || from == 4) && available_positions[from] != 7) valid_move = true;
break;
case 1:
if ((from == 0 || from == 2 || from == 5) && available_positions[from] != 7) valid_move = true;
break;
case 2:
if ((from == 1 || from == 3 || from == 6) && available_positions[from] != 7) valid_move = true;
break;
case 3:
if ((from == 0 || from == 2 || from == 7) && available_positions[from] != 7) valid_move = true;
break;
case 4:
if ((from == 0 || from == 5 || from == 7) && available_positions[from] != 7) valid_move = true;
break;
case 5:
if ((from == 1 || from == 4 || from == 6) && available_positions[from] != 7) valid_move = true;
break;
case 6:
if ((from == 2 || from == 5 || from == 7) && available_positions[from] != 7) valid_move = true;
break;
case 7:
if ((from == 3 || from == 4 || from == 6) && available_positions[from] != 7) valid_move = true;
break;
}
// check that bloc to move did not previously occupy target position
if (valid_move && bloc[available_positions[from]].previous_position != to) move_bloc(from, to);
} // End of if
} // End of while
Slowly_fade_off();
}// End blocks
void fillnoise8() { // Fill a frame of the x/y array of 8-bit noise values using the inoise8 function.
// If we're runing at a low "speed", some 8-bit artifacts become visible
// from frame-to-frame. In order to reduce this, we can do some fast data-smoothing.
// The amount of data smoothing we're doing depends on "speed".
uint8_t dataSmoothing = 0;
if ( speed < 50) {
dataSmoothing = 200 - (speed * 4);
}
for (int i = 0; i < CUBE_SIZE; i++) {
int ioffset = scale * i;
for (int j = 0; j < CUBE_SIZE; j++) {
int joffset = scale * j;
uint8_t data = inoise8(x + ioffset, y + joffset, z);
// The range of the inoise8 function is roughly 16-238.
// These two operations expand those values out to roughly 0..255
// You can comment them out if you want the raw noise data.
data = qsub8(data, 16);
data = qadd8(data, scale8(data, 39));
if ( dataSmoothing ) {
uint8_t olddata = noise[i][j];
uint8_t newdata = scale8( olddata, dataSmoothing) + scale8( data, 256 - dataSmoothing);
data = newdata;
}
noise[i][j] = data;
}
}
z += speed;
// apply slow drift to X and Y, just for visual variation.
x += speed / 8;
y -= speed / 16;
}
void mapNoiseToLEDsUsingPalette() {
static uint8_t ihue = 0;
for (int i = 0; i < CUBE_SIZE; i++) {
for (int j = 0; j < CUBE_SIZE; j++) {
// We use the value at the (i,j) coordinate in the noise
// array for our brightness, and the flipped value from (j,i)
// for our pixel's index into the color palette.
uint8_t index = noise[j][i];
uint8_t bri = noise[i][j];
// if this palette is a 'loop', add a slowly-changing base value
if ( colorLoop) {
index += ihue;
}
// brighten up, as the color palette itself often contains the
// light/dark dynamic range desired
if ( bri > 127 ) {
bri = 255;
} else {
bri = dim8_raw( bri * 2);
}
CRGB color = ColorFromPalette( currentPalette, index, bri);
static int nTo;
switch (layer)
{
case X_LAYER:
nTo = XYZ(nFillFrame, i, j);
break;
case Y_LAYER:
nTo = XYZ(i, nFillFrame, j);
break;
case Z_LAYER:
nTo = XYZ(i, j, nFillFrame);
break;
}
leds[nTo] = color;
}
}
ihue += 1;
}
void copyLayer(uint8_t fromLayer, uint8_t toLayer) { // Copies pixels from one layer to another
int nFrom = 0; // from pixel
int nTo = 0; // to pixel
for (int m = 0; m < CUBE_SIZE; m++)
for (int n = 0; n < CUBE_SIZE; n++)
{
switch (layer)
{
case X_LAYER:
nFrom = XYZ(fromLayer, m, n);
nTo = XYZ(toLayer, m, n);
break;
case Y_LAYER:
nFrom = XYZ(m, fromLayer, n);
nTo = XYZ(m, toLayer, n);
break;
case Z_LAYER:
nFrom = XYZ(m, n, fromLayer);
nTo = XYZ(m, n, toLayer);
break;
}
leds[nTo] = leds[nFrom];
}
}
void moveFrameForward() { // Copy frames foward in the plane being used from the fillFrame back
switch (fillDirection)
{
case UP:
{
for (int nLayer = CUBE_SIZE - 1; nLayer > 0; nLayer--) copyLayer(nFillFrame, nLayer);
}
break;
case DOWN:
{
for (int nLayer = 0; nLayer < CUBE_SIZE; nLayer++) copyLayer(nFillFrame, nLayer);
}
break;
}
}
void SetupRandomPalette() { // This function generates a random palette that's a gradient between four different colors.
// There are several different palettes of colors demonstrated here.
//
// FastLED provides several 'preset' palettes: RainbowColors_p, RainbowStripeColors_p,
// OceanColors_p, CloudColors_p, LavaColors_p, ForestColors_p, and PartyColors_p.
//
// Additionally, you can manually define your own color palettes, or you can write
// code that creates color palettes on the fly.
// 1 = 5 sec per palette
// 2 = 10 sec per palette
// etc
// This function generates a random palette that's a gradient
// between four different colors. The first is a dim hue, the second is
// a bright hue, the third is a bright pastel, and the last is
// another bright hue. This gives some visual bright/dark variation
// which is more interesting than just a gradient of different hues.
currentPalette = CRGBPalette16(
CHSV( random(256), 255, 32),
CHSV( random(256), 255, 255),
CHSV( random(256), 128, 255),
CHSV( random(256), 255, 255));
}
void SetupBlackAndWhiteStripedPalette() { // This function sets up a palette of black and white stripes using code.
// This function sets up a palette of black and white stripes,
// using code. Since the palette is effectively an array of
// sixteen CRGB colors, the various fill_* functions can be used
// to set them up.
// 'black out' all 16 palette entries...
fill_solid( currentPalette, 16, CRGB::Black);
// and set every fourth one to white.
currentPalette[0] = CRGB::White;
currentPalette[4] = CRGB::White;
currentPalette[8] = CRGB::White;
currentPalette[12] = CRGB::White;
}
void SetupPurpleAndGreenPalette() { // This function sets up a palette of purple and green stripes.
CRGB purple = CHSV( HUE_PURPLE, 255, 255);
CRGB green = CHSV( HUE_GREEN, 255, 255);
CRGB black = CRGB::Black;
currentPalette = CRGBPalette16(
green, green, green, black,
purple, purple, purple, black,
green, green, green, black,
purple, purple, purple, black);
}
void SelectPalette() {
uint8_t Palette_select = random(12); // Selects a number from 0 to 11
orientation = random(24);
speed = 1;
scale = random(15, 25);
colorLoop = 1;
switch (Palette_select) {
case 0: currentPalette = RainbowColors_p; break;
case 1: SetupPurpleAndGreenPalette(); break;
case 2: SetupBlackAndWhiteStripedPalette(); break;
case 3: currentPalette = ForestColors_p; break;
case 4: currentPalette = CloudColors_p; break;
case 5: currentPalette = LavaColors_p; break;
case 6: currentPalette = OceanColors_p; break;
case 7: currentPalette = PartyColors_p; break;
case 8: currentPalette = RainbowStripeColors_p; break;
default: SetupRandomPalette(); break;
}
}
void noise_animation() { //******noise_animation******noise_animation******noise_animation******noise_animation******
Set_all_to_black();
start_brightness = 0;
target_brightness = 128;
FastLED.setBrightness(start_brightness);
LEDS.show();
SelectPalette(); // Periodically choose a new palette with fixed speed and scale
uint8_t noise_delay = random(10, 30);
start = millis();
while (millis() - start < finish) { // Stay in this loop for 20 seconds
start_brightness++; // Will slowly bring brightness to max
if (start_brightness > target_brightness) start_brightness = target_brightness; // Will slowly bring brightness to max
FastLED.setBrightness(start_brightness);
fillnoise8(); // generate noise data
mapNoiseToLEDsUsingPalette(); // convert noise data to colors in the LED array
moveFrameForward();
noise_delay = random(10, 30);
LEDS.show();
delay(noise_delay);
} // End while
Slowly_fade_off();
} // End noise_animation function
class Particle {
public:
uint8_t type; // 0 = electron, 1 = dough hook, 2 = prop, 3 = earth, 4 = ballon
boolean CCW; // If true, initial direction of orbit is Counterclockwise
int16_t F16posX; // x position of the particle in fractions of a pixel (PIXRES) from origin (0,0,0)
int16_t F16posY; // y position of the particle in fractions of a pixel (PIXRES) from origin (0,0,0)
int16_t F16posZ; // z position of the particle in fractions of a pixel (PIXRES) from origin (0,0,0)
uint16_t radius; // radius of the particle in fractions of a pixel (PIXRES) from the CENTER
uint16_t off_center; // Valid only for cylinders to move center in one of the XYZ directions
uint16_t phi; // Azimuthal angle given as 16 bits unsigned value to sine & cosine functions
uint16_t theta; // Inclination angle given as 16 bits unsigned value to sine & cosine functions
uint16_t phi_speed; // Value to increment/decrement phi angle. Determines the particle speed.
uint16_t theta_offset; // Value to increment/decrement theta angle. Changes the particle rotation plane.
uint8_t hue; // particle color
Particle() { // Constructor for this class sets all variables to some default values
type = 0;
CCW = true;
F16posX = 0;
F16posY = 0;
F16posZ = 0;
radius = 0;
off_center = 0;
phi = 0;
theta = 0;
phi_speed = 0;
theta_offset = 0;
hue = 0;
}
void Move() { // Move function of the Particle class
switch (type) {
case 0: // Electrons
phi++;
if (phi > (2 * phi_speed) - 1) { // Checks when the particle has gone around 1 orbit
phi = 0;
theta += 10; // Slowly change electron's rotational plane after a full orbit.
}
F16posX = CENTER + (radius * cos(PI * theta / theta_offset) * sin(PI * phi / phi_speed));
F16posY = CENTER + (radius * sin(PI * theta / theta_offset) * sin(PI * phi / phi_speed));
F16posZ = CENTER + (radius * cos(PI * phi / phi_speed));
break;
case 1: // dough hook
phi++;
if (phi > 359) phi = 0;
F16posX = CENTER + (radius * sin(PI * theta / theta_offset) * cos(PI * phi / phi_speed));
F16posY = CENTER + (radius * sin(PI * theta / theta_offset) * sin(PI * phi / phi_speed));
F16posZ = CENTER + (radius * cos(PI * theta / theta_offset));
break;
case 2: // propeller CW and CCW
if (CCW) { // Checks if orbit is Counter-clockwise
phi++;
if (phi > 359) phi = 0; // Checks when the particle has gone around 1 orbit
}
else { // Orbit is clockwise
phi--;
if (phi > 359) phi = 359; // Checks when the particle has gone around 1 orbit
}
F16posX = off_center + (radius * cos(PI * theta / theta_offset) * sin(PI * phi / phi_speed));
F16posY = CENTER + (radius * sin(PI * theta / theta_offset) * sin(PI * phi / phi_speed));
F16posZ = CENTER + (radius * cos(PI * phi / phi_speed));
break;
case 3: // earth
phi+=4;
if (phi > 359) phi = 0;
F16posX = CENTER + (radius * sin(PI * theta / theta_offset) * cos(PI * phi / phi_speed));
F16posY = CENTER + (radius * sin(PI * theta / theta_offset) * sin(PI * phi / phi_speed));
F16posZ = CENTER + (radius * cos(PI * theta / theta_offset));
break;
case 4: // balloon
F16posX = CENTER + (radius * sin(PI * theta / theta_offset) * cos(PI * phi / phi_speed));
F16posY = CENTER + (radius * sin(PI * theta / theta_offset) * sin(PI * phi / phi_speed));
F16posZ = CENTER + (radius * cos(PI * theta / theta_offset));
break;
} // End switch-case
} // End of the Move Function within the Particle class
void Draw() { // Draw function of the Particle class
int x = F16posX >> 8; // PIXRES; // convert from pos to raw pixel number
int y = F16posY >> 8; // PIXRES; // convert from pos to raw pixel number
int z = F16posZ >> 8; // PIXRES; // convert from pos to raw pixel number
int fx = F16posX & 0xFF; // extract the 'fractional' part of the position
int fy = F16posY & 0xFF; // extract the 'fractional' part of the position
int fz = F16posZ & 0xFF; // extract the 'fractional' part of the position
int bx = 255 - fx; // Fractional part that remains and assigned to the base pixels
int by = 255 - fy; // Value to be distributed to X or Y or Z base pixels
int bz = 255 - fz;
uint8_t x0y0z0 = scale8(bx, scale8(by, bz));
uint8_t x0y0z1 = scale8(bx, scale8(by, fz));
uint8_t x0y1z0 = scale8(bx, scale8(fy, bz));
uint8_t x0y1z1 = scale8(bx, scale8(fy, fz));
uint8_t x1y0z0 = scale8(fx, scale8(by, bz));
uint8_t x1y0z1 = scale8(fx, scale8(by, fz));
uint8_t x1y1z0 = scale8(fx, scale8(fy, bz));
uint8_t x1y1z1 = scale8(fx, scale8(fy, fz));
leds[XYZ(x , y , z )] += CHSV( hue, 255, x0y0z0);
leds[XYZ(x , y , z + 1)] += CHSV( hue, 255, x0y0z1);
leds[XYZ(x , y + 1, z )] += CHSV( hue, 255, x0y1z0);
leds[XYZ(x , y + 1, z + 1)] += CHSV( hue, 255, x0y1z1);
leds[XYZ(x + 1, y , z )] += CHSV( hue, 255, x1y0z0);
leds[XYZ(x + 1, y , z + 1)] += CHSV( hue, 255, x1y0z1);
leds[XYZ(x + 1, y + 1, z )] += CHSV( hue, 255, x1y1z0);
leds[XYZ(x + 1, y + 1, z + 1)] += CHSV( hue, 255, x1y1z1);
/*
Serial.print("F16posX = ");
Serial.print(F16posX);
Serial.print(" F16posY = ");
Serial.print(F16posY);
Serial.print(" F16posZ = ");
Serial.print(F16posZ);
Serial.print(" x = ");
Serial.print(x);
Serial.print(" y = ");
Serial.print(y);
Serial.print(" z = ");
Serial.print(z);
Serial.print(" fx = ");
Serial.print(fx);
Serial.print(" fy = ");
Serial.print(fy);
Serial.print(" fz = ");
Serial.print(fz);
Serial.print(" bx = ");
Serial.print(bx);
Serial.print(" by = ");
Serial.print(by);
Serial.print(" bz = ");
Serial.print(bz);
Serial.print(" x0y0z0 = ");
Serial.print(x0y0z0);
Serial.print(" x0y0z1 = ");
Serial.print(x0y0z1);
Serial.print(" x0y1z0 = ");
Serial.print(x0y1z0);
Serial.print(" x0y1z1 = ");
Serial.print(x0y1z1);
Serial.print(" x1y0z0 = ");
Serial.print(x1y0z0);
Serial.print(" x1y0z1 = ");
Serial.print(x1y0z1);
Serial.print(" x1y1z0 = ");
Serial.print(x1y1z0);
Serial.print(" x1y1z1 = ");
Serial.println(x1y1z1);
*/
} // End of draw function
}; // End of the Particle class definition
Particle electron [NUM_ELECTRONS]; // Creates an array of electron objects of type Particle class
Particle hook [NUM_HOOKS]; // Creates an array of hook objects of type Particle class
Particle prop_cw [NUM_PROP]; // Creates an array of clockwise propeller objects of type Particle class
Particle prop_ccw [NUM_PROP]; // Creates an array of counterclockwise propeller objects of type Particle class
Particle part [NUM_PART]; // Creates an array of earth objects of type Particle class
void initElectrons() {
for (int i = 0; i < NUM_ELECTRONS; i++)
{
electron[i].type = 0; // electron is particle type 0
electron[i].CCW = true;
electron[i].radius = E_RADIUS;
electron[i].phi = i * 360 / NUM_ELECTRONS; // Evenly spreads the initial phi angle accross the full orbit
electron[i].theta = i * 180 / NUM_ELECTRONS; // Evenly spreads the initial theta angle accross all totation planes
electron[i].phi_speed = 180 + i*18; // Value to increment/decrement phi angle. Determines the particle speed.
electron[i].theta_offset = 180+ i*18; // Value to increment/decrement theta angle. Changes the particle rotation plane.
electron[i].hue = i * 256 / NUM_ELECTRONS; // Evenly spreads the color accross the HSV spectrum.
}
}
void initHook() {
for (int i = 0; i < NUM_HOOKS; i++)
{
hook[i].type = 1; // hook is particle type 1
hook[i].CCW = true; // Odd numbered electrons rotate counter-clockwise
hook[i].radius = H_RADIUS;
hook[i].phi = i * 360 / NUM_HOOKS; // Evenly spreads the initial phi angle accross the full orbit
hook[i].theta = i * 180 / NUM_HOOKS; // Evenly spreads the initial theta angle accross all totation planes
hook[i].phi_speed = 180; // Value to increment/decrement phi angle. Determines the particle speed.
hook[i].theta_offset = 180; // Value to increment/decrement theta angle. Changes the particle rotation plane.
hook[i].hue = i * 256 / NUM_HOOKS; // Evenly spreads the color accross the HSV spectrum.
}
}
void init_prop_cw() {
for (int i = 0; i < NUM_PROP; i++) {
prop_cw[i].type = 2; // Clockwise propeller is particle type 2
prop_cw[i].CCW = true;
prop_cw[i].off_center = 0;
if (i == 0) prop_cw[i].radius = 0;
if (i > 0 && i < 5) prop_cw[i].radius = 512;
if (i > 4 && i < 9) prop_cw[i].radius = 768;
if (i == 1 || i == 5 ) prop_cw[i].phi = 0; // Evenly spreads the initial phi angle accross the full range
if (i == 2 || i == 6 ) prop_cw[i].phi = 90; // Evenly spreads the initial phi angle accross the full range
if (i == 3 || i == 7 ) prop_cw[i].phi = 180; // Evenly spreads the initial phi angle accross the full range
if (i == 4 || i == 8 ) prop_cw[i].phi = 270; // Evenly spreads the initial phi angle accross the full range
prop_cw[i].theta = 90; // Evenly spreads the initial theta angle accross the full range
prop_cw[i].phi_speed = 180; // Value to increment/decrement phi angle. Determines the particle speed.
prop_cw[i].theta_offset = 180; // Value to increment/decrement theta angle. Changes the particle rotation plane.
if (i == 0) prop_cw[i].hue = 64;
if (i == 1 || i == 5 ) prop_cw[i].hue = 96; // Evenly spreads the initial phi angle accross the full range
if (i == 2 || i == 6 ) prop_cw[i].hue = 160; // Evenly spreads the initial phi angle accross the full range
if (i == 3 || i == 7 ) prop_cw[i].hue = 0; // Evenly spreads the initial phi angle accross the full range
if (i == 4 || i == 8 ) prop_cw[i].hue = 192; // Evenly spreads the initial phi angle accross the full range
}
}
void init_prop_ccw() {
for (int i = 0; i < NUM_PROP; i++) {
prop_ccw[i].type = 2; // Counterclockwise propeller is particle type 2
prop_ccw[i].CCW = false;
prop_ccw[i].off_center = 0;
if (i == 0) prop_ccw[i].radius = 0;
if (i > 0 && i < 5) prop_ccw[i].radius = 512;
if (i > 4 && i < 9) prop_ccw[i].radius = 768;
if (i == 1 || i == 5 ) prop_ccw[i].phi = 0; // Evenly spreads the initial phi angle accross the full range
if (i == 2 || i == 6 ) prop_ccw[i].phi = 90; // Evenly spreads the initial phi angle accross the full range
if (i == 3 || i == 7 ) prop_ccw[i].phi = 180; // Evenly spreads the initial phi angle accross the full range
if (i == 4 || i == 8 ) prop_ccw[i].phi = 270; // Evenly spreads the initial phi angle accross the full range
prop_ccw[i].theta = 90; // Evenly spreads the initial theta angle accross the full range
prop_ccw[i].phi_speed = 180; // Value to increment/decrement phi angle. Determines the particle speed.
prop_ccw[i].theta_offset = 180; // Value to increment/decrement theta angle. Changes the particle rotation plane.
if (i == 0) prop_ccw[i].hue = 64;
if (i == 1 || i == 5 ) prop_ccw[i].hue = 96; // Evenly spreads the initial phi angle accross the full range
if (i == 2 || i == 6 ) prop_ccw[i].hue = 192; // Evenly spreads the initial phi angle accross the full range
if (i == 3 || i == 7 ) prop_ccw[i].hue = 0; // Evenly spreads the initial phi angle accross the full range
if (i == 4 || i == 8 ) prop_ccw[i].hue = 160; // Evenly spreads the initial phi angle accross the full range
}
}
void init_earth() {
uint8_t ii = 0;
uint8_t iii = 0;
for (int i = 0; i < NUM_PART; i++)
{
ii = i % 20;
iii = i / 20;
part[i].type = 3; // Earth is particle type 3
part[i].CCW = true; // All rotate in same direction
part[i].radius = E_RADIUS; // Fixed radius for all
part[i].phi_speed = 180; // A value of 180 makes phi unit = degrees. Other values can be used to affect the particle rotation speed.
part[i].theta_offset = 180; // A value of 180 makes theta unit = degrees. Other values can be used to affect the particle rotation height.
part[i].phi = ii * 360 / 20; // Evenly spreads the initial phi angle accross the full orbit
part[i].theta = iii * 18; // Evenly spreads the initial phi angle accross the full orbit
part[i].hue = ii * 256 / 20; // Spread colors around
}
}
void balloon(int radius, uint8_t color) {
uint8_t ii = 0;
uint8_t iii = 0;
for (int i = 0; i < NUM_PART; i++)
{
ii = i % 20;
iii = i / 20;
part[i].type = 4; // Balloon is particle type 4
part[i].CCW = true; // All rotate in same direction
part[i].radius = radius; // Fixed radius for all
part[i].phi_speed = 180; // A value of 180 makes phi unit = degrees. Other values can be used to affect the particle rotation speed.
part[i].theta_offset = 180; // A value of 180 makes theta unit = degrees. Other values can be used to affect the particle rotation height.
part[i].phi = ii * 360 / 20; // Evenly spreads the initial phi angle accross the full orbit
part[i].theta = iii * 18; // Evenly spreads the initial theta angle accross the full height
part[i].hue = color; // Spread colors around
}
}
void initPixelsNucleus() {
leds[XYZ(3, 3, 3)] = nucleous[0];
leds[XYZ(3, 4, 3)] = nucleous[1];
leds[XYZ(3, 3, 4)] = nucleous[1];
leds[XYZ(3, 4, 4)] = nucleous[0];
leds[XYZ(4, 3, 3)] = nucleous[1];
leds[XYZ(4, 4, 3)] = nucleous[0];
leds[XYZ(4, 3, 4)] = nucleous[0];
leds[XYZ(4, 4, 4)] = nucleous[1];
leds[XYZ(2, 3, 3)] = nucleous[1];
leds[XYZ(2, 4, 3)] = nucleous[0];
leds[XYZ(2, 3, 4)] = nucleous[0];
leds[XYZ(2, 4, 4)] = nucleous[1];
leds[XYZ(5, 3, 3)] = nucleous[0];
leds[XYZ(5, 4, 3)] = nucleous[1];
leds[XYZ(5, 3, 4)] = nucleous[1];
leds[XYZ(5, 4, 4)] = nucleous[0];
leds[XYZ(3, 2, 3)] = nucleous[1];
leds[XYZ(3, 5, 3)] = nucleous[0];
leds[XYZ(3, 2, 4)] = nucleous[0];
leds[XYZ(3, 5, 4)] = nucleous[1];
leds[XYZ(4, 2, 3)] = nucleous[0];
leds[XYZ(4, 5, 3)] = nucleous[1];
leds[XYZ(4, 2, 4)] = nucleous[1];
leds[XYZ(4, 5, 4)] = nucleous[0];
leds[XYZ(3, 3, 2)] = nucleous[1];
leds[XYZ(3, 4, 2)] = nucleous[0];
leds[XYZ(3, 3, 5)] = nucleous[0];
leds[XYZ(3, 4, 5)] = nucleous[1];
leds[XYZ(4, 3, 2)] = nucleous[0];
leds[XYZ(4, 4, 2)] = nucleous[1];
leds[XYZ(4, 3, 5)] = nucleous[1];
leds[XYZ(4, 4, 5)] = nucleous[0];
}
void paintNucleus(int x, int y, int z) {
if (leds[XYZ(x, y, z)].r & 1) { // is red odd?
leds[XYZ(x, y, z)] -= NucleousColor; // darken if red is odd
} else {
leds[XYZ(x, y, z)] += NucleousColor; // brighten if red is even
}
}
void fillNucleus() {
paintNucleus(3, 3, 3);
paintNucleus(3, 4, 3);
paintNucleus(3, 3, 4);
paintNucleus(3, 4, 4);
paintNucleus(4, 3, 3);
paintNucleus(4, 4, 3);
paintNucleus(4, 3, 4);
paintNucleus(4, 4, 4);
paintNucleus(2, 3, 3);
paintNucleus(2, 4, 3);
paintNucleus(2, 3, 4);
paintNucleus(2, 4, 4);
paintNucleus(5, 3, 3);
paintNucleus(5, 4, 3);
paintNucleus(5, 3, 4);
paintNucleus(5, 4, 4);
paintNucleus(3, 2, 3);
paintNucleus(3, 5, 3);
paintNucleus(3, 2, 4);
paintNucleus(3, 5, 4);
paintNucleus(4, 2, 3);
paintNucleus(4, 5, 3);
paintNucleus(4, 2, 4);
paintNucleus(4, 5, 4);
paintNucleus(3, 3, 2);
paintNucleus(3, 4, 2);
paintNucleus(3, 3, 5);
paintNucleus(3, 4, 5);
paintNucleus(4, 3, 2);
paintNucleus(4, 4, 2);
paintNucleus(4, 3, 5);
paintNucleus(4, 4, 5);
}
void carbon_atom() {
Set_all_to_black();
start_brightness = 0;
target_brightness = 128;
FastLED.setBrightness(start_brightness);
LEDS.show();
initElectrons();
initPixelsNucleus();
start = millis();
while (millis() - start < finish) { // Stay in this loop for 20 seconds
nucleous[0] = leds[XYZ(3, 3, 3)];
nucleous[1] = leds[XYZ(3, 4, 3)];
start_brightness++;
if (start_brightness > target_brightness) start_brightness = target_brightness; // Will slowly bring brightness to max
FastLED.setBrightness(start_brightness);
nscale8(leds, NUM_LEDS, 245); // Dim everything
initPixelsNucleus(); // Re-initialise nucleous colors before fade
for (int i = 0; i < NUM_ELECTRONS; i++) {
switch(i){
case 0:
orientation = 0;
break;
case 1:
orientation = 5;
break;
case 2:
orientation = 8;
break;
case 3:
orientation = 13;
break;
case 4:
orientation = 16;
break;
default:
orientation = 23;
break;
}
electron[i].Move();
electron[i].Draw();
}
fillNucleus();
FastLED.show();
delay(2);
} // End while
Slowly_fade_off();
} // End Carbon_Atom animation
void boxes() { //****boxes****boxes****boxes****boxes****boxes****boxes****
start_brightness = 0;
target_brightness = 128;
Set_all_to_black();
FastLED.setBrightness(start_brightness);
FastLED.show();
start = millis();
while (millis() - start < finish) { // Stay in this loop for preset duration
uint8_t pixel_x = 0, pixel_y = 0, pixel_z = 0, pixel_brightness = 0;
uint8_t base_hue = random(256);
uint8_t pixel_hue_1 = base_hue;
uint8_t pixel_hue_2 = pixel_hue_1 + 64;
uint8_t pixel_hue_3 = pixel_hue_2 + 64;
uint8_t pixel_hue_4 = pixel_hue_3 + 64;
uint8_t count = 0;
for (pixel_x = 0; pixel_x < 8; pixel_x++) { // Slow draw largest 8X8 box in X direction
for (uint8_t brt = 0; brt < 32; brt++) {
pixel_brightness = brt << 3;
leds[XYZ(pixel_x, 0, 0)] = CHSV(pixel_hue_1, 255, pixel_brightness);
leds[XYZ(pixel_x, 7, 0)] = CHSV(pixel_hue_1, 255, pixel_brightness);
leds[XYZ(pixel_x, 0, 7)] = CHSV(pixel_hue_1, 255, pixel_brightness);
leds[XYZ(pixel_x, 7, 7)] = CHSV(pixel_hue_1, 255, pixel_brightness);
start_brightness++; // Will slowly bring brightness to max
if (start_brightness > target_brightness) start_brightness = target_brightness;
FastLED.setBrightness(start_brightness);
FastLED.show();
}
}
for (pixel_y = 1; pixel_y < 7; pixel_y++) { // Slow draw largest 8X8 box in Y direction
for (uint8_t brt = 0; brt < 32; brt++) {
pixel_brightness = brt << 3;
leds[XYZ(0, pixel_y, 0)] = CHSV(pixel_hue_1, 255, pixel_brightness);
leds[XYZ(7, pixel_y, 0)] = CHSV(pixel_hue_1, 255, pixel_brightness);
leds[XYZ(0, pixel_y, 7)] = CHSV(pixel_hue_1, 255, pixel_brightness);
leds[XYZ(7, pixel_y, 7)] = CHSV(pixel_hue_1, 255, pixel_brightness);
FastLED.show();
}
}
for (pixel_z = 1; pixel_z < 7; pixel_z++) { // Slow draw largest 8X8 box in Z direction
for (uint8_t brt = 0; brt < 32; brt++) {
pixel_brightness = brt << 3;
leds[XYZ(0, 0, pixel_z)] = CHSV(pixel_hue_1, 255, pixel_brightness);
leds[XYZ(7, 0, pixel_z)] = CHSV(pixel_hue_1, 255, pixel_brightness);
leds[XYZ(0, 7, pixel_z)] = CHSV(pixel_hue_1, 255, pixel_brightness);
leds[XYZ(7, 7, pixel_z)] = CHSV(pixel_hue_1, 255, pixel_brightness);
FastLED.show();
}
}
for (pixel_x = 1; pixel_x < 7; pixel_x++) { // Slow draw large 6X6 box in X direction
for (uint8_t brt = 0; brt < 32; brt++) {
pixel_brightness = brt << 3;
leds[XYZ(pixel_x, 1, 1)] = CHSV(pixel_hue_2, 255, pixel_brightness);
leds[XYZ(pixel_x, 6, 1)] = CHSV(pixel_hue_2, 255, pixel_brightness);
leds[XYZ(pixel_x, 1, 6)] = CHSV(pixel_hue_2, 255, pixel_brightness);
leds[XYZ(pixel_x, 6, 6)] = CHSV(pixel_hue_2, 255, pixel_brightness);
FastLED.show();
}
}
for (pixel_y = 2; pixel_y < 6; pixel_y++) { // Slow draw large 6X6 box in Y direction
for (uint8_t brt = 0; brt < 32; brt++) {
pixel_brightness = brt << 3;
leds[XYZ(1, pixel_y, 1)] = CHSV(pixel_hue_2, 255, pixel_brightness);
leds[XYZ(6, pixel_y, 1)] = CHSV(pixel_hue_2, 255, pixel_brightness);
leds[XYZ(1, pixel_y, 6)] = CHSV(pixel_hue_2, 255, pixel_brightness);
leds[XYZ(6, pixel_y, 6)] = CHSV(pixel_hue_2, 255, pixel_brightness);
FastLED.show();
}
}
for (pixel_z = 2; pixel_z < 6; pixel_z++) { // Slow draw large 6X6 box in Z direction
for (uint8_t brt = 0; brt < 32; brt++) {
pixel_brightness = brt << 3;
leds[XYZ(1, 1, pixel_z)] = CHSV(pixel_hue_2, 255, pixel_brightness);
leds[XYZ(6, 1, pixel_z)] = CHSV(pixel_hue_2, 255, pixel_brightness);
leds[XYZ(1, 6, pixel_z)] = CHSV(pixel_hue_2, 255, pixel_brightness);
leds[XYZ(6, 6, pixel_z)] = CHSV(pixel_hue_2, 255, pixel_brightness);
FastLED.show();
}
}
for (pixel_x = 2; pixel_x < 6; pixel_x++) { // Slow draw medium 4X4 box in X direction
for (uint8_t brt = 0; brt < 32; brt++) {
pixel_brightness = brt << 3;
leds[XYZ(pixel_x, 2, 2)] = CHSV(pixel_hue_3, 255, pixel_brightness);
leds[XYZ(pixel_x, 5, 2)] = CHSV(pixel_hue_3, 255, pixel_brightness);
leds[XYZ(pixel_x, 2, 5)] = CHSV(pixel_hue_3, 255, pixel_brightness);
leds[XYZ(pixel_x, 5, 5)] = CHSV(pixel_hue_3, 255, pixel_brightness);
FastLED.show();
}
}
for (pixel_y = 3; pixel_y < 5; pixel_y++) { // Slow draw medium 4X4 box in Y direction
for (uint8_t brt = 0; brt < 32; brt++) {
pixel_brightness = brt << 3;
leds[XYZ(2, pixel_y, 2)] = CHSV(pixel_hue_3, 255, pixel_brightness);
leds[XYZ(5, pixel_y, 2)] = CHSV(pixel_hue_3, 255, pixel_brightness);
leds[XYZ(2, pixel_y, 5)] = CHSV(pixel_hue_3, 255, pixel_brightness);
leds[XYZ(5, pixel_y, 5)] = CHSV(pixel_hue_3, 255, pixel_brightness);
FastLED.show();
}
}
for (pixel_z = 3; pixel_z < 5; pixel_z++) { // Slow draw medium 4X4 box in Z direction
for (uint8_t brt = 0; brt < 32; brt++) {
pixel_brightness = brt << 3;
leds[XYZ(2, 2, pixel_z)] = CHSV(pixel_hue_3, 255, pixel_brightness);
leds[XYZ(5, 2, pixel_z)] = CHSV(pixel_hue_3, 255, pixel_brightness);
leds[XYZ(2, 5, pixel_z)] = CHSV(pixel_hue_3, 255, pixel_brightness);
leds[XYZ(5, 5, pixel_z)] = CHSV(pixel_hue_3, 255, pixel_brightness);
FastLED.show();
}
}
for (pixel_x = 3; pixel_x < 5; pixel_x++) { // Slow draw smallest 2X2 box
for (uint8_t brt = 0; brt < 32; brt++) {
pixel_brightness = brt << 3;
leds[XYZ(pixel_x, 3, 3)] = CHSV(pixel_hue_4, 255, pixel_brightness);
leds[XYZ(pixel_x, 4, 3)] = CHSV(pixel_hue_4, 255, pixel_brightness);
leds[XYZ(pixel_x, 3, 4)] = CHSV(pixel_hue_4, 255, pixel_brightness);
leds[XYZ(pixel_x, 4, 4)] = CHSV(pixel_hue_4, 255, pixel_brightness);
FastLED.show();
}
}
delay(500); // Some delay before slowly erasing all the boxes
while (count < 5) {
for (pixel_x = 0; pixel_x < 8; pixel_x++) { // Quick draw largest 8X8 box in X direction
leds[XYZ(pixel_x, 0, 0)] = CHSV(pixel_hue_1, 255, 255);
leds[XYZ(pixel_x, 7, 0)] = CHSV(pixel_hue_1, 255, 255);
leds[XYZ(pixel_x, 0, 7)] = CHSV(pixel_hue_1, 255, 255);
leds[XYZ(pixel_x, 7, 7)] = CHSV(pixel_hue_1, 255, 255);
}
for (pixel_y = 1; pixel_y < 7; pixel_y++) { // Quick draw largest 8X8 box in Y direction
leds[XYZ(0, pixel_y, 0)] = CHSV(pixel_hue_1, 255, 255);
leds[XYZ(7, pixel_y, 0)] = CHSV(pixel_hue_1, 255, 255);
leds[XYZ(0, pixel_y, 7)] = CHSV(pixel_hue_1, 255, 255);
leds[XYZ(7, pixel_y, 7)] = CHSV(pixel_hue_1, 255, 255);
}
for (pixel_z = 1; pixel_z < 7; pixel_z++) { // Quick draw largest 8X8 box in Z direction
leds[XYZ(0, 0, pixel_z)] = CHSV(pixel_hue_1, 255, 255);
leds[XYZ(7, 0, pixel_z)] = CHSV(pixel_hue_1, 255, 255);
leds[XYZ(0, 7, pixel_z)] = CHSV(pixel_hue_1, 255, 255);
leds[XYZ(7, 7, pixel_z)] = CHSV(pixel_hue_1, 255, 255);
}
for (pixel_x = 1; pixel_x < 7; pixel_x++) { // Quick draw large 6X6 box in X direction
leds[XYZ(pixel_x, 1, 1)] = CHSV(pixel_hue_2, 255, 255);
leds[XYZ(pixel_x, 6, 1)] = CHSV(pixel_hue_2, 255, 255);
leds[XYZ(pixel_x, 1, 6)] = CHSV(pixel_hue_2, 255, 255);
leds[XYZ(pixel_x, 6, 6)] = CHSV(pixel_hue_2, 255, 255);
}
for (pixel_y = 2; pixel_y < 6; pixel_y++) { // Quick draw large 6X6 box in Y direction
leds[XYZ(1, pixel_y, 1)] = CHSV(pixel_hue_2, 255, 255);
leds[XYZ(6, pixel_y, 1)] = CHSV(pixel_hue_2, 255, 255);
leds[XYZ(1, pixel_y, 6)] = CHSV(pixel_hue_2, 255, 255);
leds[XYZ(6, pixel_y, 6)] = CHSV(pixel_hue_2, 255, 255);
}
for (pixel_z = 2; pixel_z < 6; pixel_z++) { // Quick draw large 6X6 box in Z direction
leds[XYZ(1, 1, pixel_z)] = CHSV(pixel_hue_2, 255, 255);
leds[XYZ(6, 1, pixel_z)] = CHSV(pixel_hue_2, 255, 255);
leds[XYZ(1, 6, pixel_z)] = CHSV(pixel_hue_2, 255, 255);
leds[XYZ(6, 6, pixel_z)] = CHSV(pixel_hue_2, 255, 255);
}
for (pixel_x = 2; pixel_x < 6; pixel_x++) { // Quick draw medium 4X4 box in X direction
leds[XYZ(pixel_x, 2, 2)] = CHSV(pixel_hue_3, 255, 255);
leds[XYZ(pixel_x, 5, 2)] = CHSV(pixel_hue_3, 255, 255);
leds[XYZ(pixel_x, 2, 5)] = CHSV(pixel_hue_3, 255, 255);
leds[XYZ(pixel_x, 5, 5)] = CHSV(pixel_hue_3, 255, 255);
}
for (pixel_y = 3; pixel_y < 5; pixel_y++) { // Quick draw medium 4X4 box in Y direction
leds[XYZ(2, pixel_y, 2)] = CHSV(pixel_hue_3, 255, 255);
leds[XYZ(5, pixel_y, 2)] = CHSV(pixel_hue_3, 255, 255);
leds[XYZ(2, pixel_y, 5)] = CHSV(pixel_hue_3, 255, 255);
leds[XYZ(5, pixel_y, 5)] = CHSV(pixel_hue_3, 255, 255);
}
for (pixel_z = 3; pixel_z < 5; pixel_z++) { // Quick draw medium 4X4 box in Z direction
leds[XYZ(2, 2, pixel_z)] = CHSV(pixel_hue_3, 255, 255);
leds[XYZ(5, 2, pixel_z)] = CHSV(pixel_hue_3, 255, 255);
leds[XYZ(2, 5, pixel_z)] = CHSV(pixel_hue_3, 255, 255);
leds[XYZ(5, 5, pixel_z)] = CHSV(pixel_hue_3, 255, 255);
}
for (pixel_x = 3; pixel_x < 5; pixel_x++) { // Quick draw smallest 2X2 box
leds[XYZ(pixel_x, 3, 3)] = CHSV(pixel_hue_4, 255, 255);
leds[XYZ(pixel_x, 4, 3)] = CHSV(pixel_hue_4, 255, 255);
leds[XYZ(pixel_x, 3, 4)] = CHSV(pixel_hue_4, 255, 255);
leds[XYZ(pixel_x, 4, 4)] = CHSV(pixel_hue_4, 255, 255);
}
FastLED.show();
delay(20);
pixel_hue_1++;
pixel_hue_2++;
pixel_hue_3++;
pixel_hue_4++;
if (pixel_hue_1 == base_hue) count++;
} // End while count
for (pixel_x = 0; pixel_x < 8; pixel_x++) { // Slow erase largest 8X8 box in X direction
for (int8_t brt = 31; brt >= 0; brt--) {
pixel_brightness = brt << 3;
leds[XYZ(pixel_x, 0, 0)] = CHSV(pixel_hue_1, 255, pixel_brightness);
leds[XYZ(pixel_x, 7, 0)] = CHSV(pixel_hue_1, 255, pixel_brightness);
leds[XYZ(pixel_x, 0, 7)] = CHSV(pixel_hue_1, 255, pixel_brightness);
leds[XYZ(pixel_x, 7, 7)] = CHSV(pixel_hue_1, 255, pixel_brightness);
FastLED.show();
}
}
for (pixel_y = 1; pixel_y < 7; pixel_y++) { // Slow erase largest 8X8 box in Y direction
for (int8_t brt = 31; brt >= 0; brt--) {
pixel_brightness = brt << 3;
leds[XYZ(0, pixel_y, 0)] = CHSV(pixel_hue_1, 255, pixel_brightness);
leds[XYZ(7, pixel_y, 0)] = CHSV(pixel_hue_1, 255, pixel_brightness);
leds[XYZ(0, pixel_y, 7)] = CHSV(pixel_hue_1, 255, pixel_brightness);
leds[XYZ(7, pixel_y, 7)] = CHSV(pixel_hue_1, 255, pixel_brightness);
FastLED.show();
}
}
for (pixel_z = 1; pixel_z < 7; pixel_z++) { // Slow erase largest 8X8 box in Z direction
for (int8_t brt = 31; brt >= 0; brt--) {
pixel_brightness = brt << 3;
leds[XYZ(0, 0, pixel_z)] = CHSV(pixel_hue_1, 255, pixel_brightness);
leds[XYZ(7, 0, pixel_z)] = CHSV(pixel_hue_1, 255, pixel_brightness);
leds[XYZ(0, 7, pixel_z)] = CHSV(pixel_hue_1, 255, pixel_brightness);
leds[XYZ(7, 7, pixel_z)] = CHSV(pixel_hue_1, 255, pixel_brightness);
FastLED.show();
}
}
for (pixel_x = 1; pixel_x < 7; pixel_x++) { // Slow erase large 6X6 box in X direction
for (int8_t brt = 31; brt >= 0; brt--) {
pixel_brightness = brt << 3;
leds[XYZ(pixel_x, 1, 1)] = CHSV(pixel_hue_2, 255, pixel_brightness);
leds[XYZ(pixel_x, 6, 1)] = CHSV(pixel_hue_2, 255, pixel_brightness);
leds[XYZ(pixel_x, 1, 6)] = CHSV(pixel_hue_2, 255, pixel_brightness);
leds[XYZ(pixel_x, 6, 6)] = CHSV(pixel_hue_2, 255, pixel_brightness);
FastLED.show();
}
}
for (pixel_y = 2; pixel_y < 6; pixel_y++) { // Slow erase large 6X6 box in Y direction
for (int8_t brt = 31; brt >= 0; brt--) {
pixel_brightness = brt << 3;
leds[XYZ(1, pixel_y, 1)] = CHSV(pixel_hue_2, 255, pixel_brightness);
leds[XYZ(6, pixel_y, 1)] = CHSV(pixel_hue_2, 255, pixel_brightness);
leds[XYZ(1, pixel_y, 6)] = CHSV(pixel_hue_2, 255, pixel_brightness);
leds[XYZ(6, pixel_y, 6)] = CHSV(pixel_hue_2, 255, pixel_brightness);
FastLED.show();
}
}
for (pixel_z = 2; pixel_z < 6; pixel_z++) { // Slow erase large 6X6 box in Z direction
for (int8_t brt = 31; brt >= 0; brt--) {
pixel_brightness = brt << 3;
leds[XYZ(1, 1, pixel_z)] = CHSV(pixel_hue_2, 255, pixel_brightness);
leds[XYZ(6, 1, pixel_z)] = CHSV(pixel_hue_2, 255, pixel_brightness);
leds[XYZ(1, 6, pixel_z)] = CHSV(pixel_hue_2, 255, pixel_brightness);
leds[XYZ(6, 6, pixel_z)] = CHSV(pixel_hue_2, 255, pixel_brightness);
FastLED.show();
}
}
for (pixel_x = 2; pixel_x < 6; pixel_x++) { // Slow erase medium 4X4 box in X direction
for (int8_t brt = 31; brt >= 0; brt--) {
pixel_brightness = brt << 3;
leds[XYZ(pixel_x, 2, 2)] = CHSV(pixel_hue_3, 255, pixel_brightness);
leds[XYZ(pixel_x, 5, 2)] = CHSV(pixel_hue_3, 255, pixel_brightness);
leds[XYZ(pixel_x, 2, 5)] = CHSV(pixel_hue_3, 255, pixel_brightness);
leds[XYZ(pixel_x, 5, 5)] = CHSV(pixel_hue_3, 255, pixel_brightness);
FastLED.show();
}
}
for (pixel_y = 3; pixel_y < 5; pixel_y++) { // Slow erase medium 4X4 box in Y direction
for (int8_t brt = 31; brt >= 0; brt--) {
pixel_brightness = brt << 3;
leds[XYZ(2, pixel_y, 2)] = CHSV(pixel_hue_3, 255, pixel_brightness);
leds[XYZ(5, pixel_y, 2)] = CHSV(pixel_hue_3, 255, pixel_brightness);
leds[XYZ(2, pixel_y, 5)] = CHSV(pixel_hue_3, 255, pixel_brightness);
leds[XYZ(5, pixel_y, 5)] = CHSV(pixel_hue_3, 255, pixel_brightness);
FastLED.show();
}
}
for (pixel_z = 3; pixel_z < 5; pixel_z++) { // Slow erase medium 4X4 box in Z direction
for (int8_t brt = 31; brt >= 0; brt--) {
pixel_brightness = brt << 3;
leds[XYZ(2, 2, pixel_z)] = CHSV(pixel_hue_3, 255, pixel_brightness);
leds[XYZ(5, 2, pixel_z)] = CHSV(pixel_hue_3, 255, pixel_brightness);
leds[XYZ(2, 5, pixel_z)] = CHSV(pixel_hue_3, 255, pixel_brightness);
leds[XYZ(5, 5, pixel_z)] = CHSV(pixel_hue_3, 255, pixel_brightness);
FastLED.show();
}
}
for (pixel_x = 3; pixel_x < 5; pixel_x++) { // Slow erase smallest 2X2 box
for (int8_t brt = 31; brt >= 0; brt--) {
pixel_brightness = brt << 3;
leds[XYZ(pixel_x, 3, 3)] = CHSV(pixel_hue_4, 255, pixel_brightness);
leds[XYZ(pixel_x, 4, 3)] = CHSV(pixel_hue_4, 255, pixel_brightness);
leds[XYZ(pixel_x, 3, 4)] = CHSV(pixel_hue_4, 255, pixel_brightness);
leds[XYZ(pixel_x, 4, 4)] = CHSV(pixel_hue_4, 255, pixel_brightness);
FastLED.show();
}
}
} // End while
} // End boxes
void dough_hook() { //******dough_hook******dough_hook******dough_hook******dough_hook******
Set_all_to_black();
start_brightness = 0;
target_brightness = 255;
FastLED.setBrightness(start_brightness);
LEDS.show();
initHook();
orientation = random(24);
start = millis();
while (millis() - start < finish) { // Stay in this loop for 20 seconds
start_brightness++; // Will slowly bring brightness to max
if (start_brightness > target_brightness) start_brightness = target_brightness;
FastLED.setBrightness(start_brightness);
nscale8(leds, NUM_LEDS, 200); // Dim everything
for (int i = 0; i < NUM_HOOKS; i++) {
hook[i].Move();
hook[i].Draw();
}
FastLED.show();
} // End while
Slowly_fade_off();
} // End dough_hook animation
void propeller() { //******propeller******propeller******propeller******propeller******
Set_all_to_black();
start_brightness = 0;
target_brightness = 96;
FastLED.setBrightness(start_brightness);
LEDS.show();
init_prop_cw();
init_prop_ccw();
start = millis();
while (millis() - start < finish) { // Stay in this loop for 20 seconds
start_brightness++; // Will slowly bring brightness to max
if (start_brightness > target_brightness) start_brightness = target_brightness;
FastLED.setBrightness(start_brightness);
nscale8(leds, NUM_LEDS, 240); // Dim everything
for (int i = 0; i < NUM_PROP; i++) {
prop_cw[i].Move();
prop_ccw[i].Move();
}
orientation = 19;
for (int i = 0; i < NUM_PROP; i++) prop_cw[i].Draw();
orientation = 20;
for (int i = 0; i < NUM_PROP; i++) prop_cw[i].Draw();
orientation = 9;
for (int i = 0; i < NUM_PROP; i++) prop_ccw[i].Draw();
orientation = 13;
for (int i = 0; i < NUM_PROP; i++) prop_ccw[i].Draw();
FastLED.show();
delay(10);
} // End while
Slowly_fade_off();
} // End propeller animation
void rotate_90() { //******rotate_90******rotate_90******rotate_90******rotate_90******
uint8_t p_x[] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 6, 5, 4, 3, 2, 1, 0}; // perimeter 8X8 rotation sequence
uint8_t p_y[] = {0, 1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0};
uint8_t l_x[] = {1, 1, 1, 1, 1, 1, 2, 3, 4, 5, 6, 6, 6, 6, 6, 6, 5, 4, 3, 2, 1}; // large box 6X6 rotation sequence
uint8_t l_y[] = {1, 2, 3, 4, 5, 6, 6, 6, 6, 6, 6, 5, 4, 3, 2, 1, 1, 1, 1, 1, 1};
uint8_t m_x[] = {2, 2, 2, 2, 3, 4, 5, 5, 5, 5, 4, 3, 2}; // medium box 4X4 rotation sequence
uint8_t m_y[] = {2, 3, 4, 5, 5, 5, 5, 4, 3, 2, 2, 2, 2};
uint8_t s_x[] = {3, 3, 4, 4, 3}; // small box 2X2 rotation sequence
uint8_t s_y[] = {3, 4, 4, 3, 3};
CRGB temp = CRGB (0, 0, 0);
for (uint8_t seq = 0; seq < 7; seq++) {
for (uint8_t zz = 0; zz < 8; zz++) {
temp = leds[XYZ(p_x[0], p_y[0], zz)];
for (uint8_t perim = 0; perim < 28; perim++) {
leds[XYZ(p_x[perim], p_y[perim], zz)] = leds[XYZ(p_x[perim + 1], p_y[perim + 1], zz)];
}
leds[XYZ(p_x[27], p_y[27], zz)] = temp;
}
if (seq > 0 && seq < 6) {
for (uint8_t zz = 0; zz < 8; zz++) {
temp = leds[XYZ(l_x[0], l_y[0], zz)];
for (uint8_t large = 0; large < 20; large++) {
leds[XYZ(l_x[large], l_y[large], zz)] = leds[XYZ(l_x[large + 1], l_y[large + 1], zz)];
}
leds[XYZ(l_x[19], l_y[19], zz)] = temp;
}
}
if (seq > 1 && seq < 5) {
for (uint8_t zz = 0; zz < 8; zz++) {
temp = leds[XYZ(m_x[0], m_y[0], zz)];
for (uint8_t medium = 0; medium < 12; medium++) {
leds[XYZ(m_x[medium], m_y[medium], zz)] = leds[XYZ(m_x[medium + 1], m_y[medium + 1], zz)];
}
leds[XYZ(m_x[11], m_y[11], zz)] = temp;
}
}
if (seq == 3) {
for (uint8_t zz = 0; zz < 8; zz++) {
temp = leds[XYZ(s_x[0], s_y[0], zz)];
for (uint8_t small = 0; small < 4; small++) {
leds[XYZ(s_x[small], s_y[small], zz)] = leds[XYZ(s_x[small + 1], s_y[small + 1], zz)];
}
leds[XYZ(s_x[3], s_y[3], zz)] = temp;
}
}
FastLED.show();
delay(100);
}
} // End rotate_90 function
void all_color_fades() { //*****all_color_fades*****all_color_fades*****all_color_fades*****all_color_fades*****all_color_fades
uint8_t xx, yy, zz;
uint16_t del = 5;
orientation = 0; // Will select a random face from which to start the swiping
start_brightness = 0;
target_brightness = 255;
uint8_t brx[] = {0, 4, 16, 32, 64, 128, 192, 255};
uint8_t bry[] = {0, 4, 16, 32, 64, 128, 192, 255};
uint8_t brz[] = {0, 4, 16, 32, 64, 128, 192, 255};
for (xx = 0; xx < 8; xx++) {
for (yy = 0; yy < 8; yy++) {
for (zz = 0; zz < 8; zz++) {
leds[XYZ(xx, yy, zz)] = CRGB(brx[xx], bry[yy], brz[zz]);
}
}
}
while ( start_brightness < target_brightness) {
FastLED.setBrightness(start_brightness);
FastLED.show();
delay(del);
start_brightness++;
}
start = millis();
while (millis() - start < finish) {
orientation = random(24);
rotate_90();
FastLED.show();
delay(1000);
}//while
Slowly_fade_off();
}//all_color_fades
void color_twinkle() { //******color_twinkle******color_twinkle******color_twinkle******color_twinkle******color_twinkle******
#define STARTING_BRIGHTNESS 32
#define BRIGHTEN_BY 64 // highest number up to 255 is fastest brightening
#define DIM_BY 240 // higher number up to 255 is slowest dimming
CRGBPalette16 gPalette = RainbowColors_p;
uint16_t start_brightness = 255;
enum { GETTING_DARKER = 0, GETTING_BRIGHTER = 1 };
bool pixel_direction[NUM_LEDS];
for ( uint16_t i = 0; i < NUM_LEDS; i++) pixel_direction[i] = GETTING_DARKER; // Initialize all pixel_direction
Set_all_to_black();
FastLED.setBrightness(start_brightness);
FastLED.show();
start = millis();
while (millis() - start < finish) { // Stay in this loop for 20 seconds
for ( uint16_t i = 0; i < NUM_LEDS; i++) {
if (!pixel_direction[i]) leds[i].nscale8(DIM_BY); // howMuchDarker Should be 255 - 8
else {
CRGB incrementalColor = leds[i];
incrementalColor.nscale8(BRIGHTEN_BY); // howMuchBrighter Should be 16
leds[i] += incrementalColor;
if ( leds[i].r == 255 || leds[i].g == 255 || leds[i].b == 255) pixel_direction[i] = GETTING_DARKER; // Maxed out reverse direction
}
}
uint16_t pos = random(NUM_LEDS); // Select a pixel for a potential twinkle start
if (!leds[pos].r && !leds[pos].g && !leds[pos].b) { // If there is no color in that pixel
leds[pos] = ColorFromPalette( gPalette, random(256), STARTING_BRIGHTNESS);
pixel_direction[pos] = GETTING_BRIGHTER;
}
FastLED.show();
FastLED.delay(20);
} // End while loop
Slowly_fade_off();
} // End color_twinkle******
void earth() { //******earth******earth******earth******earth******
Set_all_to_black();
start_brightness = 0;
target_brightness = 64;
FastLED.setBrightness(start_brightness);
LEDS.show();
init_earth();
orientation = 0;
start = millis();
while (millis() - start < finish) { // Stay in this loop for 20 seconds
start_brightness++; // Will slowly bring brightness to max
if (start_brightness > target_brightness) start_brightness = target_brightness;
FastLED.setBrightness(start_brightness);
nscale8(leds, NUM_LEDS, 230); // Dim everything
for (int i = 0; i < NUM_PART; i++) {
part[i].Move();
part[i].Draw();
}
FastLED.show();
} // End while
Slowly_fade_off();
} // End earth animation
void blow_balloon() { //******blow_balloon******blow_balloon******blow_balloon******blow_balloon******
Set_all_to_black();
start_brightness = 0;
target_brightness = 128;
FastLED.setBrightness(start_brightness);
LEDS.show();
uint8_t color = 0;
orientation = 0;
start = millis();
while (millis() - start < finish) { // Stay in this loop for 20 seconds
start_brightness = 0;
for (int x = 0; x < 2000; x += 32) {
balloon(x, color); // Initializes all the 200 ballon pixels with radius and color
nscale8(leds, NUM_LEDS, 100); // Dim everything
for (int i = 0; i < NUM_PART; i++) {
part[i].Move();
part[i].Draw();
}
start_brightness += 5; // Will slowly bring brightness to max
if (start_brightness > target_brightness) start_brightness = target_brightness;
FastLED.setBrightness(start_brightness);
FastLED.show();
//delay(1000);
}
for (int x = 2000; x >= 0; x -= 32) {
balloon(x, color);
//Set_all_to_black();
nscale8(leds, NUM_LEDS, 100); // Dim everything
for (int i = 0; i < NUM_PART; i++) {
part[i].Move();
part[i].Draw();
}
FastLED.show();
//delay(1000);
}
for (uint8_t fader = 0; fader < 4; fader++) { // Initial quick fade
fadeToBlackBy( leds, NUM_LEDS, 50);
FastLED.show();
delay(5);
}
for (uint8_t fader = 0; fader < 200; fader++) { // Finish witha a slower fade
fadeToBlackBy( leds, NUM_LEDS, 10);
FastLED.show();
delay(5);
}
color += 20;
} // End while
Slowly_fade_off();
} // End blow_balloon animation
void draw_dice() { //******draw_dice******draw_dice******draw_dice******draw_dice******
Set_all_to_black();
CRGB one = CRGB (255, 0, 255);
CRGB two = CRGB (0, 255, 255);
CRGB tre = CRGB (255, 255, 0);
CRGB fou = CRGB (0, 255, 0);
CRGB fiv = CRGB (0, 0, 255);
CRGB six = CRGB (255, 0, 0);
leds[XYZ(3, 3, 7)] = one; leds[XYZ(3, 4, 7)] = one; leds[XYZ(4, 3, 7)] = one; leds[XYZ(4, 4, 7)] = one;
leds[XYZ(1, 7, 1)] = two; leds[XYZ(1, 7, 2)] = two; leds[XYZ(2, 7, 1)] = two; leds[XYZ(2, 7, 2)] = two;
leds[XYZ(5, 7, 5)] = two; leds[XYZ(5, 7, 6)] = two; leds[XYZ(6, 7, 5)] = two; leds[XYZ(6, 7, 6)] = two;
leds[XYZ(0, 3, 3)] = tre; leds[XYZ(0, 3, 4)] = tre; leds[XYZ(0, 4, 3)] = tre; leds[XYZ(0, 4, 4)] = tre;
leds[XYZ(0, 5, 1)] = tre; leds[XYZ(0, 5, 2)] = tre; leds[XYZ(0, 6, 1)] = tre; leds[XYZ(0, 6, 2)] = tre;
leds[XYZ(0, 1, 5)] = tre; leds[XYZ(0, 1, 6)] = tre; leds[XYZ(0, 2, 5)] = tre; leds[XYZ(0, 2, 6)] = tre;
leds[XYZ(7, 1, 1)] = fou; leds[XYZ(7, 1, 2)] = fou; leds[XYZ(7, 2, 1)] = fou; leds[XYZ(7, 2, 2)] = fou;
leds[XYZ(7, 5, 5)] = fou; leds[XYZ(7, 5, 6)] = fou; leds[XYZ(7, 6, 5)] = fou; leds[XYZ(7, 6, 6)] = fou;
leds[XYZ(7, 5, 1)] = fou; leds[XYZ(7, 5, 2)] = fou; leds[XYZ(7, 6, 1)] = fou; leds[XYZ(7, 6, 2)] = fou;
leds[XYZ(7, 1, 5)] = fou; leds[XYZ(7, 1, 6)] = fou; leds[XYZ(7, 2, 5)] = fou; leds[XYZ(7, 2, 6)] = fou;
leds[XYZ(3, 0, 3)] = fiv; leds[XYZ(3, 0, 4)] = fiv; leds[XYZ(4, 0, 3)] = fiv; leds[XYZ(4, 0, 4)] = fiv;
leds[XYZ(1, 0, 1)] = fiv; leds[XYZ(1, 0, 2)] = fiv; leds[XYZ(2, 0, 1)] = fiv; leds[XYZ(2, 0, 2)] = fiv;
leds[XYZ(5, 0, 5)] = fiv; leds[XYZ(5, 0, 6)] = fiv; leds[XYZ(6, 0, 5)] = fiv; leds[XYZ(6, 0, 6)] = fiv;
leds[XYZ(5, 0, 1)] = fiv; leds[XYZ(5, 0, 2)] = fiv; leds[XYZ(6, 0, 1)] = fiv; leds[XYZ(6, 0, 2)] = fiv;
leds[XYZ(1, 0, 5)] = fiv; leds[XYZ(1, 0, 6)] = fiv; leds[XYZ(2, 0, 5)] = fiv; leds[XYZ(2, 0, 6)] = fiv;
leds[XYZ(1, 1, 0)] = six; leds[XYZ(1, 2, 0)] = six; leds[XYZ(2, 1, 0)] = six; leds[XYZ(2, 2, 0)] = six;
leds[XYZ(5, 5, 0)] = six; leds[XYZ(5, 6, 0)] = six; leds[XYZ(6, 5, 0)] = six; leds[XYZ(6, 6, 0)] = six;
leds[XYZ(1, 5, 0)] = six; leds[XYZ(2, 5, 0)] = six; leds[XYZ(1, 6, 0)] = six; leds[XYZ(2, 6, 0)] = six;
leds[XYZ(5, 1, 0)] = six; leds[XYZ(6, 1, 0)] = six; leds[XYZ(5, 2, 0)] = six; leds[XYZ(6, 2, 0)] = six;
leds[XYZ(3, 1, 0)] = six; leds[XYZ(3, 2, 0)] = six; leds[XYZ(4, 1, 0)] = six; leds[XYZ(4, 2, 0)] = six;
leds[XYZ(3, 5, 0)] = six; leds[XYZ(3, 6, 0)] = six; leds[XYZ(4, 5, 0)] = six; leds[XYZ(4, 6, 0)] = six;
} // end of draw_dice function
void dice() { //******dice******dice******dice******dice******
start_brightness = 0;
target_brightness = 128;
FastLED.setBrightness(start_brightness);
orientation = 2;
draw_dice();
LEDS.show();
for (start_brightness = 0; start_brightness < target_brightness; start_brightness++) { // Will slowly bring brightness to max
FastLED.setBrightness(start_brightness);
LEDS.show();
delay(10);
}
start = millis();
while (millis() - start < finish) { // Stay in this loop for 20 seconds
orientation = random(24);
rotate_90();
FastLED.show();
delay(500);
} // End while
Slowly_fade_off();
} // End dice animation
void draw_abcdef() { //******draw_abcdef******draw_abcdef******draw_abcdef******draw_abcdef******
Set_all_to_black();
CRGB one = CRGB (255, 0, 255);
CRGB two = CRGB (0, 255, 255);
CRGB tre = CRGB (255, 0, 0);
CRGB fou = CRGB (0, 0, 255);
CRGB fiv = CRGB (0, 255, 0);
CRGB six = CRGB (255, 255, 0);
leds[XYZ(0, 2, 1)] = one; leds[XYZ(0, 2, 2)] = one; leds[XYZ(0, 2, 3)] = one; leds[XYZ(0, 2, 4)] = one;
leds[XYZ(0, 2, 5)] = one; leds[XYZ(0, 5, 1)] = one; leds[XYZ(0, 5, 2)] = one; leds[XYZ(0, 5, 3)] = one;
leds[XYZ(0, 5, 4)] = one; leds[XYZ(0, 5, 5)] = one; leds[XYZ(0, 3, 3)] = one; leds[XYZ(0, 4, 3)] = one;
leds[XYZ(0, 3, 6)] = one; leds[XYZ(0, 4, 6)] = one;
leds[XYZ(5, 1, 7)] = two; leds[XYZ(5, 2, 7)] = two; leds[XYZ(5, 3, 7)] = two; leds[XYZ(5, 4, 7)] = two;
leds[XYZ(5, 5, 7)] = two; leds[XYZ(5, 6, 7)] = two; leds[XYZ(3, 1, 7)] = two; leds[XYZ(4, 1, 7)] = two;
leds[XYZ(3, 3, 7)] = two; leds[XYZ(4, 3, 7)] = two; leds[XYZ(3, 6, 7)] = two; leds[XYZ(4, 6, 7)] = two;
leds[XYZ(2, 2, 7)] = two; leds[XYZ(2, 4, 7)] = two; leds[XYZ(2, 5, 7)] = two;
leds[XYZ(7, 5, 2)] = tre; leds[XYZ(7, 5, 3)] = tre; leds[XYZ(7, 5, 4)] = tre; leds[XYZ(7, 5, 5)] = tre;
leds[XYZ(7, 3, 1)] = tre; leds[XYZ(7, 4, 1)] = tre; leds[XYZ(7, 3, 6)] = tre; leds[XYZ(7, 4, 6)] = tre;
leds[XYZ(7, 2, 2)] = tre; leds[XYZ(7, 2, 5)] = tre;
leds[XYZ(5, 1, 0)] = fou; leds[XYZ(5, 2, 0)] = fou; leds[XYZ(5, 3, 0)] = fou; leds[XYZ(5, 4, 0)] = fou;
leds[XYZ(5, 5, 0)] = fou; leds[XYZ(5, 6, 0)] = fou; leds[XYZ(4, 1, 0)] = fou; leds[XYZ(3, 1, 0)] = fou;
leds[XYZ(4, 6, 0)] = fou; leds[XYZ(3, 6, 0)] = fou; leds[XYZ(2, 2, 0)] = fou; leds[XYZ(2, 3, 0)] = fou;
leds[XYZ(2, 4, 0)] = fou; leds[XYZ(2, 5, 0)] = fou;
leds[XYZ(2, 0, 1)] = fiv; leds[XYZ(3, 0, 1)] = fiv; leds[XYZ(4, 0, 1)] = fiv; leds[XYZ(5, 0, 1)] = fiv;
leds[XYZ(2, 0, 6)] = fiv; leds[XYZ(3, 0, 6)] = fiv; leds[XYZ(4, 0, 6)] = fiv; leds[XYZ(5, 0, 6)] = fiv;
leds[XYZ(5, 0, 2)] = fiv; leds[XYZ(5, 0, 3)] = fiv; leds[XYZ(5, 0, 4)] = fiv; leds[XYZ(5, 0, 5)] = fiv;
leds[XYZ(3, 0, 3)] = fiv; leds[XYZ(4, 0, 3)] = fiv;
leds[XYZ(2, 7, 1)] = six; leds[XYZ(3, 7, 1)] = six; leds[XYZ(4, 7, 1)] = six; leds[XYZ(5, 7, 1)] = six;
leds[XYZ(2, 7, 2)] = six; leds[XYZ(2, 7, 4)] = six; leds[XYZ(2, 7, 5)] = six; leds[XYZ(2, 7, 6)] = six;
leds[XYZ(2, 7, 3)] = six; leds[XYZ(3, 7, 3)] = six; leds[XYZ(4, 7, 3)] = six;
} // end of draw_abcdef function
void abcdef() { //******abcdef******abcdef******abcdef******abcdef******
start_brightness = 0;
target_brightness = 128;
FastLED.setBrightness(start_brightness);
orientation = 3;
draw_abcdef();
LEDS.show();
for (start_brightness = 0; start_brightness < target_brightness; start_brightness++) { // Will slowly bring brightness to max
FastLED.setBrightness(start_brightness);
LEDS.show();
delay(10);
}
uint16_t delay_1 = 10;
uint16_t delay_2 = 2000;
uint16_t rotation_sequence[][2] = {{12,delay_1},{16,delay_2}, // B
{0,delay_1},{20,delay_2}, // C
{12,delay_1},{20,delay_2}, // D
{8,delay_2}, // E
{0,delay_1},{0,delay_2}, // F
{0,delay_1},{20,delay_1},{20,delay_2}}; // A
delay(delay_2);
start = millis();
while (millis() - start < finish) { // Stay in this loop for 20 seconds
for (uint8_t seq = 0; seq < 12; seq++){
orientation = rotation_sequence[seq][0];
rotate_90();
FastLED.show();
delay(rotation_sequence[seq][1]);
}
} // End while
Slowly_fade_off();
} // End abcdef animation
void setup() { //****setup****setup****setup****setup****setup****setup****setup****setup****setup****setup****setup****setup****setup
randomSeed(analogRead(3));
Serial.begin(9600);
LEDS.addLeds<OCTOWS2811, RGB>(leds, LEDS_PER_PIN);
FastLED.setBrightness(start_brightness);
FastLED.setDither(0);
fill_solid(leds, NUM_LEDS, CRGB(0, 0, 0));
FastLED.show();
FastLED.delay (100);
randomSeed(analogRead(0));
x = random16(); // Initialize our cube noise coordinates to some random values
y = random16();
z = random16();
if (fillDirection == UP) nFillFrame = 0; else nFillFrame = CUBE_SIZE - 1; // Specific to noise
}//***end setup***end setup***end setup***end setup***end setup***end setup***end setup***end setup***end setup***end setup
void loop() { //***start loop***start loop***start loop***start loop***start loop***start loop***start loop***start loop***start loop
///*
boxes(); // Slow draw of gradually smaller centered boxes
rain(); // rain falling without accumulation at the bottom.
blocks(); // Number of 4X4X4 blocs (3-7) that move around randomly to available free position
earth(); // Earth like sphere slowly rotating
pyramids(); // Raising and lowering pyramids
harlem_shake(); // Not bad, has a few different animations. Must separate the different animations !
folder(); // All fixed, working nicely now !!!
bugs(); // Random number (4-8) bugs that move randomly in all directions. All fixed, good animation
noise_animation(); // Random noise patterns using palettes and fixed, optimized range of speed and scale
dough_hook(); // Slow spiraling animation similar to a a dough hook
dice(); // Animation of a regular 6 face dice being rotated
sine_wave(); // All fixed, good animation
snake(); // Not bad, snake like.
propeller(); // All 6 faces of the cube show a slow moving 4 blade propeller
color_swipes(); // whole cube color wiping changes left-right-front-back-up-down
moving_walls(); // Very similar to Harlem shake but more controlled movements to show how red and green and blue combine !
carbon_atom(); // Carbon atom with 6 electrons
all_color_fades(); // A nice representation of all color variations from white to black going through RGB
color_twinkle(); // Pixels very randomly fade in and out, no patterns
blow_balloon(); // Animation of a ballon being inflated
abcdef(); // Random rotation of a baby's cube with letters ABCEDF on the 6 faces
//*/
}//***end loop***end loop***end loop***end loop***end loop***end loop***end loop***end loop***end loop***end loop***end loop***end loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment