Julia で円をモチーフにした格子模様を描く(3)
plotter.jl を include
https://blog.goo.ne.jp/r-de-r/e/bd71a52a09801335d56f7c47d879bfe3
include("plotter.jl")
function en3(nx=6, ny=5; r=1, factor=0.95, width=600, height=400)
function unit(x, y, r)
deg = 180:0.25:270
xs = zeros(length(deg))
ys = zeros(length(deg))
for (i, θ) = enumerate(deg)
xs[i] = cosd(θ)factor + r
ys[i] = sind(θ)factor + r
end
xs2 = copy(xs)
ys2 = copy(ys)
for θ = 0:90:270 # degree
for i = 1:length(xs)
xs2[i], ys2[i] = xs[i] * cosd(θ) + ys[i] * sind(θ), xs[i] * sind(θ) - ys[i] * cosd(θ)
end
plotpolygon(x .+ xs2, y .+ ys2, fcol=:black)
end
end
nx += 1
ny += 1
x1, y1, x2, y2 = r, r, nx, ny
println("(width, height) = ($(x2 - x1), $(y2 - y1))")
plotbegin(w=width, h=height)
plotlimit(x1, y1, x2, y2)
for y = 1:ny
for x = 1:nx
unit(x, y, r)
end
end
plotend()
end
en3(6, 4, width=600, height=400)
savefig("en3.png")
※コメント投稿者のブログIDはブログ作成者のみに通知されます