0

Simple problem: Using the ImageDraw module in Python, draw a line between (x1, y1) and (x2, y2) with a thickness or width larger than 1 pixel.

4

1 回答 1

2

引用实际脚本,仅显示实际参与绘制粗线的部分:

from PIL import Image, ImageDraw
import math

x1 = 100
y1 = 100
x2 = 200
y2 = 175

# thickness of line
thick = 4

# compute angle
a = math.atan((y2-y1)/(x2-x1))
sin = math.sin(a)
cos = math.cos(a)
xdelta = sin * thick / 2.0
ydelta = cos * thick / 2.0
xx1 = x1 - xdelta
yy1 = y1 + ydelta
xx2 = x1 + xdelta
yy2 = y1 - ydelta
xx3 = x2 + xdelta
yy3 = y2 - ydelta
xx4 = x2 - xdelta
yy4 = y2 + ydelta
draw.polygon((xx1, yy1, xx2, yy2, xx3, yy3, xx4, yy4))

这是这种技术的结果。组成表盘的各个部分均使用“粗线”技术绘制。

拨号.png

编辑:这是引发我在 Python 中搜索“粗线”函数的讨论(还包含我编写的完整脚本):

http://gimpforums.com/thread-how-to-draw-this-geometric-pattern-programmatically

于 2013-11-14T19:21:04.530 回答