blobs.ino 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include <EEPROM.h>
  2. #include <SPI.h>
  3. #include <GD2.h>
  4. #define NBLOBS 128 //' a{
  5. #define OFFSCREEN -16384
  6. struct xy {
  7. int x, y;
  8. } blobs[NBLOBS];
  9. void setup()
  10. {
  11. GD.begin();
  12. for (int i = 0; i < NBLOBS; i++) {
  13. blobs[i].x = OFFSCREEN;
  14. blobs[i].y = OFFSCREEN;
  15. }
  16. Serial.begin(1000000); // JCB
  17. } //' }a
  18. void loop() //' b{
  19. {
  20. static byte blob_i;
  21. GD.get_inputs();
  22. if (GD.inputs.x != -32768) {
  23. blobs[blob_i].x = GD.inputs.x << 4; //' xy{
  24. blobs[blob_i].y = GD.inputs.y << 4; //' }xy
  25. } else {
  26. blobs[blob_i].x = OFFSCREEN;
  27. blobs[blob_i].y = OFFSCREEN;
  28. }
  29. blob_i = (blob_i + 1) & (NBLOBS - 1);
  30. GD.ClearColorRGB(0xd0d0c0); // JCB
  31. GD.ClearColorRGB(0xe0e0e0);
  32. GD.Clear();
  33. GD.Begin(BITMAPS); // JCB
  34. GD.BitmapSize(NEAREST, REPEAT, REPEAT, 480, 272); // JCB
  35. GD.Vertex2ii(0, 0); // JCB
  36. // Draw the blobs from oldest to youngest // JCB
  37. GD.Begin(POINTS);
  38. for (int i = 0; i < NBLOBS; i++) {
  39. // Blobs fade away and swell as they age
  40. GD.ColorA(i << 1);
  41. GD.PointSize((1024 + 16) - (i << 3));
  42. // Random color for each blob, keyed from (blob_i + i)
  43. uint8_t j = (blob_i + i) & (NBLOBS - 1);
  44. byte r = j * 17;
  45. byte g = j * 23;
  46. byte b = j * 147;
  47. GD.ColorRGB(r, g, b);
  48. // Draw it!
  49. GD.Vertex2f(blobs[j].x, blobs[j].y);
  50. }
  51. GD.swap();
  52. } //' }b