Julia で円をモチーフにした格子模様を描く(4)
plotter.jl を include
https://blog.goo.ne.jp/r-de-r/e/bd71a52a09801335d56f7c47d879bfe3
include("plotter.jl")
function en4(nx=6, ny=5; r=1, factor=0.985, width=600, height=400)
function unit(x, y, r)
deg = 180:0.25:270
xs = zeros(length(deg), 2)
ys = zeros(length(deg), 2)
for (i, θ) = enumerate(deg)
xs[i, 1] = cosd(θ)factor + r
xs[i, 2] = cosd(θ-180)factor
ys[i, 1] = sind(θ)factor + r
ys[i, 2] = sind(θ-180)factor
end
xs = reshape(xs, :, 1)
ys = reshape(ys, :, 1)
xs2 = copy(xs)
ys2 = copy(ys)
for θ = 0:90:270 # degree
sine, cosine = sincosd(θ)
for i = 1:length(xs)
xs2[i], ys2[i] = xs[i]cosine + ys[i]sine, xs[i]sine - ys[i]cosine
end
plotpolygon(x .+ xs2, y .+ ys2, lwd=0, fcol=:black)
end
end
x1, y1, x2, y2 = r, r, 2nx+r, 2ny+r
println("(width, height) = ($(x2 - x1), $(y2 - y1))")
plotbegin(w=width, h=height)
#plotlimit(x1, y1, x2, y2)
#plotbox(x1, y1, x2, y2, col=:gray, fcol=:gray)
for y = 1:ny
for x = 1:nx
unit(2x, 2y, r)
end
end
plotend()
end
en4(6, 4, width=600, height=400)
savefig("en4.png")