forked from bahamas10/bash-bmp
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgradient
More file actions
executable file
·60 lines (49 loc) · 982 Bytes
/
gradient
File metadata and controls
executable file
·60 lines (49 loc) · 982 Bytes
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
#!/usr/bin/env bash
#
# Emits a gradient BMP image
#
# Author: Dave Eddy <dave@daveeddy.com>
# Date: July 29, 2025
# License: MIT
. ./lib/bmp || exit
debug() {
echo '[debug]' "$@" >&2
}
fatal() {
echo '[fatal]' "$@" >&2
exit 1
}
make-bmp() {
local width=$1
local height=$2
bmp-header "$width" "$height"
local padding=$REPLY
local r g b y x
for ((y = 0; y < height; y++)); do
for ((x = 0; x < width; x++)); do
((r = x * 255 / width))
((b = y * 255 / height))
bmp-rgb "$r" 0 "$b"
done
debug "handled row $((y + 1))/$height"
bmp-pad "$padding"
done
}
main() {
local width=400
local height=400
local output=out.bmp
local OPTIND OPTARG opt
while getopts 'w:h:o:' opt; do
case "$opt" in
w) width=$OPTARG;;
h) height=$OPTARG;;
o) output=$OPTARG;;
*) fatal 'bad option';;
esac
done
make-bmp "$width" "$height" > "$output" || \
fatal "failed to generate $output"
echo "generated ${width}x$height image: $output"
}
main "$@"