GFXcanvas.ino (3671B)
1 /*** 2 This example is intended to demonstrate the use of getPixel() versus 3 getRawPixel() and the fast horizontal and vertical drawing routines 4 in the GFXcanvas family of classes, 5 6 When using the GFXcanvas* classes as the image buffer for a hardware driver, 7 there is a need to get individual pixel color values at given physical 8 coordinates. Rather than subclasses or client classes call getBuffer() and 9 reinterpret the byte layout of the buffer, two methods are added to each of the 10 GFXcanvas* classes that allow fetching of specific pixel values. 11 12 * getPixel(x, y) : Gets the pixel color value at the rotated coordinates in 13 the image. 14 * getRawPixel(x,y) : Gets the pixel color value at the unrotated coordinates 15 in the image. This is useful for getting the pixel value to map to a hardware 16 pixel location. This method was made protected as only the hardware driver 17 should be accessing it. 18 19 The GFXcanvas*SerialDemo classes in this example will print to Serial the 20 contents of the underlying GFXcanvas buffer in both the current rotated layout 21 and the underlying physical layout. 22 ***/ 23 24 #include "GFXcanvasSerialDemo.h" 25 #include <Arduino.h> 26 27 void setup() { 28 Serial.begin(115200); 29 30 // first create a rectangular GFXcanvas8SerialDemo object and draw to it 31 GFXcanvas8SerialDemo demo8(21, 11); 32 33 demo8.fillScreen(0x00); 34 demo8.setRotation(1); // now canvas is 11x21 35 demo8.fillCircle(5, 10, 5, 0xAA); 36 demo8.writeFastHLine(0, 0, 11, 0x11); 37 demo8.writeFastHLine(10, 10, -11, 0x22); 38 demo8.writeFastHLine(0, 20, 11, 0x33); 39 demo8.writeFastVLine(0, 0, 21, 0x44); 40 demo8.writeFastVLine(10, 20, -21, 0x55); 41 42 Serial.println("Demonstrating GFXcanvas rotated and raw pixels.\n"); 43 44 // print it out rotated 45 46 Serial.println("The canvas's content in the rotation of '0':\n"); 47 demo8.setRotation(0); 48 demo8.print(true); 49 Serial.println("\n"); 50 51 Serial.println("The canvas's content in the rotation of '1' (which is what " 52 "it was drawn in):\n"); 53 demo8.setRotation(1); 54 demo8.print(true); 55 Serial.println("\n"); 56 57 Serial.println("The canvas's content in the rotation of '2':\n"); 58 demo8.setRotation(2); 59 demo8.print(true); 60 Serial.println("\n"); 61 62 Serial.println("The canvas's content in the rotation of '3':\n"); 63 demo8.setRotation(3); 64 demo8.print(true); 65 Serial.println("\n"); 66 67 // print it out unrotated 68 Serial.println("The canvas's content in it's raw, physical layout:\n"); 69 demo8.print(false); 70 Serial.println("\n"); 71 72 // Demonstrate GFXcanvas1SerialDemo 73 74 GFXcanvas1SerialDemo demo1(21, 11); 75 demo1.fillScreen(0); 76 demo1.setRotation(0); 77 demo1.writeFastHLine(0, 0, 9, 1); 78 demo1.setRotation(1); 79 demo1.writeFastHLine(0, 0, 9, 1); 80 demo1.setRotation(2); 81 demo1.writeFastHLine(0, 0, 9, 1); 82 demo1.setRotation(3); 83 demo1.writeFastHLine(0, 0, 9, 1); 84 demo1.setRotation(1); 85 demo1.fillRect(3, 8, 5, 5, 1); 86 87 Serial.println("\nThe GFXcanvas1 raw content after drawing a fast horizontal " 88 "line in each rotation:\n"); 89 demo1.print(false); 90 Serial.println("\n"); 91 92 // Demonstrate GFXcanvas16SerialDemo 93 94 GFXcanvas16SerialDemo demo16(21, 11); 95 demo16.fillScreen(0); 96 demo16.setRotation(0); 97 demo16.writeFastHLine(0, 0, 9, 0x1111); 98 demo16.setRotation(1); 99 demo16.writeFastHLine(0, 0, 9, 0x2222); 100 demo16.setRotation(2); 101 demo16.writeFastHLine(0, 0, 9, 0x3333); 102 demo16.setRotation(3); 103 demo16.writeFastHLine(0, 0, 9, 0x4444); 104 demo16.setRotation(1); 105 demo16.fillRect(3, 8, 5, 5, 0x8888); 106 107 Serial.println("\nThe GFXcanvas16 raw content after drawing a fast " 108 "horizontal line in each rotation:\n"); 109 demo16.print(false); 110 Serial.println("\n"); 111 } 112 113 void loop() {}