裏 RjpWiki

Julia ときどき R, Python によるコンピュータプログラム,コンピュータ・サイエンス,統計学

Julia で花菱をモチーフとした模様を描く(3)

2021年08月31日 | ブログラミング

Julia で花菱をモチーフとした模様を描く(3)

include("plotter.jl")

function hanabisi3(nx=6, ny=6; r=1, fcol1=:darkturquoise,
                   fcol2=:green3, fcol3=:lightpink,
                   fcol4=:lightsalmon,
                   backcol=:cornsilk, circlecol=:gold,
                   width=600, height=400)
    plotbegin(w=width, h=height)
    nx += 1
    ny += 3
    x1, y1, x2, y2 = 2r, r, (2nx+1)r, ny*r
    println("(width, height) = ($(x2 - x1), $(y2 - y1))")
    plotbegin(w=width, h=height)
    plotlimit(x1, y1, x2, y2)
    plotbox(x1, y1, x2, y2, lwd=0, fcol=backcol)
    r1, φ = 0.95r, 5
    for i = 1:ny
        y = i*r
        for j = 1:nx
            x = (2j + i % 2)r
            plotcircle(x, y, r1, startangle=φ, endangle=90-φ, col=circlecol, lwd=2)
            plotcircle(x, y, r1, startangle=90+φ, endangle=180-φ, col=circlecol, lwd=2)
            plotcircle(x, y, r1, startangle=180+φ, endangle=270-φ, col=circlecol, lwd=2)
            plotcircle(x, y, r1, startangle=270+φ, endangle=360-φ, col=circlecol, lwd=2)
            fcol=[fcol1, fcol2, fcol3, fcol4][(3i + j) % 4 + 1]
            hanabisi(x, y, r=0.5r, lwd=1, fcol=fcol,
                     backcol=backcol)
        end
    end
    plotend()
end

hanabisi3(4, 4, width=630, height=420)

コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

Julia で花菱をモチーフとした模様を描く(2)

2021年08月31日 | ブログラミング

Julia で花菱をモチーフとした模様を描く(2)

include("plotter.jl")

function hanabisi2(nx=6, ny=6; r=1, fcol=:brown,
                   backcol=:cornsilk, width=600, height=400)
    plotbegin(w=width, h=height)
    nx += 1
    ny += 2
    x1, y1, x2, y2 = 2r, r*sqrt(3), (2nx+1)r, ny*r*sqrt(3)
    println("(width, height) = ($(x2 - x1), $(y2 - y1))")
    plotbegin(w=width, h=height)
    plotlimit(x1, y1, x2, y2)
    plotbox(x1, y1, x2, y2, lwd=0, fcol=backcol)
    for i = 1:ny
        y = sqrt(3)i*r
        for j = 1:nx
            x = (2j + i % 2)r
            plotpolygon2(x, y, 1.08r, 6, φ=30, lwd=0, fcol=fcol)
            plotpolygon2(x, y, 0.85r, 6, φ=30, lwd=0, fcol=backcol)
            plotpolygon2(x, y, 0.80r, 6, φ=30, lwd=1, col=fcol)
            hanabisi(x, y, r=0.6r, lwd=1, fcol=fcol,
                     backcol=backcol)
        end
    end
    plotend()
end

hanabisi2(4, 3, width=630, height=485)

コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

Julia で花菱をモチーフとした模様を描く(1)

2021年08月31日 | ブログラミング

Julia で花菱をモチーフとした模様を描く(1)

include("plotter.jl")

以下の関数は単位としての花菱を1つ描く

function hanabisi(x, y; r=1, lwd=2, fcol=:black, backcol=:white, frame=false, framecol=:red)
    u = r / 280
    tangent = 5/7
    plotcircle(x + 250u, y, 55u, col=fcol, fcol=fcol)
    plotcircle(x - 250u, y, 55u, col=fcol, fcol=fcol)
    plotcircle(x + 175u, y + 45u, 60u, col=fcol, fcol=fcol)
    plotcircle(x - 175u, y + 45u, 60u, col=fcol, fcol=fcol)
    plotcircle(x + 175u, y - 45u, 60u, col=fcol, fcol=fcol)
    plotcircle(x - 175u, y - 45u, 60u, col=fcol, fcol=fcol)
    plotcircle(x + 75u, y + 115u, 55u, col=fcol, fcol=fcol)
    plotcircle(x - 75u, y + 115u, 55u, col=fcol, fcol=fcol)
    plotcircle(x + 75u, y - 115u, 55u, col=fcol, fcol=fcol)
    plotcircle(x - 75u, y - 115u, 55u, col=fcol, fcol=fcol)
    plotcircle(x, y + 175u, 55u, col=fcol, fcol=fcol)
    plotcircle(x, y - 175u, 55u, col=fcol, fcol=fcol)
    plotpolygon(x .+ [0u, 127u, 0u, -127u], y .+ [0u, 95u, 175u, 95u],
                lwd=0, fcol=fcol)
    plotpolygon(x .+ [0u, 127u, 0u, -127u], y .+ [0u, -95u, -175u, -95u],
                lwd=0, fcol=fcol)
    plotpolygon(x .+ [0u, 129u, 250u, 129u], y .+ [0u, 86u, 0u, -86u],
                lwd=0, fcol=fcol)
    plotpolygon(x .+ [0u, -129u, -250u, -129u], y .+ [0u, -86u, 0u, 86u],
                lwd=0, fcol=fcol)
    plotline(x + 175u, y + 125u, x - 175u, y - 125u, lwd=lwd, col=backcol)
    plotline(x + 175u, y - 125u, x - 175u, y + 125u, lwd=lwd, col=backcol)
    plotline(x, y + 95u, x, y - 95u, lwd=lwd, col=backcol)
    plotline(x+ 115u, y, x - 115u, y, lwd=lwd, col=backcol)
    plotcircle(x, y, 45u, col=backcol, fcol=backcol)
    plotcircle(x, y, 35u, col=fcol, fcol=fcol)
    if frame
        d = 1120/3
        plotpolygon(x .+ [d*u, 0, -d*u, 0],
                    y .+ [0, d*tangent*u, 0, -d*tangent*u],
                    lwd=0.5, col=:red)
    end
end

パラメータの設定で2通りの花菱模様を描くプログラム。

function hanabisi1(nx=6, ny=6; r=1, fcol1=:lightpink,
                   fcol2=:lightgoldenrod, backcol=:lightcyan,
                   frame=false, framecol=:red, width=600, height=400)
    plotbegin(w=width, h=height)
    nx += 1
    ny = 2ny + 1
    tangent = 5/7
    x1, y1, x2, y2 = 2r, tangent*r, (2nx+1)r, tangent*ny*r
    println("(width, height) = ($(x2 - x1), $(y2 - y1))")
    plotbegin(w=width, h=height)
    plotlimit(x1, y1, x2, y2)
    plotbox(x1, y1, x2, y2, lwd=0, fcol=backcol)
    for i = 1:ny
        for j = 1:nx
            hanabisi(2j + i % 2, tangent*i, r=0.72,
                 fcol=i % 2 == 1 ? fcol1 : fcol2, backcol=backcol,
                 frame=frame, framecol=framecol)
        end
    end
    plotend()
end

hanabisi1(4, 4, width=650, height=426)

hanabisi1(4, 4, fcol1=:mediumseagreen, fcol2=:dodgerblue3,
          backcol=:darksalmon, frame=true, framecol=:white,
          width=650, height=426)

コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

家紋シリーズ 鱗(3) 六つ鱗 

2021年08月29日 | ブログラミング

家紋シリーズ 鱗(3) 六つ鱗 

include("plotter.jl")

function mutuuroko(; r=1, width=400, height=400)
    plotbegin(w=width, h=height)
    plotpolygon2(0, 0, r, 3, lwd=0, fcol=:black)
    plotpolygon2(0, 0, r, 3, φ = 30, lwd=0, fcol=:black)
    plotpolygon2(0, 0, r/sqrt(3), 6, φ = 60, lwd=0, fcol=:white)
    plotend()
end


mutuuroko()

コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

家紋シリーズ 鱗(2) 三つ鱗,丸に三つ鱗

2021年08月29日 | ブログラミング

家紋シリーズ 鱗(2) 三つ鱗,丸に三つ鱗

include("plotter.jl")

function mituuroko(; r=1, width=400, height=400, maru=false)
    u = sqrt(3)/6*r
    !maru && plotbegin(w=width, h=height)
    plotpolygon2(0, u, u, 3, lwd=0, fcol=:black)
    plotpolygon2(r/4, -0.5u, u, 3, lwd=0, fcol=:black)
    plotpolygon2(-r/4, -0.5u, u, 3, lwd=0, fcol=:black)
    !maru && plotend()
end

mituuroko()

function marunimituuroko(; r=1, width=400, height=400)
    plotbegin(w=width, h=height)
    plotcircle(0, 0, r, fcol=:black)
    plotcircle(0, 0, 60/70*r, col=:white, fcol=:white)
    mituuroko(; r=1.43, maru=true)
    plotend()
end

marunimituuroko()

コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

家紋シリーズ 鱗(1) 丸に一つ鱗 

2021年08月29日 | ブログラミング

家紋シリーズ 鱗(1) 丸に一つ鱗 

include("plotter.jl")

function marunihitotuuroko(; r=1, width=400, height=400)
    u = r/140
    plotbegin(w=width, h=height)
    plotcircle(0, 0, 70u, fcol=:black)
    plotcircle(0, 0, 57u, fcol=:white)
    plotpolygon2(0, 0, 54u, 3, fcol=:black)
    plotend()
end

marunihitotuuroko()

コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

家紋シリーズ 梅(9) 八重向こう梅

2021年08月29日 | ブログラミング

家紋シリーズ 梅(9) 八重向こう梅

include("plotter.jl")

function yaemukouume(; r=1, width=400, height=400)
    u = r/72
    plotbegin(w=width, h=height)
    for i = 54:72:342
        plotcircle(43u*cosd(i), 43u*sind(i), 31u, fcol=:black)
    end
    for i = 18:72:306
        plotcircle(43u*cosd(i), 43u*sind(i), 30u, lwd=3, col=:white, fcol=:white)
    end
    for i = 18:72:306
        plotcircle(43u*cosd(i), 43u*sind(i), 28u, lwd=3, fcol=:black)
    end
    plotcircle(0, 0, 40u, fcol=:black)
    plotcircle(0, 0, 9u, col=:white, fcol=:white)
    plotcircle(0, 0, 7u * r, fcol=:black)
    d = 3
    for i = 6:12:354
        plotpolygon([39u*cosd(i), 9u*cosd(i-d), 9u*cosd(i+d)],
                    [39u*sind(i), 9u*sind(i-d), 9u*sind(i+d)],
                    col=:white, fcol=:white)
        plotcircle(39u*cosd(i), 39u*sind(i), u, col=:white, fcol=:white)
    end
    plotend()
end

yaemukouume()

コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

家紋シリーズ 梅(8) 向こう梅

2021年08月29日 | ブログラミング

家紋シリーズ 梅(8) 向こう梅

include("plotter.jl")

function mukouume(; r=1, width=400, height=400)
    u = r/72
    plotbegin(w=width, h=height)
    for i = 18:72:306
        plotcircle(43u*cosd(i), 43u*sind(i), 28u, fcol=:black)
    end
    plotcircle(0, 0, 40u, fcol=:black)
    plotcircle(0, 0, 9u, col=:white, fcol=:white)
    plotcircle(0, 0, 7u * r, fcol=:black)
    d = 3
    for i = 6:12:354
        plotpolygon([40u*cosd(i), 9u*cosd(i-d), 9u*cosd(i+d)],
                    [40u*sind(i), 9u*sind(i-d), 9u*sind(i+d)],
                    col=:white, fcol=:white)
        plotcircle(40u*cosd(i), 40u*sind(i), u, col=:white, fcol=:white)
    end
    plotend()
end

mukouume()

コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

家紋シリーズ 梅(7) 八重梅,丸に八重梅

2021年08月29日 | ブログラミング

家紋シリーズ 梅(7) 八重梅,丸に八重梅

include("plotter.jl")

function yaeume(; r=1, width=400, height=400, maru=false)
    u = r/70
    ! maru && plotbegin(w=width, h=height)
    for i = 54:72:342
        plotcircle(46u*cosd(i), 46u*sind(i), 26u, fcol=:black)
    end
    for i = 18:72:306
        plotcircle(46u*cosd(i), 46u*sind(i), 27u, lwd=3,
                   col=:white, fcol=:black)
        R = sqrt(46^2-26^2) * r / 70
        xs = [0, R*cosd(54), R*cosd(18), 0]
        ys = [0, R*sind(54), R*sind(-18), 0]
        xs2 = copy(xs)
        ys2 = copy(ys)
        sine, cosine = sincosd(i+18)
        for j = 1:length(xs)
            xs2[j], ys2[j] = xs[j]cosine + ys[j]sine, xs[j]sine - ys[j]cosine
        end
        plotpolygon(xs2, ys2, fcol=:black)
    end
    for i = 18:72:306
        plotline(0, 0, 25u*cosd(i), 25u*sind(i), col=:white, lwd=4)
        plotline(0, 0, 40u*cosd(i+36), 40u*sind(i+36), col=:white, lwd=4)
    end
    plotcircle(0, 0, 12u, col=:white, fcol=:white)
    plotcircle(0, 0, 10u, fcol=:black)
    ! maru && plotend()
end

yaeume()

function maruniyaeume(; r=1, width=400, height=400)
    u = r/71
    plotbegin(w=width, h=height)
    plotcircle(0, 0, 71u, fcol=:black)
    plotcircle(0, 0, 60u, col=:white, fcol=:white)
    yaeume(r=0.8, maru=true)
    plotend()
end

maruniyaeume()

コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

家紋シリーズ 梅(6) 梅の花,丸に梅の花

2021年08月29日 | ブログラミング

家紋シリーズ 梅(6) 梅の花,丸に梅の花

include("plotter.jl")

function umenohana(; r=1, width=400, height=400, maru=false)
    u = r/70
    ! maru && plotbegin(w=width, h=height)
    for i = 18:72:306
        plotcircle(46u*cosd(i), 46u*sind(i), 26u, fcol=:black)
        R = sqrt(46^2-26^2)u
        xs = [0, R*cosd(54), R*cosd(18), 0]
        ys = [0, R*sind(54), R*sind(-18), 0]
        xs2 = copy(xs)
        ys2 = copy(ys)
        sine, cosine = sincosd(i+18)
        for j = 1:length(xs)
            xs2[j], ys2[j] = xs[j]cosine + ys[j]sine, xs[j]sine - ys[j]cosine
        end
        plotpolygon(xs2, ys2, fcol=:black)
    end
    for i = 18:72:306
        plotline(0, 0, 25u*cosd(i), 25u*sind(i), col=:white, lwd=4)
        plotline(0, 0, 50u*cosd(i+36), 50u*sind(i+36), col=:white, lwd=4)
    end
    plotcircle(0, 0, 12u, col=:white, fcol=:white)
    plotcircle(0, 0, 10u, fcol=:black)
    ! maru && plotend()
end

umenohana()

function maruniumenohana(; r=1, width=400, height=400)
    u = r/71
    plotbegin(w=width, h=height)
    plotcircle(0, 0, 71u, fcol=:black)
    plotcircle(0, 0, 60u, col=:white, fcol=:white)
    umenohana(r=0.8, maru=true)
    plotend()
end

maruniumenohana()

コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

家紋シリーズ 梅(5) 丸に剣梅鉢

2021年08月29日 | ブログラミング

家紋シリーズ 梅(5) 丸に剣梅鉢

include("plotter.jl")

function marunikenumebati(; r=1, width=400, height=400)
    u = r/70
    plotbegin(w=width, h=height)
    plotcircle(0, 0, r, fcol=:black)
    plotcircle(0, 0, 58/70*r, fcol=:white)
    x = [-20.33,-20.33,26.82,28.24,29.65,31.06,32.47,33.88,35.29,36.71,
         38.12,39.53,40.94,42.35,43.76,45.18,46.59,48.0,56.47,-20.33] .* u
    y = [0.0,2.16,2.16,2.16,2.22,2.27,2.57,2.98,3.38,3.92,4.6,5.38,
         6.36,7.5,8.79,10.28,11.99,13.91,0.0,0.0] .* u
    xs = vcat(x, reverse(x))
    ys = vcat(y, -reverse(y))
    for i = 54:72:400
        xs2 = copy(xs)
        ys2 = copy(ys)
        sine, cosine = sincosd(i)
        for j = 1:length(xs)
            xs2[j], ys2[j] = xs[j]cosine + ys[j]sine, xs[j]sine - ys[j]cosine
        end
        plotpolygon(xs2, ys2, fcol=:black)
    end
    for i = 18:72:306
        plotcircle(39u*cosd(i), 39u*sind(i), 17u, fcol=:black)
    end
    plotcircle(0, 0, 10u, col=:white, fcol=:white)
    plotcircle(0, 0, 8u, fcol=:black)
    plotend()
end

marunikenumebati()

コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

家紋シリーズ 梅(4) 丸に星梅鉢

2021年08月29日 | ブログラミング

家紋シリーズ 梅(4) 丸に星梅鉢

include("plotter.jl")

function marunihosiumebati(; r=1, width=400, height=400)
    u = r/70
    plotbegin(w=width, h=height)
    plotcircle(0, 0, r, fcol=:black)
    plotcircle(0, 0, 60u, fcol=:white)
    plotcircle(0, 0, 14u, fcol=:black)
    for i = 18:72:306
        plotcircle(37u*cosd(i), 37u*sind(i), 20.5u, fcol=:black)
    end
    plotend()
end

marunihosiumebati()

コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

家紋シリーズ 梅(3) 丸に梅鉢

2021年08月29日 | ブログラミング

家紋シリーズ 梅(3) 丸に梅鉢

include("plotter.jl")

function maruniumebati(; r=1, width=400, height=400)
    u = r/70
    plotbegin(w=width, h=height)
    plotcircle(0, 0, 70u, fcol=:black)
    plotcircle(0, 0, 58u, fcol=:white)
    plotpolygon2(0, 0, 18u, 5, φ=54, fcol=:black)
    plotcircle(0, 0, 10.5u, fcol=:white)
    for i = 0:36:324
        plotline(0, 0, 18u*cosd(i), 18u*sind(i), lwd=3, col=:white)
    end
    plotcircle(0, 0, 8.5u, fcol=:black)
    for i = 18:72:306
        plotcircle(36.2u*cosd(i), 36.2u*sind(i), 19.5u, fcol=:black)
    end
    plotend()
end

maruniumebati()

コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

家紋シリーズ 梅(2) 加賀梅鉢

2021年08月29日 | ブログラミング

家紋シリーズ 梅(2) 加賀梅鉢

include("plotter.jl")

function kagaumebati(; r=1, width=400, height=400)
    u = r/25
    plotbegin(w=width, h=height)
    plotpolygon2(0, 0, r, 5, φ=54, fcol=:black)
    plotcircle(0, 0, 16u, fcol=:white)
    for i = 0:36:324
        plotline(0, 0, r*cosd(i), r*sind(i), lwd=8, col=:white)
    end
    plotcircle(0, 0, 11u, fcol=:black)
    for i = 18:72:306
        plotcircle(48u*cosd(i), 48u*sind(i), r, fcol=:black)
    end
    plotend()
end

kagaumebati()

コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

家紋シリーズ 梅(1) 梅鉢

2021年08月29日 | ブログラミング

家紋シリーズ 梅(1) 梅鉢

include("plotter.jl")

function umebati(; r=1, width=400, height=400)
    u = r/23
    plotbegin(w=width, h=height)
    plotpolygon2(0, 0, 23u, 5, φ=54, fcol=:black)
    plotcircle(0, 0, 14u, fcol=:white)
    for i = 0:36:324
        plotline(0, 0, 23u*cosd(i), 23u*sind(i), lwd=3, col=:white)
    end
    plotcircle(0, 0, 12u, fcol=:black)
    for i = 18:72:306
        plotcircle(46u*cosd(i), 46u*sind(i), 25u, fcol=:black)
    end
    plotend()
end

umebati()

コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

PVアクセスランキング にほんブログ村

PVアクセスランキング にほんブログ村