// https://forum.arduino.cc/t/creating-a-fake-broken-screen-tool-with-arduino-esp32/1343365/

#include <Adafruit_SSD1306.h> // https://github.com/adafruit/Adafruit_SSD1306
#define WIDTH 128
#define HEIGHT 64
#define I2C_ADDRESS 0x3C
Adafruit_SSD1306 display(WIDTH, HEIGHT, &Wire, -1); // create OLED object

int startx, starty, vectx, vecty, newx, newy;

void setup() {
  randomSeed(analogRead(A0));

  Serial.begin(115200); // initialize serial communications

  display.begin(SSD1306_SWITCHCAPVCC, I2C_ADDRESS);
  display.clearDisplay();
  display.display();

  // starting point
  startx = random(WIDTH); starty = random(HEIGHT);
  display.drawPixel(x, y, 1);
  display.display();

  // vector to move the crack in the same direction
  vectx = random(-1, 2); // value -1 or 0 or 1
  vecty = random(-1, 2);
}

void loop() {

  getnewxy();

  display.drawPixel(x, y, 1);
  display.display();
}

void getnewxy() {
  switch(vectx) {
    case(-1): // move left
    case( 0): // center
    case( 1): // move right
  }

  switch(vecty) {
    case(-1): newy += random(-1, 2);
    case( 0): newx += random(-1, 2);
    case( 1): 
  }

  newx = random(-1, 2);
  newy = random(-1, 2);
  x += newx;
  y += newy;
}