简单问题:在Python中使用ImageDraw模块,在(x1,y1)和(x2,y2)之间画一条线,其厚度或宽度大于1像素。
答案 0 :(得分: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))
这是这种技术的结果。构成表盘的分段均使用“粗线”技术绘制。
编辑:这是我在Python中搜索“粗线”函数的讨论(也包含我写的完整脚本):
http://gimpforums.com/thread-how-to-draw-this-geometric-pattern-programmatically