website statistics

blobsΒΆ

../../../_images/main2.png

(or download the high quality version: blobs.avi)

blobs is a sketching demonstration, as you paint on the touch screen a trail of circles follows.

The background is a repeated seamless texture ( thanks to Patrick Hoesly).

The code keeps a history of the last 128 touch positions, and draws the transparent, randomly colored circles.

#include <EEPROM.h>
#include <SPI.h>
#include <GD2.h>

#define NBLOBS      128
#define OFFSCREEN   -16384

struct xy {
  int x, y;
};

byte blob_i;
struct xy blobs[NBLOBS];

#include "blobs_assets.h"

void setup()
{
  GD.begin();

  LOAD_ASSETS();

  for (int i = 0; i < NBLOBS; i++) {
    blobs[i].x = OFFSCREEN;
    blobs[i].y = OFFSCREEN;
  }
}

void loop()
{
  GD.get_inputs();
  
  if (GD.inputs.x != -32768) {
    blobs[blob_i].x = GD.inputs.x << 4;
    blobs[blob_i].y = GD.inputs.y << 4;
  } else {
    blobs[blob_i].x = OFFSCREEN;
    blobs[blob_i].y = OFFSCREEN;
  }
  blob_i = (blob_i + 1) & (NBLOBS - 1);

  GD.ClearColorRGB(0xd0d0c0);
  GD.Clear();

  GD.Begin(BITMAPS);
  GD.BitmapSize(NEAREST, REPEAT, REPEAT, 480, 272);
  GD.Vertex2ii(0, 0);

  // Draw the blobs from oldest to youngest
  GD.Begin(POINTS);
  for (int i = 0; i < NBLOBS; i++) {

    // Blobs fade away and swell as they age
    GD.ColorA(i << 1);
    GD.PointSize((1024 + 16) - (i << 3));

    // Random color for each blob
    uint8_t j = (blob_i + i) & (NBLOBS - 1);
    byte r = j * 17;
    byte g = j * 23;
    byte b = j * 147;
    GD.ColorRGB(r, g, b);

    // Draw it!
    GD.Vertex2f(blobs[j].x, blobs[j].y);
  }
  GD.swap();
}