using Compose
set_default_graphic_size(15cm,5cm)
f_points = [(.1, .1), (.9, .1), (.9, .2), (.2, .2), (.2, .4), (.6, .4), (.6, .5),
(.2, .5), (.2, .9), (.1, .9), (.1, .1)]
f_points = (x->0.4.*x.+0.1).(f_points)
fpoly(ϕ::Float64) = (context(rotation=Rotation(ϕ,0.3,0.46)), polygon(f_points))
imgfa(θ, ϕ=0.0, x=0.5,y=0.5) = compose(context(),
fill("salmon"), fillopacity(1.0), fpoly(ϕ),
(context(rotation=Rotation(θ,x,y)), line([(x-0.5,y),(x+0.5,y)]), circle(x,y, 0.02)),
(context(mirror=Mirror(θ, x, y)), fpoly(ϕ))
)
Fmir = hstack(imgfa(-π/4), imgfa(-π/2.2), imgfa(π/4, 1π))
img = compose(context(), rectangle(), fill(nothing), stroke("black"), Fmir)
">
<path d="M-75,-25 L75,-25 75,25 -75,25 z" class="primitive"/>
</g>
<g fill-opacity="1" fill="%23FA8072" id="img-e9727cb2-2">
<g transform="translate(133.18,17.55)">
<path d="M5.82,5.45 L5.82,-10.55 3.82,-10.55 3.82,3.45 -0.18,3.45 -0.18,-4.55 -2.18,-4.55 -2.18,3.45 -10.18,3.45 -10.18,5.45 5.82,5.45 z" class="primitive"/>
</g>
<g transform="translate(125,25)">
<circle cx="0" cy="0" r="1" class="primitive"/>
</g>
<g transform="translate(125,25)">
<path fill="none" d="M-17.68,-17.68 L17.68,17.68 " class="primitive"/>
</g>
<g transform="translate(117.55,33.18)">
<path d="M5.45,5.82 L-10.55,5.82 -10.55,3.82 3.45,3.82 3.45,-0.18 -4.55,-0.18 -4.55,-2.18 3.45,-2.18 3.45,-10.18 5.45,-10.18 5.45,5.82 z" class="primitive"/>
</g>
</g>
<g fill-opacity="1" fill="%23FA8072" id="img-e9727cb2-3">
<g transform="translate(90.47,16.85)">
<path d="M6.87,-4.05 L-8.48,-8.55 -9.04,-6.63 4.39,-2.69 3.26,1.15 -4.41,-1.11 -4.98,0.81 2.7,3.07 0.45,10.74 2.37,11.31 6.87,-4.05 z" class="primitive"/>
</g>
<g transform="translate(75,25)">
<circle cx="0" cy="0" r="1" class="primitive"/>
</g>
<g transform="translate(75,25)">
<path fill="none" d="M-3.56,24.75 L3.56,-24.75 " class="primitive"/>
</g>
<g transform="translate(62.45,12.82)">
<path d="M-5.45,-5.82 L10.55,-5.82 10.55,-3.82 -3.45,-3.82 -3.45,0.18 4.55,0.18 4.55,2.18 -3.45,2.18 -3.45,10.18 -5.45,10.18 -5.45,-5.82 z" class="primitive"/>
</g>
</g>
<g fill-opacity="1" fill="%23FA8072" id="img-e9727cb2-4">
<g transform="translate(37.18,37.55)">
<path d="M5.82,5.45 L5.82,-10.55 3.82,-10.55 3.82,3.45 -0.18,3.45 -0.18,-4.55 -2.18,-4.55 -2.18,3.45 -10.18,3.45 -10.18,5.45 5.82,5.45 z" class="primitive"/>
</g>
<g transform="translate(25,25)">
<circle cx="0" cy="0" r="1" class="primitive"/>
</g>
<g transform="translate(25,25)">
<path fill="none" d="M-17.68,17.68 L17.68,-17.68 " class="primitive"/>
</g>
<g transform="translate(12.45,12.82)">
<path d="M-5.45,-5.82 L10.55,-5.82 10.55,-3.82 -3.45,-3.82 -3.45,0.18 4.55,0.18 4.55,2.18 -3.45,2.18 -3.45,10.18 -5.45,10.18 -5.45,-5.82 z" class="primitive"/>
</g>
</g>
</g>
</svg>
)
using Compose
set_default_graphic_size(15cm,5cm)
# This example also illustrates nested contexts
f_points = [(.1, .1), (.9, .1), (.9, .2), (.2, .2), (.2, .4),
(.6, .4), (.6, .5), (.2, .5), (.2, .9), (.1, .9), (.1, .1)]
rect(c::String) = (context(), rectangle(), stroke(c))
circ(c::String, s::Float64=0.4) = (context(), circle([x],[y],[0.03,s]), stroke(c))
fpoly(c::String) = (context(), polygon(f_points), fill(c), fillopacity(1.0))
contextC(θ::Float64) = (context(0.5,0.5,1.5,1.5, units=UnitBox(0,0,1,1),
rotation=Rotation(θ,x,y)), fpoly("steelblue"), circ("orange"))
imgf(θ::Float64) = compose(context(),
(context(0.15, 0.15, 0.7, 0.7, units=UnitBox(0,0,2,2)), rect("red"),
contextC(θ)) # context C in context B in context A
)
x, y, θ = 0.5, 0.25, π/3
Frot = hstack(imgf(-θ), imgf(0.), imgf(θ))
img = compose(context(), rectangle(), fill(nothing), stroke("black"), Frot)
">
<path d="M-75,-25 L75,-25 75,25 -75,25 z" class="primitive"/>
</g>
<g stroke="%23FFA500" id="img-f568d3fc-2">
<g transform="translate(129.38,22.81)">
<circle cx="0" cy="0" r="0.79" class="primitive"/>
</g>
<g transform="translate(129.38,22.81)">
<circle cx="0" cy="0" r="10.5" class="primitive"/>
</g>
</g>
<g fill-opacity="1" fill="%234682B4" id="img-f568d3fc-3">
<g transform="translate(124.5,21.77)">
<path d="M3.03,-10.02 L13.53,8.17 11.26,9.48 2.07,-6.43 -2.47,-3.81 2.78,5.29 0.5,6.6 -4.75,-2.49 -13.84,2.76 -15.15,0.48 3.03,-10.02 z" class="primitive"/>
</g>
</g>
<g stroke="%23FF0000" id="img-f568d3fc-4">
<g transform="translate(125,25)">
<path d="M-17.5,-17.5 L17.5,-17.5 17.5,17.5 -17.5,17.5 z" class="primitive"/>
</g>
</g>
<g stroke="%23FFA500" id="img-f568d3fc-5">
<g transform="translate(79.38,22.81)">
<circle cx="0" cy="0" r="0.79" class="primitive"/>
</g>
<g transform="translate(79.38,22.81)">
<circle cx="0" cy="0" r="10.5" class="primitive"/>
</g>
</g>
<g fill-opacity="1" fill="%234682B4" id="img-f568d3fc-6">
<g transform="translate(76.03,26.51)">
<path d="M-7.16,-7.64 L13.84,-7.64 13.84,-5.01 -4.53,-5.01 -4.53,0.24 5.97,0.24 5.97,2.86 -4.53,2.86 -4.53,13.36 -7.16,13.36 -7.16,-7.64 z" class="primitive"/>
</g>
</g>
<g stroke="%23FF0000" id="img-f568d3fc-7">
<g transform="translate(75,25)">
<path d="M-17.5,-17.5 L17.5,-17.5 17.5,17.5 -17.5,17.5 z" class="primitive"/>
</g>
</g>
<g stroke="%23FFA500" id="img-f568d3fc-8">
<g transform="translate(29.38,22.81)">
<circle cx="0" cy="0" r="0.79" class="primitive"/>
</g>
<g transform="translate(29.38,22.81)">
<circle cx="0" cy="0" r="10.5" class="primitive"/>
</g>
</g>
<g fill-opacity="1" fill="%234682B4" id="img-f568d3fc-9">
<g transform="translate(30.91,27.56)">
<path d="M-10.19,2.38 L0.31,-15.8 2.58,-14.49 -6.61,1.42 -2.06,4.05 3.19,-5.05 5.46,-3.73 0.21,5.36 9.31,10.61 7.99,12.88 -10.19,2.38 z" class="primitive"/>
</g>
</g>
<g stroke="%23FF0000" id="img-f568d3fc-10">
<g transform="translate(25,25)">
<path d="M-17.5,-17.5 L17.5,-17.5 17.5,17.5 -17.5,17.5 z" class="primitive"/>
</g>
</g>
</g>
</svg>
)
using Compose
set_default_graphic_size(15cm, 5cm)
f_points = [(.1, .1), (.9, .1), (.9, .2), (.2, .2), (.2, .4), (.6, .4),
(.6, .5), (.2, .5), (.2, .9), (.1, .9), (.1, .1)]
f_points = (x->0.5.*x.+0.3).(f_points)
ctxl(θ, x, y) = (context(rotation=Rotation(θ, x, y)), circle(x,y, 0.01),
line([(x-0.5,y),(x+0.5,y)]))
fpoly(c::String) = (context(), polygon(f_points), fill(c) )
ctxf(θ, ϕ, s, x, y,c) = (context(rotation=Rotation(-θ, x, y),
shear=Shear(s, ϕ, x, y)), fpoly(c))
x, y, θ = 0.5, 0.5, -π/6
img1 = compose(context(), stroke("black"), ctxl(θ,x,y), ctxf(0,0,0,x,y, "yellow"),
(context(), arc(x,y,0.3,π+θ,π-0.15), arrow()) )
img2 = compose(context(), stroke("black"), ctxl(0,x,y),
ctxf(θ,0,1.8,x,y,"transparent"), ctxf(θ,0,0,x,y,"yellow"),
text(0.5, 0.1, "x' = x+y*shear", hcenter, vcenter) )
img3 = compose(context(), stroke("black"),
ctxl(θ, x, y), ctxf(0,θ,1.8,x,y,"yellow") )
hstack(img1, img2, img3)
">
<path d="M8.31,-16.01 L12.73,-7.01 9.35,-2.56 5.49,-10.44 -1.26,-1.54 0.95,2.96 -2.43,7.41 -4.63,2.91 -18.13,20.7 -18.69,19.58 8.31,-16.01 z" class="primitive"/>
</g>
</g>
<g transform="translate(125,25)">
<path fill="none" d="M-21.65,12.5 L21.65,-12.5 " class="primitive"/>
</g>
<g transform="translate(125,25)">
<circle cx="0" cy="0" r="0.5" class="primitive"/>
</g>
</g>
<g stroke="%23000000" id="img-02ae3118-3">
<g transform="translate(75,5)">
<g class="primitive">
<text text-anchor="middle" dy="0.35em">x%27 = x+y*shear</text>
</g>
</g>
<g fill="%23FFFF00" id="img-02ae3118-4">
<g transform="translate(74.52,24.46)">
<path d="M-2.27,-9.71 L15.05,0.29 13.8,2.46 -1.35,-6.29 -3.85,-1.96 4.81,3.04 3.56,5.2 -5.1,0.2 -10.1,8.86 -12.27,7.61 -2.27,-9.71 z" class="primitive"/>
</g>
</g>
<g fill="%23000000" fill-opacity="0.000" id="img-02ae3118-5">
<g transform="translate(75.49,24.46)">
<path d="M15.21,-9.71 L14.53,0.29 9.38,2.46 9.97,-6.29 -0.32,-1.96 -0.66,3.04 -5.81,5.2 -5.47,0.2 -26.06,8.86 -25.97,7.61 15.21,-9.71 z" class="primitive"/>
</g>
</g>
<g transform="translate(75,25)">
<path fill="none" d="M-25,0 L25,0 " class="primitive"/>
</g>
<g transform="translate(75,25)">
<circle cx="0" cy="0" r="0.5" class="primitive"/>
</g>
</g>
<g stroke="%23000000" id="img-02ae3118-6">
<g marker-end="url(%23arrow)" id="img-02ae3118-7">
<g transform="translate(25,25)">
<path d="M-12.99,7.5 A15,15 0 0 1 -14.83,2.24" class="primitive"/>
</g>
</g>
<g fill="%23FFFF00" id="img-02ae3118-8">
<g transform="translate(24.32,24.77)">
<path d="M-6.82,-7.27 L13.18,-7.27 13.18,-4.77 -4.32,-4.77 -4.32,0.23 5.68,0.23 5.68,2.73 -4.32,2.73 -4.32,12.73 -6.82,12.73 -6.82,-7.27 z" class="primitive"/>
</g>
</g>
<g transform="translate(25,25)">
<path fill="none" d="M-21.65,12.5 L21.65,-12.5 " class="primitive"/>
</g>
<g transform="translate(25,25)">
<circle cx="0" cy="0" r="0.5" class="primitive"/>
</g>
</g>
</svg>
)