生成各种矢量形状(如直线、矩形等)的x、y坐标的python生成器模块,以线算法fame的bresenham命名。
PyBresenham的Python项目详细描述
生成各种矢量形状(如直线、矩形等)的x、y坐标的python生成器模块,以线算法fame的bresenham命名。
例如:
>>> import pybresenham >>> pybresenham.line(0, 0, 3, 6) <generator object line at 0x00000000030923B8> >>> list(pybresenham.line(0, 0, 3, 6)) [(0, 0), (0, 1), (1, 2), (1, 3), (2, 4), (2, 5), (3, 6)]
皮布雷森姆目前正在开发中,正在寻找贡献者!
安装
^{tt1}$
快速入门指南
获取从(0,0)到(5,10)的直线点:
>>> import pybresenham >>> for x, y in pybresenham.line(0, 0, 5, 10): ... print('(%s, %s)' % (x, y)) ... (0, 0) (0, 1) (1, 2) (1, 3) (2, 4) (2, 5) (3, 6) (3, 7) (4, 8) (4, 9) (5, 10) >>> list(pybresenham.line(0, 0, 5, 10)) [(0, 0), (0, 1), (1, 2), (1, 3), (2, 4), (2, 5), (3, 6), (3, 7), (4, 8), (4, 9), (5, 10)]
获取从(0,0)到(2,0)到(2,2)的多行点:
>>> import pybresenham >>> list(pybresenham.lines([(0, 0), (2, 0), (2, 2)])) [(0, 0), (1, 0), (2, 0), (2, 1), (2, 2)]
获取以(0,0)为中心、半径为3的圆的点:
>>> list(pybresenham.circle(0, 0, 3)) [(0, -3), (3, 0), (0, 3), (1, -3), (3, -1), (3, 1), (-1, 3), (-3, -1), (-3, 1), (-1, -3), (1, 3), (2, -2), (2, 2), (-2, 2), (-2, -2)]
快速绘制上述圆圈:
>>> import pybresenham >>> pybresenham._drawPoints(pybresenham.circle(0, 0, 3), bg=' ') OOO O O O O O O O O O O OOO
快速绘制正方形和矩形:
>>> import pybresenham >>> list(pybresenham.square(0, 0, 4)) [(0, 0), (1, 0), (2, 0), (3, 0), (3, 1), (3, 2), (3, 3), (2, 3), (1, 3), (0, 3), (0, 2), (0, 1)] >>> pybresenham._drawPoints(pybresenham.square(0, 0, 4), bg=' ') OOOO O O O O OOOO >>> pybresenham._drawPoints(pybresenham.rectangle(0, 0, 15, 4), bg=' ') OOOOOOOOOOOOOOO O O O O OOOOOOOOOOOOOOO>>> drawPoints(polygon(10, 10, 8, 5), bg=' ') O O O O OO O O OO O O O O O O O O O O O O O O O O O O O OOOOOOOOO>>> drawPoints(polygon(10, 10, 8, 5, rotationDegrees=20), bg=' ') OO O OOO O OO O OO O O O O O O O O O O O O O O O OO O OO O OOO OO
路线图
以下功能尚未实现:
- ellipse()
- ellipseVertices()
- arc()
- arcVertices()
- star()
- starVertices()
- hexGrid()
- hexGridVertices()
- hexGridInterior()
- bezier()
- bezierVertices()
- roundedBox()
- roundedBoxVertices()
thickness、filled、endcap和viewport参数仍未实现。(除了square()和rectangle(),它们实现了filled参数。)