Code to generate the Imperial Seal of Japan, a stylized chrysanthemum with 16 petals.
import Diagrams.Backend.SVG.CmdLine
import qualified Diagrams.TwoD.Path.Boolean as B
We start with an upright petal defined by an angle.
We construct the petal from a wedge
and a circle
which we position in
such a way that the circle touches the wedge right and left of the circle
segment.
petal :: Angle Double -> Diagram B
= strokePath $ B.union Winding (uprightWedge <> touchingCircle)
petal angle where
First we draw an upright wedge by constructing a counterclockwise wedge starting at 12 o’clock, then rotating it clockwise so it is centered.
= wedge 1 yDir angle # rotate (negated halfAngle) uprightWedge
Next, we draw the circle touching the wedge.
= circle circleRadius # translateY yShift touchingCircle
The center (origin) of the wedge, the center of the circle and the point where they touch form a right-angled triangle with the hypotenuse being the line from center_circle to center_wegde, and relative to half the wedge’s angle at the origin of the wedge, the adjacent leg is radius_wedge and the opposite opposite leg is radius_circle. Thus, cos halfAngle = radius_wedge(=1) / hypotenuse
= 1 / cosA halfAngle yShift
and tan halfAngle = radius_circle / radius_wedge.
= 1 * tanA halfAngle
circleRadius = (/2) <$> angle halfAngle
For the corolla we want n petals arranged in a circle so each has an angle of 1/n times a full circle.
= mconcat $ take n $ iterate (rotate angle) (petal angle)
nPetals n where
= (1 / fromIntegral n) @@ turn angle
The seal consists of two corollas on top of each other with a small circle on top of them.
= circle 0.158
imperialSeal <> corolla
<> rotateBy (1/ fromIntegral (2*n)) corolla
-- background corolla rotated by half a petal
where
= nPetals n
corolla = 16
n
= imperialSeal # fc gold
imperialSealGoldWhite # bgFrame 0.1 white
= imperialSeal # fc (sRGB24read "#c0a73f")
imperialSealGoldRed # lc (sRGB24read "#be0025")
# bgFrame 0.1 (sRGB24read "#be0025")
# lwG 0.04
= imperialSealGoldWhite example
= mainWith (example :: Diagram B) main