Debian Codegraph @

texmf-dist/source/latex/avremu/test-suite/mandelbrot.c

raw
1 /** mandel.c by Eric R. Weeks written 9-28-96
2 ** [email protected]
3 ** http://www.physics.emory.edu/~weeks/
4 **
5 ** This program is public domain, but this header must be left intact
6 ** and unchanged.
7 **
8 **/
9
10 #include <avr/io.h>
11
12 #define CMD_COLOR 1
13 #define CMD_DOT 2
14
15
16
17 static
18 void setcolor(uint8_t r, uint8_t g, uint8_t b) {
19 TWDR = r;
20 TWDR = g;
21 TWDR = b;
22 TWAR = CMD_COLOR;
23 }
24
25 static
26 void dot(uint8_t x, uint8_t y) {
27 TWDR = x, TWDR = y;
28 TWAR = CMD_DOT;
29 }
30
31
32 /* Colors
33 import colorsys
34 def color(i):
35 h = i/float(100)
36 s = 1.0
37 v = h
38 print h, s, v
39 x = colorsys.hsv_to_rgb(h, s, v)
40 return (str(int(x[0] * 255)),
41 str(int(x[1] * 255)),
42 str(int(x[2] * 255)))
43
44 colors = [color (i) for i in range(0, 100)]
45
46 print "char color_R[] = {%s};" % (",".join([x[0] for x in colors]))
47 print "char color_G[] = {%s};" % (",".join([x[1] for x in colors]))
48 print "char color_B[] = {%s};" % (",".join([x[2] for x in colors]))
49 */
50
51 char color_R[] = {0,2,5,7,10,12,15,17,20,22,25,28,30,33,35,38,40,42,42,41,40,39,38,36,34,31,29,26,22,19,15,11,6,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,13,24,35,47,58,70,83,95,108,121,135,149,163,177,192,207,214,216,219,221,224,226,229,232,234,237,239,242,244,247,249,252};
52 char color_G[] = {0,0,0,1,2,3,5,7,9,12,15,18,22,25,29,34,39,43,45,48,51,53,56,58,61,63,66,68,71,73,76,79,81,84,86,89,91,94,96,99,102,104,107,109,112,114,117,119,122,124,127,122,116,110,104,98,91,84,76,69,61,52,44,35,26,16,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
53 char color_B[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,8,14,20,27,33,40,48,55,63,71,80,89,98,107,117,127,130,132,135,137,140,142,145,147,150,153,155,158,160,163,165,168,170,173,175,178,181,183,186,188,191,193,196,198,201,204,206,209,211,205,195,184,173,161,149,137,125,112,99,86,72,58,44,29,15};
54
55
56 int main() {
57
58 float x,xx,y,cx,cy;
59 uint8_t iteration;
60 uint8_t hx,hy;
61 #define itermax 100 /* how many iterations to do */
62 #define magnify 4.0 /* no magnification */
63 #define hxres 250 /* horizonal resolution */
64 #define hyres 250 /* vertical resolution */
65 #define ydelta 0
66 #define xdelta -0.75
67
68 uint8_t i;
69 for (hy=1;hy<=hyres;hy++) {
70 for (hx=1;hx<=hxres;hx++) {
71 cx = (((float)hx)/((float)hxres)-0.5)/magnify*3.0-0.7;
72 cy = (((float)hy)/((float)hyres)-0.5)/magnify*3.0;
73 cx += xdelta;
74 cy += ydelta;
75 x = 0.0; y = 0.0;
76 for (iteration=1; iteration < itermax; iteration++) {
77 xx = x*x-y*y+cx;
78 y = 2.0*x*y+cy;
79 x = xx;
80 if (x*x+y*y>128.0){
81 i = iteration;
82 iteration = itermax + 1;
83 }
84 }
85 // Print a dot
86 if (iteration<itermax+1) {
87 setcolor(0,0,0);
88 } else {
89 setcolor(color_R[i],
90 color_G[i],
91 color_B[i]);
92 }
93 dot(hx-1, hy-1);
94 }
95 }
96
97 asm volatile ("break");
98 }
99
100 /*
101 check-name: Mandelbrot Set
102 compiler-opts: -O3
103 check-long: 1
104 check-start:
105 \def\avr@debug#1{}
106
107 \avr@instr@run
108
109 \avrdrawppm{mandelbrot.ppm}
110
111 \immediate\write18{convert mandelbrot.ppm mandelbrot.png}
112
113 \includegraphics[width=\linewidth]{mandelbrot.png}
114
115 check-end:
116 */