Yin and yang
func circle (rad, cx, cy, fill='white', stroke='black') {
say "<circle cx='#{cx}' cy='#{cy}' r='#{rad}' fill='#{fill}' stroke='#{stroke}' stroke-width='1'/>"
}
func yin_yang (rad, cx, cy, fill='white', stroke='black', angle=90) {
var (c, w) = (1, 0)
angle != 0 && say "<g transform='rotate(#{angle}, #{cx}, #{cy})'>"
circle(rad, cx, cy, fill, stroke)
say("<path d='M #{cx} #{cy + rad}A #{rad/2} #{rad/2} 0 0 #{c} #{cx} #{cy} ",
"#{rad/2} #{rad/2} 0 0 #{w} #{cx} #{cy - rad} #{rad} #{rad} 0 0 #{c} #{cx} ",
"#{cy + rad} z' fill='#{stroke}' stroke='none' />")
circle(rad/5, cx, cy + rad/2, fill, stroke)
circle(rad/5, cx, cy - rad/2, stroke, fill)
angle != 0 && say "</g>"
}
say '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "https://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="https://www.w3.org/2000/svg" version="1.1" xmlns:xlink="https://www.w3.org/1999/xlink">'
yin_yang(40, 50, 50)
yin_yang(20, 120, 120)
say '</svg>'
Last updated