4

今、私は Hexagon(x,y,n) と呼ばれる関数を持っています。これは、(x,y) を中心とし、Python ウィンドウで辺の長さが n の六角形を描画します。

私の目標は、画面の中心から六角形を次々と描画し、1 つずつ広げるテッセレーション アニメーションを描画することです(ここに添付した図としてhttp://s7.postimage.org/lu6qqq2a3/Tes.jpg)。

この問題を解決するアルゴリズムを探しています。プログラミングは初めてで、それを行うのは難しいと感じました。

ありがとう!

4

1 に答える 1

2

六角形のリングの場合、次のような関数を定義できます。

def HexagonRing(x,y,n,r):
    dc = n*math.sqrt(3) # distance between to neighbouring hexagon centers
    xc,yc = x,y-r*dc # hexagon center of one before first hexagon (=last hexagon)
    dx,dy = -dc*math.sqrt(3)/2,dc/2 # direction vector to next hexagon center
    for i in range(0,6):
        # draw r hexagons in line
        for j in range(0,r):
            xc,yc = xc+dx,yc+dy
            Hexagon(xc,yc,n)
        # rotate direction vector by 60°
        dx,dy = (math.cos(math.pi/3)*dx+math.sin(math.pi/3)*dy,
               -math.sin(math.pi/3)*dx+math.cos(math.pi/3)*dy)

次に、リングを次々に描画できます。

Hexagon(0,0,10)
HexagonRing(0,0,10,1)
HexagonRing(0,0,10,2)
HexagonRing(0,0,10,3)
于 2013-02-17T19:43:54.580 に答える