3
现在我有一个叫做Hexagon(x,y,n)的函数,它将在python窗口中绘制一个以(x,y)为中心且边长为n的六边形。在Python中绘制六边形镶嵌动画
我的目标是绘制镶嵌动画将在屏幕中心画陆续六角一个接一个展开一个(如右图我这里附http://s7.postimage.org/lu6qqq2a3/Tes.jpg)。
我正在寻找解决此问题的算法。编程新手,我发现很难做到这一点。
谢谢!
现在我有一个叫做Hexagon(x,y,n)的函数,它将在python窗口中绘制一个以(x,y)为中心且边长为n的六边形。在Python中绘制六边形镶嵌动画
我的目标是绘制镶嵌动画将在屏幕中心画陆续六角一个接一个展开一个(如右图我这里附http://s7.postimage.org/lu6qqq2a3/Tes.jpg)。
我正在寻找解决此问题的算法。编程新手,我发现很难做到这一点。
谢谢!
对于六边形的环可以定义一个函数是这样的:
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)
非常感谢!这非常有帮助。 – user2063057 2013-02-17 23:31:50