-
Notifications
You must be signed in to change notification settings - Fork 0
/
mandelbrot.html
209 lines (190 loc) · 4.27 KB
/
mandelbrot.html
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<html>
<head><title>Mandelbrot</title>
<script language="javascript">
var svg_array=[];
function redraw()
{
document.getElementById("svg0").innerHTML=svg_array;
}
/* round a number (x) to the (10^y)th place */
function rn( x, y )
{
return Math.round(x*(10**y))/(10**y);
}
function convertX(X)
{
return Math.round(100*(Number(125)*Number(X)+Number(252)))/100;
}
function convertY(Y)
{
return Math.round(100*(Number(-125)*Number(Y)+Number(252)))/100;
}
/* helper function */
function addObjectAndRedraw(text)
{
addObject(text);
redraw();
}
function addObject(text)
{
svg_array.pop(); /* pop off the </svg> tag */
svg_array.push( text );
svg_array.push("</svg>"); /* push it back on */
}
function addPoint( x, y, c )
{
var color_string="#";
switch( c )
{
case 0:
return;
case 1:
color_string+="00000F";
break;
case 2:
color_string+="0000FF";
break;
case 3:
color_string+="000F0F";
break;
case 4:
color_string+="000FFF";
break;
case 5:
color_string+="00F00F";
break;
case 6:
color_string+="00F0FF";
break;
case 7:
color_string+="00FF0F";
break;
case 8:
color_string+="00FFFF";
break;
case 8:
color_string+="0F000F";
break;
case 9:
color_string+="0F00FF";
break;
case 10:
color_string+="0F0F0F";
break;
case 11:
color_string+="0F0FFF";
break;
case 12:
color_string+="0FF00F";
break;
case 13:
color_string+="0FF0FF";
break;
case 14:
color_string+="0FFF0F";
break;
case 15:
color_string+="0FFFFF";
break;
case 16:
color_string+="F00000";
break;
case 17:
color_string+="F0000F";
break;
case 18:
color_string+="F000FF";
break;
case 19:
color_string+="F00F0F";
break;
case 20:
color_string+="F00FFF";
break;
case 21:
color_string+="F0F00F";
break;
case 22:
color_string+="F0F0FF";
break;
case 23:
color_string+="F0FF0F";
break;
case 24:
color_string+="F0FFFF";
break;
case 25:
color_string+="FF000F";
break;
case 26:
color_string+="FF00FF";
break;
case 27:
color_string+="FF0F0F";
break;
case 28:
color_string+="FF0FFF";
break;
case 29:
color_string+="FFF00F";
break;
case 30:
color_string+="FFF0FF";
break;
case 31:
color_string+="FFFF0F";
break;
case 32:
color_string+="FFFFFF";
break;
default:
color_string+="000000";
break;
}
addObject( "<circle stroke-width='0' fill='" + color_string + "' stroke='" + color_string + "' cx='" + convertX(x) + "' cy='" + convertY(y) + "' r='1'/>" );
}
function onload()
{
svg_array.push("<svg id='svg0' width='504' height='504'>");
svg_array.push("</svg>");
mandelbrot();
redraw();
}
function dot(r, c)
{
/* save the original values of the real and imaginary portion of the # */
var r0=r;
var c0=c;
/* (R + Ci)( R + Ci ) */
/* R^2 + 2RCi - C^2 */
for( var k = 0; k<32; k++ )
{
var r1=r*r-c*c + r0;
var c1=2*r*c + c0;
r=r1;
c=c1;
if( Math.sqrt((r-r0)*(r-r0)+(c-c0)*(c-c0)) > 40 ) return k;
}
/* if the distance between the original point and the new one is too great */
/* then _NO_DOT_!!! (return 0) -- otherwise return 1 for (yes_dot) */
if( Math.sqrt((r-r0)*(r-r0)+(c-c0)*(c-c0)) > 0 ) return 1;
return 0;
}
function mandelbrot()
{
for( var i=-2; i<=2; i=i+0.01 )
{
for( var j=2; j>=-2; j=j-0.01 )
{
addPoint( i, j, dot(i,j));
}
}
redraw();
}
</script>
</head>
<body onload="onload();">
<title>Julia Set - (C)2022 - Michael K. Pellegrino</title>
<p id="svg0"></p>
</body>
</html>