blobs.ino 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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.ColorRGB(0xa0a0a0);
  34. GD.cmd_text(240, 136, 31, OPT_CENTER, "touch to draw");
  35. // GD.Begin(BITMAPS); // JCB
  36. // GD.BitmapSize(NEAREST, REPEAT, REPEAT, 480, 272); // JCB
  37. // GD.Vertex2ii(0, 0); // JCB
  38. // Draw the blobs from oldest to youngest // JCB
  39. GD.Begin(POINTS);
  40. for (int i = 0; i < NBLOBS; i++) {
  41. // Blobs fade away and swell as they age
  42. GD.ColorA(i << 1);
  43. GD.PointSize((1024 + 16) - (i << 3));
  44. // Random color for each blob, keyed from (blob_i + i)
  45. uint8_t j = (blob_i + i) & (NBLOBS - 1);
  46. byte r = j * 17;
  47. byte g = j * 23;
  48. byte b = j * 147;
  49. GD.ColorRGB(r, g, b);
  50. // Draw it!
  51. GD.Vertex2f(blobs[j].x, blobs[j].y);
  52. }
  53. GD.swap();
  54. } //' }b