Skip to content

Instantly share code, notes, and snippets.

@PatWie
Created January 20, 2015 18:57
Show Gist options
  • Save PatWie/3e8ae1ec7c965d7c2f6d to your computer and use it in GitHub Desktop.
Save PatWie/3e8ae1ec7c965d7c2f6d to your computer and use it in GitHub Desktop.
creates a random checkers pattern and export it to png
WIDTH=300
HEIGHT=300
BGCOLOR="#0f232c"
echo "" > pattern.svg
echo -n "<svg id=\"subtle\" width=\"${WIDTH}\" height=\"${HEIGHT}\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">" >> pattern.svg
echo -n "<rect x=\"0\" y=\"0\" width=\"100%\" height=\"100%\" fill=\"${BGCOLOR}\"></rect>" >> pattern.svg
for i in `seq 1 10 $WIDTH`; do
for j in `seq 1 10 $WIDTH`; do
OPACITY=`shuf -i 1-10 -n 1`
FILLER=`shuf -i 0-1 -n 1`
OPACITY=`echo "scale=2; ${OPACITY}/100.0" | bc`
if [[ "$FILLER" == "1" ]]; then
FILLE="#222"
else
FILLE="#ddd"
fi
echo -n "<rect x=\"$i\" stroke=\"#000\" stroke-opacity=\"0.1\" y=\"$j\" width=\"10\" height=\"10\" style=\"fill: ${FILLE}; fill-opacity: ${OPACITY};\"></rect>" >> pattern.svg
done
done
echo -n "</svg>" >> pattern.svg
inkscape -z -e pattern.png pattern.svg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment