-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmandel.tiny
99 lines (75 loc) · 2.41 KB
/
mandel.tiny
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
##############################################################
#
# Tiny script to draw the Mandelbrot set on the console.
# Translated from the PowerShell original.
#
##############################################################
import 'console'
screenY = 20.0
screenX = 50.0
minReal = -2.0
maxReal = 1.0
minImaginary = -1.2
MaxImaginary = 1.2
realFactor = ( maxReal - minReal ) / ( screenX - 1.0 )
imaginaryFactor = ( MaxImaginary - minImaginary ) / ( screenY - 1.0 )
cImaginary = 0.0
cReal = 0.0
zReal = 0.0
zImaginary = 0.0
zRealSq = 0.0
zImaginarySq = 0.0
interCount = 0
xOrd = 0
yOrd = 0
bailout = 16
color_map = [
"Blue", "DarkBlue", "Green", "DarkGreen", "Cyan",
"DarkCyan", "Yellow", "DarkYellow", "Gray", "DarkGray",
"Magenta", "DarkMagenta", "Red", "DarkRed", "White"
]
lastcolor = ""
color = color_map[0]
oldBackgroundColor = console.GetBackgroundColor()
oldForegroundColor = console.GetForegroundColor()
try {
# Console.SetWindowSize( screenX, screenY + 2 )
Console.SetBackgroundColor('Black')
Console.Clear()
while (yOrd < screenY/2) {
cImaginary = MaxImaginary - yOrd * imaginaryFactor
xOrd = 0
while (xOrd < screenX) {
cReal = minReal + xOrd * realFactor
zReal = cReal
zImaginary = cImaginary
interCount = 0
while (interCount < bailout) {
zRealSq = zReal * zReal
zImaginarySq = zImaginary * zImaginary;
if (zRealSq + zImaginarySq > 4 ) {
break
}
zImaginary = 2.0 * zReal * zImaginary + cImaginary
zReal = zRealSq - zImaginarySq + cReal
interCount += 1
}
if ( interCount < bailout ) {
color = color_map[interCount % 15]
if ( lastcolor != color ) {
Console.SetBackgroundColor(color)
}
lastcolor = color
Console.PrintAt( xOrd, yOrd, ' ')
Console.PrintAt( xOrd, screenY - yOrd - 1, ' ')
}
xOrd += 1
}
yOrd += 1
}
}
finally {
Console.SetBackgroundColor( oldBackgroundColor )
Console.SetForegroundColor( oldForegroundColor )
Console.SetCursor(0 , screenY + 1)
}