Infineon Team
Published © MIT

Christmas Greetings - XXL Chatbot

Ho Ho Ho - we wish you a great holiday season with this scaled up animatronik Chatbot

BeginnerFull instructions provided4 hours1,320
Christmas Greetings - XXL Chatbot

Things used in this project

Hardware components

Arduino Mega 2560
Arduino Mega 2560
×1
Adafruit 64x32 Flexible RGB LED Matrix - 4mm Pitch
×1
Adafruit RGB Matrix Shield for Arduino
×1
XMC2GO - industrial microcontroller kit
Infineon XMC2GO - industrial microcontroller kit
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
3D Printer (generic)
3D Printer (generic)

Story

Read more

Schematics

Round LED PCB

Production files

display a christmas tree on the 64x32 matrix_header

Code

display a christmas tree on the 64x32 matrix

Arduino
#include <Adafruit_GFX.h>    // Core graphics library
#include <RGBmatrixPanel.h>  // Hardware-specific library

#define CLK 11  // USE THIS ON ARDUINO MEGA
#define OE 9
#define LAT 10
#define A A0
#define B A1
#define C A2
#define D A3

#define V_OFF 5
#define H_OFF 16

#define WAIT_SWIPE 70
#define DIM 32

uint16_t world[DIM][DIM];
uint16_t copyWorld[DIM][DIM];

RGBmatrixPanel matrix(A, B, C, D, CLK, LAT, OE, false, 64);

uint16_t currentColor = 0;

class Game {
  friend void loop();
public:
  struct Point {
    Point(byte x, byte y)
      : x(x), y(y) {}
    Point()
      : x(0), y(0) {}
    byte x;
    byte y;
  };
  virtual void init() {
    _isOver = false;
    _rounds = 0;
    onInit();
  }
  virtual void simulate() = 0;
  virtual unsigned long getInterval() = 0;
  virtual bool isOver() const {
    return _isOver;
  }
  virtual uint16_t mapColor(byte x, byte y) {
    return world[x][y];
  }

  static uint16_t rgb(byte r, byte g, byte b) {
    return matrix.Color333(r / 32, g / 32, b / 32);
  }

protected:
  virtual void onInit() = 0;

  bool getRandomBool() {
    return random(2) == 1;
  }

  Point getRandomPos() {
    Point pt;
    while (true) {
      pt.x = random(0, DIM);
      pt.y = random(0, DIM);
      if (world[pt.x][pt.y] == 0) {
        break;
      }
    }
    return pt;
  }

  bool _isOver;
  uint16_t _rounds;
};

class Xmas : public Game {
public:
  Xmas() {}
  virtual void onInit() override;
  virtual void simulate() override;
  virtual unsigned long getInterval() override;
  virtual uint16_t mapColor(byte x, byte y) override;
  virtual bool isOver() const override;
};

#include <chatbot_xmas.h>

Xmas xmas;
Game* pGame = nullptr;


void chooseGame() {
  pGame = &xmas;
}


uint8_t getColorVal() {
  //return 7;
  return random(4, 8);
}

uint16_t getColor(bool newColor) {
  uint8_t r = 0;
  uint8_t g = 0;
  uint8_t b = 0;
  if (newColor) {
    currentColor = random() % 7;
  }
  switch (currentColor) {
    case 0:  // green
      g = getColorVal();
      break;

    case 1:  // red
      r = getColorVal();
      break;

    case 2:  // blue
      b = getColorVal();
      break;

    case 3:  // yellow
      r = getColorVal();
      g = getColorVal();
      break;

    case 4:  // cyan
      g = getColorVal();
      b = getColorVal();
      break;

    case 5:  // magenta
      r = getColorVal();
      b = getColorVal();
      break;

    default:  // white
      r = getColorVal();
      b = getColorVal();
      g = getColorVal();
      break;
  }
  return matrix.Color333(r, g, b);
}

void initWorld() {
  chooseGame();

  uint16_t color = getColor(true);
  // swipe left to right
  for (int c = 0; c < DIM; c++) {
    for (int r = 0; r < DIM; r++) {
      matrix.drawPixel(max(0, c - 1), r + 16, 0);
      matrix.drawPixel(c + V_OFF, r + H_OFF, color);
    }
    matrix.swapBuffers(true);
    delay(WAIT_SWIPE);
  }

  // init world
  for (int r = 0; r < DIM; r++) {
    for (int c = 0; c < DIM; c++) {
      world[r][c] = 0;
      copyWorld[r][c] = 0;
    }
  }

  pGame->init();

  // swipe right to left
  for (int c = DIM - 1; c >= 0; c--) {
    for (int r = 0; r < DIM; r++) {
      matrix.drawPixel(max(0, c - 1), r + 16, color);
      matrix.drawPixel(c + V_OFF, r + H_OFF, pGame->mapColor(r, c));
    }
    matrix.swapBuffers(true);
    delay(WAIT_SWIPE);
  }
}

void setup() {
  int seed = analogRead(11);
  delay(seed % 9);
  seed = seed * millis();
  randomSeed(seed);
  matrix.begin();
  matrix.setRotation(3);
  initWorld();
}

void render() {
  for (byte r = 0; r < DIM; r++) {
    for (byte c = 0; c < DIM; c++) {
      auto color = pGame->mapColor(r, c);
      matrix.drawPixel(c + V_OFF, r + H_OFF, color);
    }
  }
  matrix.swapBuffers(true);
}

void loop() {
  render();
  delay(pGame->getInterval());
  pGame->simulate();
  pGame->_rounds++;
  if (pGame->isOver()) {
    initWorld();
  }
}

chatbot_xmas.h

C Header File
#define OFF_1 2
#define OFF_2 -2

void Xmas::onInit()
{
world[3+OFF_1][4] = rgb(0,204,0);
world[OFF_1+3][5] = rgb(51,204,0);
world[OFF_1+4][3] = rgb(51,204,0);
world[OFF_1+4][4] = rgb(51,204,0);
world[OFF_1+4][5] = rgb(51,204,0);
world[OFF_1+4][6] = rgb(51,204,0);
world[OFF_1+4][7] = rgb(51,204,0);
world[OFF_1+5][3] = rgb(51,204,0);
world[OFF_1+5][4] = rgb(0,204,0);
world[OFF_1+5][5] = rgb(51,204,0);
world[OFF_1+5][6] = rgb(51,204,0);
world[OFF_1+5][7] = rgb(255,255,0);
world[OFF_1+5][8] = rgb(51,204,0);
world[OFF_1+5][9] = rgb(51,204,0);
world[OFF_1+6][3] = rgb(51,204,0);
world[OFF_1+6][4] = rgb(255,255,0);
world[OFF_1+6][5] = rgb(51,204,0);
world[OFF_1+6][6] = rgb(255,0,255);
world[OFF_1+6][7] = rgb(51,204,0);
world[OFF_1+6][8] = rgb(51,204,0);
world[OFF_1+6][9] = rgb(51,204,0);
world[OFF_1+6][10] = rgb(51,204,0);
world[OFF_1+6][11] = rgb(51,204,0);
world[OFF_1+7][3] = rgb(51,204,0);
world[OFF_1+7][4] = rgb(51,204,0);
world[OFF_1+7][5] = rgb(255,255,0);
world[OFF_1+7][6] = rgb(51,204,0);
world[OFF_1+7][7] = rgb(51,204,0);
world[OFF_1+7][8] = rgb(51,204,0);
world[OFF_1+7][9] = rgb(51,204,0);
world[OFF_1+7][10] = rgb(51,204,0);
world[OFF_1+7][11] = rgb(51,204,0);
world[OFF_1+7][12] = rgb(51,204,0);
world[OFF_1+7][13] = rgb(51,204,0);
world[OFF_1+8][3] = rgb(51,204,0);
world[OFF_1+8][4] = rgb(51,204,0);
world[OFF_1+8][5] = rgb(51,204,0);
world[OFF_1+8][6] = rgb(255,0,255);
world[OFF_1+8][7] = rgb(51,204,0);
world[OFF_1+8][8] = rgb(51,204,0);
world[OFF_1+8][9] = rgb(51,204,0);
world[OFF_1+8][10] = rgb(51,204,0);
world[OFF_1+8][11] = rgb(51,204,0);
world[OFF_1+8][12] = rgb(51,204,0);
world[OFF_1+8][13] = rgb(51,204,0);
world[OFF_1+8][14] = rgb(255,255,0);
world[OFF_1+8][15] = rgb(51,204,0);
world[OFF_1+9][3] = rgb(51,204,0);
world[OFF_1+9][4] = rgb(51,204,0);
world[OFF_1+9][5] = rgb(51,204,0);
world[OFF_1+9][6] = rgb(255,255,0);
world[OFF_1+9][7] = rgb(51,204,0);
world[OFF_1+9][8] = rgb(51,204,0);
world[OFF_1+9][9] = rgb(255,255,0);
world[OFF_1+9][10] = rgb(255,0,255);
world[OFF_1+9][11] = rgb(51,204,0);
world[OFF_1+9][12] = rgb(51,204,0);
world[OFF_1+9][13] = rgb(51,204,0);
world[OFF_1+9][14] = rgb(255,0,255);
world[OFF_1+9][15] = rgb(51,204,0);
world[OFF_1+9][16] = rgb(51,204,0);
world[OFF_1+9][17] = rgb(51,204,0);
world[OFF_1+10][3] = rgb(51,204,0);
world[OFF_1+10][4] = rgb(51,204,0);
world[OFF_1+10][5] = rgb(51,204,0);
world[OFF_1+10][6] = rgb(255,0,255);
world[OFF_1+10][7] = rgb(51,204,0);
world[OFF_1+10][8] = rgb(51,204,0);
world[OFF_1+10][9] = rgb(255,0,255);
world[OFF_1+10][10] = rgb(255,255,0);
world[OFF_1+10][11] = rgb(51,204,0);
world[OFF_1+10][12] = rgb(51,204,0);
world[OFF_1+10][13] = rgb(255,255,0);
world[OFF_1+10][14] = rgb(51,204,0);
world[OFF_1+10][15] = rgb(51,204,0);
world[OFF_1+10][16] = rgb(51,204,0);
world[OFF_1+10][17] = rgb(255,255,0);
world[OFF_1+10][18] = rgb(51,204,0);
world[OFF_1+10][19] = rgb(51,204,0);
world[OFF_1+11][2] = rgb(153,51,0);
world[OFF_1+11][3] = rgb(51,204,0);
world[OFF_1+11][4] = rgb(51,204,0);
world[OFF_1+11][5] = rgb(255,255,0);
world[OFF_1+11][6] = rgb(51,204,0);
world[OFF_1+11][7] = rgb(51,204,0);
world[OFF_1+11][8] = rgb(51,204,0);
world[OFF_1+11][9] = rgb(51,204,0);
world[OFF_1+11][10] = rgb(51,204,0);
world[OFF_1+11][11] = rgb(51,204,0);
world[OFF_1+11][12] = rgb(51,204,0);
world[OFF_1+11][13] = rgb(255,0,255);
world[OFF_1+11][14] = rgb(51,204,0);
world[OFF_1+11][15] = rgb(51,204,0);
world[OFF_1+11][16] = rgb(51,204,0);
world[OFF_1+11][17] = rgb(255,0,255);
world[OFF_1+11][18] = rgb(51,204,0);
world[OFF_1+11][19] = rgb(51,204,0);
world[OFF_1+11][20] = rgb(51,204,0);
world[OFF_1+11][21] = rgb(51,204,0);
world[OFF_1+12][0] = rgb(153,51,0);
world[OFF_1+12][1] = rgb(153,51,0);
world[OFF_1+12][2] = rgb(153,51,0);
world[OFF_1+12][3] = rgb(51,204,0);
world[OFF_1+12][4] = rgb(51,204,0);
world[OFF_1+12][5] = rgb(255,0,255);
world[OFF_1+12][6] = rgb(51,204,0);
world[OFF_1+12][7] = rgb(51,204,0);
world[OFF_1+12][8] = rgb(51,204,0);
world[OFF_1+12][9] = rgb(51,204,0);
world[OFF_1+12][10] = rgb(51,204,0);
world[OFF_1+12][11] = rgb(51,204,0);
world[OFF_1+12][12] = rgb(255,255,0);
world[OFF_1+12][13] = rgb(51,204,0);
world[OFF_1+12][14] = rgb(51,204,0);
world[OFF_1+12][15] = rgb(51,204,0);
world[OFF_1+12][16] = rgb(255,255,0);
world[OFF_1+12][17] = rgb(51,204,0);
world[OFF_1+12][18] = rgb(51,204,0);
world[OFF_1+12][19] = rgb(51,204,0);
world[OFF_1+12][20] = rgb(51,204,0);
world[OFF_1+12][21] = rgb(51,204,0);
world[OFF_1+12][22] = rgb(51,204,0);
world[OFF_1+12][23] = rgb(51,204,0);
world[OFF_1+13][0] = rgb(153,51,0);
world[OFF_1+13][1] = rgb(153,51,0);
world[OFF_1+13][2] = rgb(153,51,0);
world[OFF_1+13][3] = rgb(51,204,0);
world[OFF_1+13][4] = rgb(51,204,0);
world[OFF_1+13][5] = rgb(51,204,0);
world[OFF_1+13][6] = rgb(255,255,0);
world[OFF_1+13][7] = rgb(51,204,0);
world[OFF_1+13][8] = rgb(51,204,0);
world[OFF_1+13][9] = rgb(51,204,0);
world[OFF_1+13][10] = rgb(255,0,255);
world[OFF_1+13][11] = rgb(51,204,0);
world[OFF_1+13][12] = rgb(255,0,255);
world[OFF_1+13][13] = rgb(51,204,0);
world[OFF_1+13][14] = rgb(51,204,0);
world[OFF_1+13][15] = rgb(51,204,0);
world[OFF_1+13][16] = rgb(255,0,255);
world[OFF_1+13][17] = rgb(51,204,0);
world[OFF_1+13][18] = rgb(51,204,0);
world[OFF_1+13][19] = rgb(51,204,0);
world[OFF_1+13][20] = rgb(255,0,255);
world[OFF_1+13][21] = rgb(51,204,0);
world[OFF_1+13][22] = rgb(51,204,0);
world[OFF_1+13][23] = rgb(51,204,0);
world[OFF_1+13][24] = rgb(255,255,0);
world[OFF_1+13][25] = rgb(51,204,0);
/*world[OFF_1+14][0] = rgb(153,51,0);
world[OFF_1+14][1] = rgb(153,51,0);
world[14][2] = rgb(153,51,0);
world[14][3] = rgb(51,204,0);
world[14][4] = rgb(51,204,0);
world[14][5] = rgb(51,204,0);
world[14][6] = rgb(51,204,0);
world[14][7] = rgb(255,0,255);
world[14][8] = rgb(51,204,0);
world[14][9] = rgb(51,204,0);
world[14][10] = rgb(51,204,0);
world[14][11] = rgb(51,204,0);
world[14][12] = rgb(255,255,0);
world[14][13] = rgb(51,204,0);
world[14][14] = rgb(51,204,0);
world[14][15] = rgb(51,204,0);
world[14][16] = rgb(255,255,0);
world[14][17] = rgb(51,204,0);
world[14][18] = rgb(51,204,0);
world[14][19] = rgb(255,0,255);
world[14][20] = rgb(51,204,0);
world[14][21] = rgb(51,204,0);
world[14][22] = rgb(51,204,0);
world[14][23] = rgb(255,0,255);
world[14][24] = rgb(51,204,0);
world[14][25] = rgb(0,204,0);
world[14][26] = rgb(51,204,0);
world[14][27] = rgb(0,204,0);
world[14][28] = rgb(255,0,255);
world[14][31] = rgb(255,0,255);
world[15][0] = rgb(153,51,0);
world[15][1] = rgb(153,51,0);
world[15][2] = rgb(153,51,0);
world[15][3] = rgb(51,204,0);
world[15][4] = rgb(51,204,0);
world[15][5] = rgb(51,204,0);
world[15][6] = rgb(51,204,0);
world[15][7] = rgb(0,204,0);
world[15][8] = rgb(255,255,0);
world[15][9] = rgb(51,204,0);
world[15][10] = rgb(51,204,0);
world[15][11] = rgb(51,204,0);
world[15][12] = rgb(51,204,0);
world[15][13] = rgb(255,0,255);
world[15][14] = rgb(51,204,0);
world[15][15] = rgb(51,204,0);
world[15][16] = rgb(51,204,0);
world[15][17] = rgb(255,0,255);
world[15][18] = rgb(51,204,0);
world[15][19] = rgb(0,204,0);
world[15][20] = rgb(51,204,0);
world[15][21] = rgb(51,204,0);
world[15][22] = rgb(255,255,0);
world[15][23] = rgb(51,204,0);
world[15][24] = rgb(255,255,0);
world[15][25] = rgb(51,204,0);
world[15][26] = rgb(51,204,0);
world[15][27] = rgb(51,204,0);
world[15][28] = rgb(0,204,0);
world[15][29] = rgb(255,255,51);
world[15][30] = rgb(255,255,51);
world[16][0] = rgb(153,51,0);
world[16][1] = rgb(153,51,0);
world[16][2] = rgb(153,51,0);
world[16][3] = rgb(51,204,0);
world[16][4] = rgb(51,204,0);
world[16][5] = rgb(51,204,0);
world[16][6] = rgb(0,204,0);
world[16][7] = rgb(0,204,0);
world[16][8] = rgb(255,0,255);
world[16][9] = rgb(51,204,0);
world[16][10] = rgb(51,204,0);
world[16][11] = rgb(0,204,0);
world[16][12] = rgb(51,204,0);
world[16][13] = rgb(255,255,0);
world[16][14] = rgb(51,204,0);
world[16][15] = rgb(51,204,0);
world[16][16] = rgb(51,204,0);
world[16][17] = rgb(255,255,0);
world[16][18] = rgb(51,204,0);
world[16][19] = rgb(0,204,0);
world[16][20] = rgb(51,204,0);
world[16][21] = rgb(51,204,0);
world[16][22] = rgb(255,0,255);
world[16][23] = rgb(51,204,0);
world[16][24] = rgb(51,204,0);
world[16][25] = rgb(255,0,255);
world[16][26] = rgb(51,204,0);
world[16][27] = rgb(51,204,0);
world[16][28] = rgb(51,204,0);
world[16][29] = rgb(255,255,51);
world[16][30] = rgb(255,255,51);
world[17][0] = rgb(153,51,0);
world[17][1] = rgb(153,51,0);
world[17][2] = rgb(153,51,0);
world[17][3] = rgb(51,204,0);
world[17][4] = rgb(51,204,0);
world[17][5] = rgb(255,0,255);
world[17][6] = rgb(0,204,0);
world[17][7] = rgb(255,255,0);
world[17][8] = rgb(51,204,0);
world[17][9] = rgb(51,204,0);
world[17][10] = rgb(51,204,0);
world[17][11] = rgb(51,204,0);
world[17][12] = rgb(255,0,255);
world[17][13] = rgb(51,204,0);
world[17][14] = rgb(51,204,0);
world[17][15] = rgb(51,204,0);
world[17][16] = rgb(51,204,0);
world[17][17] = rgb(51,204,0);
world[17][18] = rgb(255,255,0);
world[17][19] = rgb(0,204,0);
world[17][20] = rgb(51,204,0);
world[17][21] = rgb(51,204,0);
world[17][22] = rgb(255,255,0);
world[17][23] = rgb(51,204,0);
world[17][24] = rgb(51,204,0);
world[17][25] = rgb(51,204,0);
world[17][26] = rgb(51,204,0);
world[17][27] = rgb(51,204,0);
world[17][28] = rgb(255,0,255);
world[17][31] = rgb(255,0,255);*/
world[OFF_2+18][0] = rgb(153,51,0);
world[OFF_2+18][1] = rgb(153,51,0);
world[OFF_2+18][2] = rgb(153,51,0);
world[OFF_2+18][3] = rgb(51,204,0);
world[OFF_2+18][4] = rgb(51,204,0);
world[OFF_2+18][5] = rgb(51,204,0);
world[OFF_2+18][6] = rgb(51,204,0);
world[OFF_2+18][7] = rgb(255,0,255);
world[OFF_2+18][8] = rgb(51,204,0);
world[OFF_2+18][9] = rgb(51,204,0);
world[OFF_2+18][10] = rgb(0,204,0);
world[OFF_2+18][11] = rgb(255,255,0);
world[OFF_2+18][12] = rgb(51,204,0);
world[OFF_2+18][13] = rgb(51,204,0);
world[OFF_2+18][14] = rgb(51,204,0);
world[OFF_2+18][15] = rgb(51,204,0);
world[OFF_2+18][16] = rgb(51,204,0);
world[OFF_2+18][17] = rgb(51,204,0);
world[OFF_2+18][18] = rgb(255,0,255);
world[OFF_2+18][19] = rgb(0,204,0);
world[OFF_2+18][20] = rgb(51,204,0);
world[OFF_2+18][21] = rgb(51,204,0);
world[OFF_2+18][22] = rgb(255,0,255);
world[OFF_2+18][23] = rgb(51,204,0);
world[OFF_2+18][24] = rgb(51,204,0);
world[OFF_2+18][25] = rgb(51,204,0);
world[OFF_2+19][0] = rgb(153,51,0);
world[OFF_2+19][1] = rgb(153,51,0);
world[OFF_2+19][2] = rgb(153,51,0);
world[OFF_2+19][3] = rgb(51,204,0);
world[OFF_2+19][4] = rgb(51,204,0);
world[OFF_2+19][5] = rgb(51,204,0);
world[OFF_2+19][6] = rgb(51,204,0);
world[OFF_2+19][7] = rgb(255,255,0);
world[OFF_2+19][8] = rgb(51,204,0);
world[OFF_2+19][9] = rgb(51,204,0);
world[OFF_2+19][10] = rgb(255,0,255);
world[OFF_2+19][11] = rgb(51,204,0);
world[OFF_2+19][12] = rgb(51,204,0);
world[OFF_2+19][13] = rgb(51,204,0);
world[OFF_2+19][14] = rgb(51,204,0);
world[OFF_2+19][15] = rgb(255,255,0);
world[OFF_2+19][16] = rgb(51,204,0);
world[OFF_2+19][17] = rgb(51,204,0);
world[OFF_2+19][18] = rgb(51,204,0);
world[OFF_2+19][19] = rgb(255,255,0);
world[OFF_2+19][20] = rgb(51,204,0);
world[OFF_2+19][21] = rgb(51,204,0);
world[OFF_2+19][22] = rgb(255,255,0);
world[OFF_2+19][23] = rgb(51,204,0);
world[OFF_2+20][2] = rgb(153,51,0);
world[OFF_2+20][3] = rgb(51,204,0);
world[OFF_2+20][4] = rgb(51,204,0);
world[OFF_2+20][5] = rgb(51,204,0);
world[OFF_2+20][6] = rgb(255,255,0);
world[OFF_2+20][7] = rgb(51,204,0);
world[OFF_2+20][8] = rgb(51,204,0);
world[OFF_2+20][9] = rgb(51,204,0);
world[OFF_2+20][10] = rgb(255,255,0);
world[OFF_2+20][11] = rgb(51,204,0);
world[OFF_2+20][12] = rgb(51,204,0);
world[OFF_2+20][13] = rgb(51,204,0);
world[OFF_2+20][14] = rgb(255,255,0);
world[OFF_2+20][15] = rgb(255,0,255);
world[OFF_2+20][16] = rgb(255,255,0);
world[OFF_2+20][17] = rgb(51,204,0);
world[OFF_2+20][18] = rgb(51,204,0);
world[OFF_2+20][19] = rgb(51,204,0);
world[OFF_2+20][20] = rgb(255,0,255);
world[OFF_2+20][21] = rgb(51,204,0);
world[OFF_2+21][3] = rgb(51,204,0);
world[OFF_2+21][4] = rgb(51,204,0);
world[OFF_2+21][5] = rgb(51,204,0);
world[OFF_2+21][6] = rgb(255,0,255);
world[OFF_2+21][7] = rgb(51,204,0);
world[OFF_2+21][8] = rgb(51,204,0);
world[OFF_2+21][9] = rgb(51,204,0);
world[OFF_2+21][10] = rgb(255,0,255);
world[OFF_2+21][11] = rgb(51,204,0);
world[OFF_2+21][12] = rgb(51,204,0);
world[OFF_2+21][13] = rgb(51,204,0);
world[OFF_2+21][14] = rgb(51,204,0);
world[OFF_2+21][15] = rgb(255,255,0);
world[OFF_2+21][16] = rgb(51,204,0);
world[OFF_2+21][17] = rgb(51,204,0);
world[OFF_2+21][18] = rgb(51,204,0);
world[OFF_2+21][19] = rgb(51,204,0);
world[OFF_2+22][3] = rgb(51,204,0);
world[OFF_2+22][4] = rgb(51,204,0);
world[OFF_2+22][5] = rgb(51,204,0);
world[OFF_2+22][6] = rgb(51,204,0);
world[OFF_2+22][7] = rgb(255,255,0);
world[OFF_2+22][8] = rgb(51,204,0);
world[OFF_2+22][9] = rgb(51,204,0);
world[OFF_2+22][10] = rgb(255,255,0);
world[OFF_2+22][11] = rgb(51,204,0);
world[OFF_2+22][12] = rgb(51,204,0);
world[OFF_2+22][13] = rgb(51,204,0);
world[OFF_2+22][14] = rgb(51,204,0);
world[OFF_2+22][15] = rgb(51,204,0);
world[OFF_2+22][16] = rgb(51,204,0);
world[OFF_2+22][17] = rgb(51,204,0);
world[OFF_2+23][3] = rgb(51,204,0);
world[OFF_2+23][4] = rgb(51,204,0);
world[OFF_2+23][5] = rgb(51,204,0);
world[OFF_2+23][6] = rgb(51,204,0);
world[OFF_2+23][7] = rgb(255,0,255);
world[OFF_2+23][8] = rgb(51,204,0);
world[OFF_2+23][9] = rgb(51,204,0);
world[OFF_2+23][10] = rgb(51,204,0);
world[OFF_2+23][11] = rgb(255,0,255);
world[OFF_2+23][12] = rgb(51,204,0);
world[OFF_2+23][13] = rgb(51,204,0);
world[OFF_2+23][14] = rgb(51,204,0);
world[OFF_2+23][15] = rgb(51,204,0);
world[OFF_2+24][3] = rgb(51,204,0);
world[OFF_2+24][4] = rgb(51,204,0);
world[OFF_2+24][5] = rgb(51,204,0);
world[OFF_2+24][6] = rgb(51,204,0);
world[OFF_2+24][7] = rgb(255,255,0);
world[OFF_2+24][8] = rgb(51,204,0);
world[OFF_2+24][9] = rgb(51,204,0);
world[OFF_2+24][10] = rgb(51,204,0);
world[OFF_2+24][11] = rgb(255,255,0);
world[OFF_2+24][12] = rgb(51,204,0);
world[OFF_2+24][13] = rgb(51,204,0);
world[OFF_2+25][3] = rgb(51,204,0);
world[OFF_2+25][4] = rgb(51,204,0);
world[OFF_2+25][5] = rgb(51,204,0);
world[OFF_2+25][6] = rgb(51,204,0);
world[OFF_2+25][7] = rgb(51,204,0);
world[OFF_2+25][8] = rgb(255,0,255);
world[OFF_2+25][9] = rgb(51,204,0);
world[OFF_2+25][10] = rgb(51,204,0);
world[OFF_2+25][11] = rgb(51,204,0);
world[OFF_2+26][3] = rgb(51,204,0);
world[OFF_2+26][4] = rgb(51,204,0);
world[OFF_2+26][5] = rgb(51,204,0);
world[OFF_2+26][6] = rgb(255,0,255);
world[OFF_2+26][7] = rgb(51,204,0);
world[OFF_2+26][8] = rgb(51,204,0);
world[OFF_2+26][9] = rgb(255,255,0);
world[OFF_2+27][3] = rgb(51,204,0);
world[OFF_2+27][4] = rgb(51,204,0);
world[OFF_2+27][5] = rgb(51,204,0);
world[OFF_2+27][6] = rgb(51,204,0);
world[OFF_2+27][7] = rgb(51,204,0);
world[OFF_2+28][4] = rgb(51,204,0);
world[OFF_2+28][5] = rgb(51,204,0);

  for (byte r = 0; r < DIM; r++)
  {
    for (byte c = 0;  c < DIM; c++)
    {
      // mask matrix
      copyWorld[r][c] = (world[r][c] == rgb(255, 0, 255));
    }
  }
  simulate();
}

void Xmas::simulate()
{
  for (byte r = 0; r < DIM; r++)
  {
    for (byte c = 0;  c < DIM; c++)
    {
      auto col = world[r][c];
      if (copyWorld[r][c] != 0) {
        switch (random(4)) {
          case 0:
            world[r][c] = rgb(255, 50, 0);
            break;

          case 1:
            world[r][c] = rgb(255, 255, 0);
            break;
            
          case 2:
            world[r][c] = rgb(255, 255, 255);
            break;

          case 3:
            world[r][c] = rgb(0, 0, 255);
            break;
        }
      }
    }
  }
}

unsigned long Xmas::getInterval()
{
  return 1000;
}

uint16_t Xmas::mapColor(byte x, byte y)
{
  return world[x][y];
}

bool Xmas::isOver() const
{
  return _rounds >= 200;
}

RGB eye library

Credits

Infineon Team

Infineon Team

90 projects • 135 followers

Comments