Created
April 8, 2023 00:20
-
-
Save takehiko/ed6dd3280affd13733f0238000f1e80c to your computer and use it in GitHub Desktop.
Marble color unifier.
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
#!/bin/bash | |
# mcu.sh: Marble color unifier. | |
# (From "four bags with one red, one green, and one blue marble per bag" | |
# to "four bags with three marbles per bag") | |
# Downloads: Multiply_4_bags_3_marbles.svg | |
# Makes: 4x3_1.svg 4x3_1.png 4x3_2.svg 4x3_2.png | |
# Depends on: wget sed inkscape gm (GraphicsMagick) | |
set -xe | |
if [ -f Multiply_4_bags_3_marbles.svg ] | |
then | |
echo "Multiply_4_bags_3_marbles.svg exists." | |
else | |
wget 'https://upload.wikimedia.org/wikipedia/commons/3/36/Multiply_4_bags_3_marbles.svg' | |
fi | |
# Fill the background with white to eliminate the transparent color. | |
sed -e '569i <rect fill="white" stroke="none" x="0" y="0" width="616" height="723"/>' Multiply_4_bags_3_marbles.svg > 4x3_1.svg | |
inkscape --export-filename=4x3_1_o.png 4x3_1.svg | |
gm convert 4x3_1_o.png -resize '50%' -quality 92 4x3_1.png | |
rm 4x3_1_o.png | |
# Choose one to decide the color of the marbles. | |
sed -E 's/00cc00|0000cc/cc0000/' 4x3_1.svg > 4x3_2.svg | |
# sed -E 's/0000cc|cc0000/00cc00/' 4x3_1.svg > 4x3_2.svg | |
# sed -E 's/cc0000|00cc00/0000cc/' 4x3_1.svg > 4x3_2.svg | |
inkscape --export-filename=4x3_2_o.png 4x3_2.svg | |
gm convert 4x3_2_o.png -resize '50%' -quality 92 4x3_2.png | |
rm 4x3_2_o.png |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment