見出し画像

刺し子模様をPythonで描く:笹りんどう

弧を3つ。たとえば次のようにとる。
半径が 2√3 の円を,中心 (-2,0) , ( √3 ,1 ) , ( -√3 ,1 ) として描いたときに,中央にできる形。3つの円の中心を結ぶと正三角形になる。

画像1

√3 を多用するので,sq3 = np.sqrt(3) として使うと楽。
弧を描く関数は,青海波のときに定義した。

# 基本パターンをorgを原点として描く
def basicpattern(org):
   pi = np.pi
   r = 2 * sq3
   drawarc(org+[0, -2], r, pi/3, 2*pi/3)
   drawarc(org+[sq3, 1], r, pi, 4*pi/3)
   drawarc(org+[-sq3, 1], r, 5*pi/3, 2*pi)

平行移動量は
Shiftx = np.array([2*sq3, 0])
Shifty = np.array([sq3, 3])

たいした量ではないので,全体を載せておこう。

import numpy as np
import matplotlib.pyplot as plt
plt.figure(figsize=(12, 6))
plt.axis([10, 40, 0, 15])
plt.xticks([]) # 目盛を非表示にする 
plt.yticks([])
# 横方向にm,縦方向にn個のパターンを描く
def drawpattern(m, n):
   for x in range(m):
       for y in range(n):
           org = x*Shiftx + y*Shifty
           basicpattern(org)
# 弧を描く 引数は 中心,半径,描き始めと描き終わりの角
def drawarc(center, r, st, en):
   t = np.linspace(st, en, 100)
   x = r * np.cos(t)+center[0]
   y = r * np.sin(t)+center[1]
   plt.plot(x, y, lw=1, color=Drawcolor)
   
# 基本パターンをorgを原点として描く
def basicpattern(org):
   pi = np.pi
   r = 2 * sq3
   drawarc(org+[0, -2], r, pi/3, 2*pi/3)
   drawarc(org+[sq3, 1], r, pi, 4*pi/3)
   drawarc(org+[-sq3, 1], r, 5*pi/3, 2*pi)
sq3 = np.sqrt(3)
# 横方向のシフト量,縦方向のシフト量,描画色を定義して描く
Shiftx = np.array([2*sq3, 0])
Shifty = np.array([sq3, 3])
Drawcolor = 'k'
drawpattern(12, 8)
plt.savefig("sasarindou1.png")
plt.show()