Last active
December 1, 2023 12:38
-
-
Save thewhodidthis/ef522400f81ad5cf0631e95ffd7e5d28 to your computer and use it in GitHub Desktop.
PPM byte beat maker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Call like so: `echo 'clamp(256, 0, 255)' | bc -l helper.bc` */ | |
define clamp(v, lo, hi) { | |
if (v < lo) { | |
return (lo) | |
} | |
if (v > hi) { | |
return (hi) | |
} | |
return (v) | |
} | |
define remap(v, x1, x2, y1, y2) { | |
return (v - x1) * (y2 - y1) / (x2 - x1) + y1 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The filenaming timestamp | |
D?=$$(date +"%Y%m%d%s") | |
# Pixmap dimensions | |
W?=64 | |
H?=64 | |
# How many pixels? | |
S?=$$(($W * $H - 1)) | |
# Out image dimensions | |
w?=192 | |
h?=192 | |
beat/jpg: beat | |
sips -s formatOptions best -s format jpeg $$(ls -tr | tail -n 1) -o $D.jpg && sips -z $h $w $D.jpg | |
beat: | |
@for i in `seq 0 $S`; do d=(); x=$$(($$i % $W)); y=$$(($$i / $W));\ | |
d+=($$(bc <<< "($$x * 64) % $$y * 255"));\ | |
c=`printf "%d\n" "$${d[@]}"`;\ | |
echo $$c $$c $$c;\ | |
done | tr "\n" " " | awk '{print "P3\n$W $H\n255\n"$$0}' > "$$(date +"%Y%m%d%s").ppm" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment