Julia で亀甲ベースの格子模様を描く(5)
plotter.jl を include
https://blog.goo.ne.jp/r-de-r/e/bd71a52a09801335d56f7c47d879bfe3
include("plotter.jl")
function kikkou5(nx=6, ny=5; r=1, width=600, height=400)
function unit(x, y)
sqrt32 = sqrt(3)/2
ax, ay = 0, 0
bx, by = sqrt32*r, r/2
cx, cy = sqrt32*r, -r/2
dx, dy = sqrt32/3*r, 0
ex, ey = sqrt32/2*r, r/4
fx, fy = 5sqrt32/6*r, r/4
gx, gy = sqrt32*r, 0
hx, hy = 5sqrt32/6*r, -r/4
ix, iy = sqrt32/2*r, -r/4
xs = [ax, bx, cx, ax, dx, dx, ex, fx, gx, hx, ix, dx, NaN, bx, fx, NaN, cx, hx];
ys = [ay, by, cy, ay, dy, dy, ey, fy, gy, hy, iy, dy, NaN, by, fy, NaN, cy, hy];
xs2 = copy(xs)
ys2 = copy(ys)
for θ = 0:60:300 # degree
for i = 1:length(xs)
xs2[i], ys2[i] = xs[i] * cosd(θ) + ys[i] * sind(θ), xs[i] * sind(θ) - ys[i] * cosd(θ)
end
plotline(x .+ xs2, y .+ ys2, lwd=2, col=:cornsilk)
end
end
sqrt3 = sqrt(3)
x1, y1, x2, y2 = r * sqrt3, r, (nx + 1.5) * r * sqrt3, (1.5ny + 0.5)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 + 1
unit(x * sqrt3 * r + (y % 2) * sqrt3 * r / 2, y * 1.5r)
end
end
plotend()
end
kikkou5(4, 4, width=780, height=550)
savefig("fig5.png")