-
Notifications
You must be signed in to change notification settings - Fork 30
/
scale.sh
executable file
·60 lines (57 loc) · 1.12 KB
/
scale.sh
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
#!/bin/bash
# for use with Life1D for CS61C
# example usage:
# $ ./Life1D 17 3141592653 | ./scale.sh 10 | ppmtogif > Life1D_17_3141592653.gif
first=1
while read line
do
array=(${line// / })
if [ "$first" -eq 0 ]
then
# insert black horizontal line
for (( k=0; k<$width; k++ ))
do
echo -n "1 "
done
echo ""
# loop by scaling factor in height
for (( n=0; n<$1; n++ ))
do
# loop by element in line
for i in "${!array[@]}"
do
echo -n "1 "
# loop by scaling factor in width
for (( j=0; j<$1; j++ ))
do
echo -n "${array[i]} "
done
done
echo "1 "
done
else
# modify first line for new dimensions
first=0
width=$((${array[1]}*($1+1)+1))
height=$((${array[2]}*($1+1)+1))
for i in "${!array[@]}"
do
if [ "$i" -eq 1 ]
then
echo -n "$width "
elif [ "$i" -eq 2 ]
then
echo -n "$height "
else
echo -n "${array[i]} "
fi
done
echo ""
fi
done
# insert black horizontal line
for (( n=0; n<$width; n++ ))
do
echo -n "1 "
done
echo ""