PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

mandelbrot.ino 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. tft.begin(RA8875_800x480);
  23. cx = -0.086f;
  24. cy = 0.85f;
  25. }
  26. void loop()
  27. {
  28. mandelbrot(-2.0f * zoom + cx, -1.5f * zoom + cy, 2.0f * zoom + cx, 1.5f * zoom + cy);
  29. zoom *= 0.7f;
  30. if (zoom <= 0.00001f)
  31. zoom = 1.0f;
  32. }
  33. void mandelbrot(float x1, float y1, float x2, float y2) {
  34. unsigned int i, j;
  35. uint16_t iter;
  36. uint16_t color;
  37. float sy = y2 - y1;
  38. float sx = x2 - x1;
  39. for (i = 0; i < tft.width(); i++) {
  40. for (j = 0; j < tft.height(); j++) {
  41. float cy = j * sy / tft.height() + y1;
  42. float cx = i * sx / tft.width() + x1;
  43. float x = 0.0f, y = 0.0f, xx = 0.0f, yy = 0.0f;
  44. for (iter = 0; iter <= MAX && (xx + yy) < 4.0f; iter++) {
  45. xx = x * x;
  46. yy = y * y;
  47. y = 2.0f * x * y + cy;
  48. x = xx - yy + cx;
  49. }
  50. color = ((iter << 7 & 0xF8) << 8) | ((iter << 4 & 0xFC) << 3) | (iter >> 3);
  51. tft.drawPixel(i, j, color);
  52. }
  53. }
  54. }