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.

mandelbrot.ino 1.6KB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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_RESET 9//any pin or nothing!
  12. #if defined(NEEDS_SET_MODULE)//Energia, this case is for stellaris/tiva
  13. RA8875 tft = RA8875(3);//select SPI module 3
  14. /*
  15. for module 3 (stellaris)
  16. SCLK: PD_0
  17. MOSI: PD_3
  18. MISO: PD_2
  19. SS: PD_1
  20. */
  21. #endif
  22. const int MAX = 256;
  23. float cx, cy;
  24. float zoom = 1.0f;
  25. void setup()
  26. {
  27. Serial.begin(9600);
  28. //while (!Serial) {;}
  29. Serial.println("RA8875 start");
  30. tft.begin(RA8875_800x480);
  31. cx = -0.086f;
  32. cy = 0.85f;
  33. }
  34. void loop()
  35. {
  36. mandelbrot(-2.0f * zoom + cx, -1.5f * zoom + cy, 2.0f * zoom + cx, 1.5f * zoom + cy);
  37. zoom *= 0.7f;
  38. if (zoom <= 0.00001f)
  39. zoom = 1.0f;
  40. }
  41. void mandelbrot(float x1, float y1, float x2, float y2) {
  42. unsigned int i, j;
  43. uint16_t iter;
  44. uint16_t color;
  45. float sy = y2 - y1;
  46. float sx = x2 - x1;
  47. for (i = 0; i < tft.width(); i++) {
  48. for (j = 0; j < tft.height(); j++) {
  49. float cy = j * sy / tft.height() + y1;
  50. float cx = i * sx / tft.width() + x1;
  51. float x = 0.0f, y = 0.0f, xx = 0.0f, yy = 0.0f;
  52. for (iter = 0; iter <= MAX && (xx + yy) < 4.0f; iter++) {
  53. xx = x * x;
  54. yy = y * y;
  55. y = 2.0f * x * y + cy;
  56. x = xx - yy + cx;
  57. }
  58. color = ((iter << 7 & 0xF8) << 8) | ((iter << 4 & 0xFC) << 3) | (iter >> 3);
  59. tft.drawPixel(i, j, color);
  60. }
  61. }
  62. }