-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjulia
executable file
·71 lines (57 loc) · 1.18 KB
/
julia
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
#!/usr/bin/env bash
# Copyright (C) 2018 Grzegorz Wcisło
# polar coordinates
radius=0.78
phi=0
main() {
init
while :; do
# rotate parameter and redraw
phi=$(echo "$phi" | awk '{printf("%f", $1 + 0.05)}')
draw
sleep 0.05
done
}
init() {
resize
# set default parameters
x=-0.5
y=0
scale=$DEFAULT_SCALE
max_iter=15
fractal=m
# save terminal state, hide cursor and clear
tput smcup
tput civis
tput clear
trap 'resize; draw' WINCH # terminal resize signal
trap cleanup INT
}
resize() {
# set new width and height
w=$(tput cols)
h=$(tput lines)
DEFAULT_SCALE=$h
}
draw() {
# move cursor to (0,0)
tput cup 0 0
# calculate carthesian coordinates
px=$(echo "$phi $radius" | awk '{printf("%f", $2*cos($1))}')
py=$(echo "$phi $radius" | awk '{printf("%f", $2*sin($1))}')
# draw fractal
./mandelbrot.out j $w $h $scale 0 0 $max_iter $px $py
}
show_debug() {
tput cup 0 0
echo "Position: ($x,$y)"
echo "Zoom: $scale"
echo "Parameter: ($px,$py)"
}
cleanup() {
# restore teminal state and show cursor
tput rmcup
tput cnorm
exit 0
}
main