GFXcanvas.ino 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /***
  2. This example is intended to demonstrate the use of getPixel() versus
  3. getRawPixel() in the GFXcanvas family of classes.
  4. When using the GFXcanvas* classes as the image buffer for a hardware driver,
  5. there is a need to get individual pixel color values at given physical
  6. coordinates. Rather than subclasses or client classes call getBuffer() and
  7. reinterpret the byte layout of the buffer, two methods are added to each of the
  8. GFXcanvas* classes that allow fetching of specific pixel values.
  9. * getPixel(x, y) : Gets the pixel color value at the rotated coordinates in
  10. the image.
  11. * getRawPixel(x,y) : Gets the pixel color value at the unrotated coordinates
  12. in the image. This is useful for getting the pixel value to map to a hardware
  13. pixel location. This method was made protected as only the hardware driver
  14. should be accessing it.
  15. The GFXcanvasSerialDemo class in this example will print to Serial the contents
  16. of the underlying GFXcanvas buffer in both the current rotated layout and the
  17. underlying physical layout.
  18. ***/
  19. #include "GFXcanvasSerialDemo.h"
  20. #include <Arduino.h>
  21. void setup() {
  22. Serial.begin(115200);
  23. // first create a rectangular GFXcanvasSerialDemo object and draw to it
  24. GFXcanvasSerialDemo demo(21, 11);
  25. demo.fillScreen(0x00);
  26. demo.setRotation(1); // now canvas is 11x21
  27. demo.fillCircle(5, 10, 5, 0xAA);
  28. demo.writeLine(0, 0, 10, 0, 0x11);
  29. demo.writeLine(0, 10, 10, 10, 0x22);
  30. demo.writeLine(0, 20, 10, 20, 0x33);
  31. demo.writeLine(0, 0, 0, 20, 0x44);
  32. demo.writeLine(10, 0, 10, 20, 0x55);
  33. Serial.println("Demonstrating GFXcanvas rotated and raw pixels.\n");
  34. // print it out rotated
  35. Serial.println("The canvas's content in the rotation of '0':\n");
  36. demo.setRotation(0);
  37. demo.print(true);
  38. Serial.println("\n");
  39. Serial.println("The canvas's content in the rotation of '1' (which is what "
  40. "it was drawn in):\n");
  41. demo.setRotation(1);
  42. demo.print(true);
  43. Serial.println("\n");
  44. Serial.println("The canvas's content in the rotation of '2':\n");
  45. demo.setRotation(2);
  46. demo.print(true);
  47. Serial.println("\n");
  48. Serial.println("The canvas's content in the rotation of '3':\n");
  49. demo.setRotation(3);
  50. demo.print(true);
  51. Serial.println("\n");
  52. // print it out unrotated
  53. Serial.println("The canvas's content in it's raw, physical layout:\n");
  54. demo.print(false);
  55. Serial.println("\n");
  56. }
  57. void loop() {}