-
Notifications
You must be signed in to change notification settings - Fork 0
/
mandlebrotSet.hs
66 lines (47 loc) · 1.97 KB
/
mandlebrotSet.hs
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
-- bounded ░
-- <= 8 ▒
-- <= 20 ▓
-- else █
--
boundedSpaceSymbol = "░"
levelOneExplosionSymbol = "▒"
levelTwoExplosionSymbol = "▓"
levelThreeExplosionSymbol = "█"
raisedPowerTwoBoundedValue = 4
--- values to exploit
levelOneExplosionValue = 200
levelTwoExplosionValue = 20
levelThreeExplosionValue = 8
-- [-2; 2] - interval
leftSideMax = -2
rightSideMax = 2
upSideMax = 1
downSideMax = -1
estimationMark = 0.019
maximumNumberOfIterations = 50
epsilon = 0.0001
---- all the values to exploit are up here ^
calculateGrowth z c numberOfIterations =
let currentResult = calculateMandlebrot z c
in let currentResultLength = estimateVectorRaisedLength currentResult
in if currentResultLength < epsilon || numberOfIterations == maximumNumberOfIterations
then (currentResultLength, numberOfIterations)
else if (checkBoundary currentResultLength)
then (currentResultLength, numberOfIterations)
else calculateGrowth currentResult c (numberOfIterations + 1)
estimateVectorRaisedLength (x, y) = x * x + y * y
checkBoundary vectorLengthRaised = vectorLengthRaised > raisedPowerTwoBoundedValue
calculateMandlebrot (zA, zB) (cX, cY) =
(zA * zA - (zB *zB) + cX , cY + 2 * zA * zB)
assignColourForSpace (calculationValue, numberOfIterations)
| calculationValue <= raisedPowerTwoBoundedValue = boundedSpaceSymbol
| numberOfIterations <= levelThreeExplosionValue = levelThreeExplosionSymbol
| numberOfIterations <= levelTwoExplosionValue = levelTwoExplosionSymbol
| otherwise = levelOneExplosionSymbol
iterateSpace x y string
| x > rightSideMax = iterateSpace leftSideMax (y - estimationMark) (string ++ "\n")
| y < downSideMax = string
| otherwise =
let currentGrowth = calculateGrowth ((0, 0)) ((x, y)) 1
in iterateSpace (x + estimationMark) y (string ++ ((assignColourForSpace currentGrowth)))
main = putStrLn (iterateSpace leftSideMax upSideMax "")