-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrapher
More file actions
executable file
·127 lines (87 loc) · 1.88 KB
/
grapher
File metadata and controls
executable file
·127 lines (87 loc) · 1.88 KB
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
#!/bin/bash
clear
while getopts "d:r:" opt; do
case $opt in
r ) detail=$OPTARG ;;
d )
domainStart=${OPTARG%:*}
domainEnd=${OPTARG#*:}
;;
esac
done
calc() {
result=$(echo "$1" | bc | sed '/\./ s/\.\{0,1\}0\{1,\}$//')
shift 1
local OPTIND
while getopts 'a' opt; do
case $opt in
a ) absolute=1;;
esac
done
if [[ absolute -eq '1' ]]; then
result=${result#-}
fi
echo $result
}
fill() {
length=$1
char=$2
for i in $(seq 0 $length); do
echo $char
done
}
#result = indices of digits found in array
findI() {
declare -a array=(${@:1:$(($# - 1))})
declare -i digit="${@: -1}"
declare -a indices=()
declare -i i=0
declare resultIndex=0
for element in ${array[@]}; do
if [[ $element -eq $digit ]]; then
indices[$resultIndex]="$i"
((resultIndex++))
fi
((i++))
done
echo ${indices[@]}
}
#equation=$(./series '+ (z * ((x ^ y)/y!))' -y 'y+2;3' -z 'z * -1;-1' -d 3)
equation=$(cat < /dev/stdin)
zoom=$(calc "1/$detail")
domainRange=$(calc "$domainEnd - $domainStart" -a)
declare -i pos_res
declare -i neg_res
pos_res=$(calc "$zoom * $domainEnd" -a)
neg_res=$(calc "$zoom * $domainStart" -a)
declare -i res=$(calc "$zoom * $domainRange")
ratio=$(calc "$res / $domainRange")
for i in $(seq $res); do
x=$(calc "($i - $neg_res)/$ratio")
point=$(calc "${equation//'x'/$x}")
point=$(calc "$point * $zoom")
point=$(printf "%.0f" $point)
points[i]=$point
done
declare -a line
#fill line with '*' and '+' on y axis
for i in $(seq $res); do
blank[i]='.'
blank[$neg_res]='+'
done
#file line with '-'
declare -a axis
axis=(`fill $res '+'`)
for y in $(seq $pos_res -1 -$neg_res); do
line=("${blank[@]}")
if [[ y -eq 0 ]]; then
line=("${axis[@]}")
fi
declare -a indices=(`findI "${points[@]}" $y`)
if [[ -n $indices ]]; then
for index in ${indices[@]}; do
line[$index]='#'
done
fi
echo "${line[@]}"
done