用Python绘制六边形镶嵌动画

use*_*057 5 algorithm animation hexagonal-tiles python-2.7

现在我有一个名为 Hexagon(x,y,n) 的函数,它将在 python 窗口中绘制一个以 (x,y) 为中心、边长为 n 的六边形。

我的目标是绘制一个镶嵌动画,该动画将从屏幕中心一个接一个地绘制六边形,并一个接一个地展开(如我在此处附上的图片http://s7.postimage.org/lu6qqq2a3/Tes.jpg)。

我正在寻找解决这个问题的算法。我刚接触编程,发现很难做到这一点。

谢谢!

cop*_*roc 3

对于六边形环,可以定义如下函数:

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

然后我们可以一个接一个地画一个环:

\n\n
Hexagon(0,0,10)\nHexagonRing(0,0,10,1)\nHexagonRing(0,0,10,2)\nHexagonRing(0,0,10,3)\n
Run Code Online (Sandbox Code Playgroud)\n