PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

drawingTests.ino 4.1KB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. how fast is the RA8875? here's.
  3. */
  4. #include <SPI.h>
  5. #include <RA8875.h>
  6. #define RA8875_CS 10 //any digital pin
  7. #define RA8875_RESET 9//any pin or nothing!
  8. RA8875 tft = RA8875(RA8875_CS,RA8875_RESET);
  9. void setup()
  10. {
  11. // begin display: Choose from: RA8875_480x272, RA8875_800x480, RA8875_800x480ALT, Adafruit_480x272, Adafruit_800x480
  12. tft.begin(RA8875_800x480);
  13. }
  14. void loop() {
  15. testdrawrects();
  16. testtriangles(false);
  17. testtriangles(true);
  18. randomRect(false);
  19. randomRect(true);
  20. randomCircles(false);
  21. randomCircles(true);
  22. randomLines();
  23. randomPoints();
  24. }
  25. void testdrawrects() {
  26. tft.fillWindow();
  27. for (int k = 0; k < 64; k++) {
  28. for (uint16_t x = 1; x < tft.height(); x += 6) {
  29. uint16_t c1 = random(0x00FF, 0xFFFF);
  30. tft.drawRect((uint16_t)((tft.width() / 2) - (x / 2)), (uint16_t)((tft.height() / 2) - (x / 2)), x, x, c1);
  31. }
  32. }
  33. }
  34. void randomCircles(bool fill) {
  35. tft.fillWindow();
  36. uint8_t k, c;
  37. for (k = 0; k < 32; k++) {
  38. for (c = 0; c < 32; c++) {
  39. // coordinates
  40. uint16_t x = random(0, tft.width() - 1);
  41. uint16_t y = random(0, tft.height() - 1);
  42. uint16_t r = random(1, tft.height() / 2);
  43. if (x - r < 0) r = x;
  44. if (x + r > (tft.width() - 1)) r = (tft.width() - 1) - x;
  45. if (y - r < 0) r = y;
  46. if (y + r > (tft.height() - 1)) r = (tft.height() - 1) - y;
  47. if (fill) {
  48. tft.fillCircle(x, y, r, random(0x0010, 0xFFFF));
  49. }
  50. else {
  51. tft.drawCircle(x, y, r, random(0x00FF, 0xFFFF));
  52. }
  53. }
  54. if (!fill) tft.fillWindow();
  55. }
  56. }
  57. void randomRect(bool fill) {
  58. tft.fillWindow();
  59. uint16_t k, c;
  60. for (k = 0; k < 128; k++) {
  61. for (c = 0; c < 32; c++) {
  62. uint16_t cx, cy, x, y, w, h;
  63. // center
  64. cx = random(0, tft.width() - 1);
  65. cy = random(0, tft.height() - 1);
  66. // size
  67. w = random(1, tft.width() / 3);
  68. h = random(1, tft.height() / 3);
  69. // upper-left
  70. x = cx - w / 2;
  71. y = cy - h / 2;
  72. if (x < 0) x = 0;
  73. if (y < 0) y = 0;
  74. // adjust size
  75. if (x + w >= tft.width()) w = tft.width() - 1 - x;
  76. if (y + h >= tft.height()) h = tft.height() - 1 - y;
  77. if (fill) {
  78. tft.fillRect(x, y, w, h, random(0x0010, 0xFFFF));
  79. }
  80. else {
  81. tft.drawRect(x, y, w, h, random(0x0010, 0xFFFF));
  82. }
  83. }
  84. tft.fillWindow();
  85. }
  86. }
  87. void randomLines() {
  88. tft.fillWindow();
  89. uint16_t k, c;
  90. for (k = 0; k < tft.height(); k++) {
  91. for (c = 0; c < 32; c++) {
  92. uint16_t x1 = random(0, tft.width() - 2);
  93. uint16_t y1 = random(0, tft.height() - 2);
  94. uint16_t x2 = random(0, tft.width() - 1);
  95. uint16_t y2 = random(0, tft.height() - 1);
  96. tft.drawLine(x1, y1, x2, y2, random(0x0010, 0xFFFF));
  97. }
  98. tft.fillWindow();
  99. }
  100. }
  101. void randomPoints() {
  102. tft.fillWindow();
  103. uint16_t k, c;
  104. for (k = 0; k < 62; k++) {
  105. for (c = 0; c < 1000; c++) {
  106. uint16_t x = random(0, tft.width() - 1);
  107. uint16_t y = random(0, tft.height() - 1);
  108. tft.drawPixel(x, y, random(0x0010, 0xFFFF));
  109. }
  110. tft.fillWindow();
  111. }
  112. }
  113. void testtriangles(bool fill) {
  114. tft.fillWindow();
  115. uint16_t p1x, p1y, p2x, p2y, p3x, p3y;
  116. uint16_t colour;
  117. for (uint16_t k = 0; k < 128; k++) {
  118. for (uint16_t t = 0 ; t <= 30; t += 1) {
  119. p1x = random(0, tft.width() - 1); //get a random number 0-319
  120. p1y = random(0, tft.height() - 1); //get a random number 0-239
  121. p2x = random(0, tft.width() - 1); //get a random number 0-319
  122. p2y = random(0, tft.height() - 1); //get a random number 0-239
  123. p3x = random(0, tft.width() - 1); //get a random number 0-319
  124. p3y = random(0, tft.height() - 1); //get a random number 0-239
  125. colour = random(0, 65536); //get a random number 0-65535
  126. //draw the triangle
  127. if (fill) {
  128. tft.fillTriangle(p1x, p1y, p2x, p2y, p3x, p3y, colour);
  129. }
  130. else {
  131. tft.drawTriangle(p1x, p1y, p2x, p2y, p3x, p3y, colour);
  132. }
  133. }
  134. tft.clearScreen();
  135. }
  136. }
  137. uint16_t halveColor(uint16_t rgb) {
  138. return (((rgb & 0b1111100000000000) >> 12) << 11 | ((rgb & 0b0000011111100000) >> 6) << 5 | ((rgb & 0b0000000000011111) >> 1));
  139. }