Nesso wandering DVD symbol

Random slopes every bounce (the real one had a set slope).

#include <Arduino_Nesso_N1.h>
NessoDisplay display;  // https://github.com/m5stack/M5GFX/blob/master/src/lgfx/v1/LGFXBase.hpp // drawing functions

// V2 - random slope every bounce

const unsigned char nesso[] = {  // 50x25px
  0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x80, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x80, 0x70, 0x07, 0xf8, 0x3f, 0xc0,
  0x40, 0x80, 0x70, 0x0f, 0xfc, 0x7f, 0xe0, 0x40, 0x80, 0x70, 0x1c, 0x0e, 0xe0, 0x70, 0x40, 0x80,
  0x70, 0x18, 0x06, 0xc6, 0x30, 0x40, 0x80, 0x70, 0x18, 0x07, 0xc6, 0x30, 0x40, 0x80, 0x70, 0x19,
  0xe7, 0xcf, 0x30, 0x40, 0x80, 0x70, 0x19, 0xe7, 0xcf, 0x30, 0x40, 0x80, 0x70, 0x19, 0xe7, 0xcf,
  0x30, 0x40, 0x80, 0x70, 0x18, 0x07, 0xc6, 0x30, 0x40, 0x80, 0x70, 0x18, 0x06, 0xc6, 0x30, 0x40,
  0x80, 0x70, 0x1c, 0x0e, 0xe0, 0x70, 0x40, 0x80, 0x70, 0x0f, 0xfc, 0x7f, 0xe0, 0x40, 0x80, 0x70,
  0x07, 0xf8, 0x3f, 0xc0, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x80, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x40, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00
};

#define BITMAP_WIDTH 50
#define BITMAP_HEIGHT 25
#define BITMAP_COLOR 0x0513  // https://rgbcolorpicker.com/565

int MAXX, MAXY, x, y, xMov, yMov;  // horizontal, vertical movement
int loSpeed = 2, hiSpeed = 4; // minimum and maximum slopes

void setup() {
  display.begin();
  display.setRotation(3);  // button left
  display.fillScreen(TFT_BLACK);

  MAXX = display.width() - BITMAP_WIDTH;    // size of usable screen width
  MAXY = display.height() - BITMAP_HEIGHT;  // size of usable screen height
  x = random(MAXX); // starting x
  y = random(MAXY); // starting y
  xMov = random(loSpeed, hiSpeed); // random slope run
  yMov = random(loSpeed, hiSpeed); // random slope rise
}

void loop() {
  dvd();
}

void dvd() {
  if (x <= 0) xMov = random(loSpeed, hiSpeed);
  if (x >= MAXX) xMov = -random(loSpeed, hiSpeed);
  if (y <= 0) yMov = random(loSpeed, hiSpeed);
  if (y >= MAXY) yMov = -random(loSpeed, hiSpeed);

  x += xMov;
  y += yMov;

  display.drawBitmap(x, y, nesso, BITMAP_WIDTH, BITMAP_HEIGHT, BITMAP_COLOR);
  delay(25);
  display.drawBitmap(x, y, nesso, BITMAP_WIDTH, BITMAP_HEIGHT, TFT_BLACK);
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.