
Sierpinski triangle fractal - only modified algo for 4DGL - original code Eric Wieser - THANKS
main.cpp@0:66e8e6fa8997, 2011-01-23 (annotated)
- Committer:
- JLS
- Date:
- Sun Jan 23 17:32:41 2011 +0000
- Revision:
- 0:66e8e6fa8997
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JLS | 0:66e8e6fa8997 | 1 | #include "TFT_4DGL.h" |
JLS | 0:66e8e6fa8997 | 2 | |
JLS | 0:66e8e6fa8997 | 3 | TFT_4DGL lcd(p9,p10,p11); |
JLS | 0:66e8e6fa8997 | 4 | |
JLS | 0:66e8e6fa8997 | 5 | #define PI 3.14159265 |
JLS | 0:66e8e6fa8997 | 6 | |
JLS | 0:66e8e6fa8997 | 7 | struct point |
JLS | 0:66e8e6fa8997 | 8 | { |
JLS | 0:66e8e6fa8997 | 9 | int x; |
JLS | 0:66e8e6fa8997 | 10 | int y; |
JLS | 0:66e8e6fa8997 | 11 | }; |
JLS | 0:66e8e6fa8997 | 12 | |
JLS | 0:66e8e6fa8997 | 13 | point points[3]; |
JLS | 0:66e8e6fa8997 | 14 | point current; |
JLS | 0:66e8e6fa8997 | 15 | |
JLS | 0:66e8e6fa8997 | 16 | int main() { |
JLS | 0:66e8e6fa8997 | 17 | |
JLS | 0:66e8e6fa8997 | 18 | int n = WHITE; |
JLS | 0:66e8e6fa8997 | 19 | |
JLS | 0:66e8e6fa8997 | 20 | for(int i=0; i<3; i++) |
JLS | 0:66e8e6fa8997 | 21 | { |
JLS | 0:66e8e6fa8997 | 22 | points[i].x = 150*sin(2*PI*i/3); |
JLS | 0:66e8e6fa8997 | 23 | points[i].y = 150*cos(2*PI*i/3); |
JLS | 0:66e8e6fa8997 | 24 | } |
JLS | 0:66e8e6fa8997 | 25 | |
JLS | 0:66e8e6fa8997 | 26 | current = points[rand()%3]; |
JLS | 0:66e8e6fa8997 | 27 | |
JLS | 0:66e8e6fa8997 | 28 | while(1) |
JLS | 0:66e8e6fa8997 | 29 | { |
JLS | 0:66e8e6fa8997 | 30 | |
JLS | 0:66e8e6fa8997 | 31 | lcd.pixel(80+current.y,160+current.x,n); |
JLS | 0:66e8e6fa8997 | 32 | |
JLS | 0:66e8e6fa8997 | 33 | point nextpoint = points[rand()%3]; |
JLS | 0:66e8e6fa8997 | 34 | |
JLS | 0:66e8e6fa8997 | 35 | current.x = (current.x + nextpoint.x)/2; |
JLS | 0:66e8e6fa8997 | 36 | current.y = (current.y + nextpoint.y)/2; |
JLS | 0:66e8e6fa8997 | 37 | } |
JLS | 0:66e8e6fa8997 | 38 | } |