-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmandelwatch.ino
72 lines (61 loc) · 1.58 KB
/
mandelwatch.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "config.h"
TTGOClass *ttgo;
#define TFT_W 240
#define TFT_H 240
void setup()
{
// Setup the LCD
ttgo = TTGOClass::getWatch();
ttgo->begin();
ttgo->openBL();
ttgo->tft->setTextFont(1);
}
int changed;
double scale = 1./128;
double cx = -.6, cy = 0;
void mandel(int skip) {
int width = TFT_W;
int height = TFT_H;
int iter, max_iter = 256;
double x, y, zx, zy, zx2, zy2;
for (int i = 0; i < height; i += skip) {
y = (i - height/2) * scale + cy;
for (int j = 0; j < width; j += skip) {
x = (j - width/2) * scale + cx;
zx = hypot(x - (double).25, y);
if (x < zx - 2 * zx * zx + (double).25) continue;
if ((x + 1)*(x + 1) + y * y < 1/16) continue;
zx = zy = zx2 = zy2 = 0;
for (iter = 0; iter < max_iter && zx2 + zy2 < 4; iter++) {
zy = 2 * zx * zy + y;
zx = zx2 - zy2 + x;
zx2 = zx * zx;
zy2 = zy * zy;
}
if (iter < max_iter) {
ttgo->tft->fillRect(j,i,skip,skip,iter*10);
if (skip < 2) { int16_t tx, ty;
if (ttgo->getTouch(tx,ty)) break;
}
}
}
}
}
void loop()
{
static int resolution=5;
if (resolution) mandel(resolution--);
int16_t x, y;
if (ttgo->getTouch(x, y)) {
if (x > TFT_W - 60) cx +=0.1;
if (x < 60) cx -=0.1;
if (y < 60) cy -=0.1;
if (y > TFT_H-60) {
if (x < 60) scale *= 1.1;
if (x > TFT_W-60) scale /= 1.1;
if ( abs(x-120) < 60) cy +=0.1;
}
resolution = 5;
ttgo->tft->fillScreen(TFT_BLACK);
}
}