PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

71 lines
1.6KB

  1. /*
  2. Another example adapted from ugfx http://ugfx.org
  3. This actually shows a problem of RA8875 library, writing
  4. one pixel it's fast but write many single pixels in the same time
  5. not and speed suffer.
  6. It shoul be a workaround that I'm actually study, this will fix
  7. also loading big images from SD memory card and so on.
  8. */
  9. #include <SPI.h>
  10. #include <RA8875.h>
  11. #define RA8875_CS 10
  12. #define RA8875_RESET 9//any pin or nothing!
  13. RA8875 tft = RA8875(RA8875_CS, RA8875_RESET);
  14. const int MAX = 256;
  15. float cx, cy;
  16. float zoom = 1.0f;
  17. void setup()
  18. {
  19. Serial.begin(9600);
  20. //while (!Serial) {;}
  21. Serial.println("RA8875 start");
  22. // begin display: Choose from: RA8875_480x272, RA8875_800x480, RA8875_800x480ALT, Adafruit_480x272, Adafruit_800x480
  23. tft.begin(RA8875_800x480);
  24. cx = -0.086f;
  25. cy = 0.85f;
  26. }
  27. void loop()
  28. {
  29. mandelbrot(-2.0f * zoom + cx, -1.5f * zoom + cy, 2.0f * zoom + cx, 1.5f * zoom + cy);
  30. zoom *= 0.7f;
  31. if (zoom <= 0.00001f)
  32. zoom = 1.0f;
  33. }
  34. void mandelbrot(float x1, float y1, float x2, float y2) {
  35. unsigned int i, j;
  36. uint16_t iter;
  37. uint16_t color;
  38. float sy = y2 - y1;
  39. float sx = x2 - x1;
  40. for (i = 0; i < tft.width(); i++) {
  41. for (j = 0; j < tft.height(); j++) {
  42. float cy = j * sy / tft.height() + y1;
  43. float cx = i * sx / tft.width() + x1;
  44. float x = 0.0f, y = 0.0f, xx = 0.0f, yy = 0.0f;
  45. for (iter = 0; iter <= MAX && (xx + yy) < 4.0f; iter++) {
  46. xx = x * x;
  47. yy = y * y;
  48. y = 2.0f * x * y + cy;
  49. x = xx - yy + cx;
  50. }
  51. color = ((iter << 7 & 0xF8) << 8) | ((iter << 4 & 0xFC) << 3) | (iter >> 3);
  52. tft.drawPixel(i, j, color);
  53. }
  54. }
  55. }