-
Notifications
You must be signed in to change notification settings - Fork 12
/
mandelbrot.zeek
109 lines (88 loc) · 2.59 KB
/
mandelbrot.zeek
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
const stdout = open("/dev/stdout") &raw_output;
const WIDTH = 80;
const HEIGHT = 25;
#const output_chars = vector(" ", "\x25\x91");
#const characters = vector(" ", ".", ":", "-", "#", "o", "*", ">");#, ")", #, "|", "&", "I", "H", "%", "*", "#");
const characters = " .:-#o*>";
function CalculateRow(y: double, factor: double, shiftRight: double)
{
local output: vector of string = vector();
local XCenter = -0.45;
local XStep = 0.3;
local MaxIterations = 50;
local xLines = WIDTH - 2;
local xMin = XCenter - xLines / 2.0 * XStep;
local xMax = XCenter + xLines / 2.0 * XStep;
local xCoords: vector of double = vector();
local xtmp = xMin * factor + shiftRight;
while ( xtmp <= xMax * factor + shiftRight )
{
xCoords += xtmp;
xtmp += XStep * factor;
}
local i = 0;
while ( ++i < |xCoords| )
{
local x = xCoords[i];
local iterations = 0;
local xTemp = x;
local yTemp = y;
local arg = x*x + y*y;
while ( arg < |characters| && iterations < |characters| * MaxIterations )
{
local xSqr = xTemp * xTemp;
local ySqr = yTemp * yTemp;
yTemp = 2 * xTemp * yTemp - y;
xTemp = xSqr - ySqr - x;
arg = xSqr + ySqr;
++iterations;
}
# Build up the full row
#output += characters[iterations % |characters|];
print stdout, characters[iterations % |characters|];
}
print stdout, "\n";
#return join_string_vec(output, "");
}
function draw_fractal()
{
local StopfactorZoom = 0.00000000000005;
local StopfactorShr = 0.7496494959997;
local StopfactorShu = 0.03000094443895;
local ZoomSpeed = 0.95;
local YCenter = 0.95;
local YStep = 0.5;
local zoomFactor = 0.9;
local yLines = HEIGHT;
local yMin = YCenter - (yLines / 2.0) * YStep;
local yMax = YCenter + (yLines / 2.0) * YStep;
while (zoomFactor > StopfactorZoom)
{
local shiftRight = zoomFactor > StopfactorShr ? zoomFactor / ZoomSpeed : StopfactorShr;
local shiftUp = zoomFactor > StopfactorShu ? zoomFactor / ZoomSpeed : StopfactorShu;
local yCoords: vector of double = vector();
local y = yMax * zoomFactor - shiftUp;
while ( y >= yMin * zoomFactor - shiftUp )
{
yCoords += y;
y -= YStep * zoomFactor;
}
local i = 0;
local tempFactor = zoomFactor;
while ( ++i < |yCoords| )
{
#print CalculateRow(yCoords[i], tempFactor, shiftRight);
CalculateRow(yCoords[i], tempFactor, shiftRight);
}
zoomFactor = zoomFactor * ZoomSpeed;
# Reset the cursor to the zero position but don't clear
# the screen. Clearing the screen gives a tearing effect.
print stdout, "\n\x1b[0;0H";
}
}
event zeek_init()
{
# Clear the screen.
print stdout, "\x1bc";
draw_fractal();
}