Last active
May 28, 2023 20:28
-
-
Save thewhodidthis/febc8cf0740808ef3baa0d6cd24d1363 to your computer and use it in GitHub Desktop.
Worley noise 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") | |
# How many feature points? | |
R?=10 | |
# Pixmap dimensions | |
W?=80 | |
H?=45 | |
# How many pixels? | |
S?=$$(($W * $H - 1)) | |
# Out image dimensions | |
w?=800 | |
h?=450 | |
gradient/jpg: gradient | |
sips -s formatOptions best -s format jpeg $$(ls -tr | tail -n 1) -o $D.jpg && sips -z $h $w $D.jpg | |
gradient: | |
@list=`make features`; for i in `seq 0 $S`; do d=(); x=$$(($$i % $W)); y=$$(($$i / $W));\ | |
while read line; do p=($$line);\ | |
d+=($$(bc <<< "scale=6; sqrt(($${p[0]} - $$x) ^ 2 + ($${p[1]} - $$y) ^ 2)"));\ | |
done <<< "$$list";\ | |
v=`printf "%f\n" "$${d[@]}" | sort -n | head -n 1`;\ | |
c=`printf "%.0f\n" "$$(bc -l helper.bc <<< "clamp(remap($$v, 0, $W / 4, 255, 0), 0, 255)")"`;\ | |
echo $$c $$c $$c;\ | |
done | tr "\n" " " | awk '{print "P3\n$W $H\n255\n"$$0}' > "$$(date +"%Y%m%d%s").ppm" | |
features: | |
@{ jot -r $R 0 $$(($W - 1)); jot -r $R 0 $$(($H - 1)); } | pr -t -2 -s" " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment