Skip to content

Instantly share code, notes, and snippets.

@YuukiToriyama
Created June 22, 2019 22:42
Show Gist options
  • Save YuukiToriyama/e4c69554ac04e255f8a0783afec99d91 to your computer and use it in GitHub Desktop.
Save YuukiToriyama/e4c69554ac04e255f8a0783afec99d91 to your computer and use it in GitHub Desktop.
Some Arrangements of Koch Curve【Bash,ImageMagick,シェル芸】

koch island

eval echo "fbfbfbf" "| sed 's/f/faffbffbfbfafaffbfbfafaffaffbf/g'"{,} | grep -o [ab]*f | awk 'BEGIN{x=250;y=250;rx=0;ry=13} {tmp=rx; printf "%s,%s ", x,y; x=x+rx; y=y+ry; if($1=="af"){rx=-ry; ry=tmp}else if($1=="bf"){rx=ry; ry=-tmp}} END{printf "%s,%s", x,y}' | xargs -I@ convert -size 1000x1000 xc:DarkRed -fill none -stroke Yellow -strokewidth 4 -draw "path 'M @'" koch_island.png

koch flower

eval echo "fbfbfbf" "| sed 's/f/ffbfbfbfbfbfaf/g'"{,,} | grep -o [ab]*f | awk 'BEGIN{x=50;y=550;rx=0;ry=20} {tmp=rx; printf "%s,%s ", x,y; x=x+rx; y=y+ry; if($1=="af"){rx=-ry; ry=tmp}else if($1=="bf"){rx=ry; ry=-tmp}} END{printf "%s,%s", x,y}' | xargs -I@ convert -size 1000x1000 xc:DarkRed -fill none -stroke Yellow -strokewidth 4 -draw "path 'M @'" flower.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment