簡単な問題: Python の ImageDraw モジュールを使用して、(x1, y1) と (x2, y2) の間に 1 ピクセルより大きい太さまたは幅の線を描画します。
2322 次
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))
これがこのテクニックの結果です。文字盤を構成する各セグメントは、「太い線」技法を使用して描かれています。
編集:これは、Python で「太い線」関数の検索を開始した議論です (私が書いた完全なスクリプトも含まれています):
http://gimpforums.com/thread-how-to-draw-this-geometric-pattern-programmatically
于 2013-11-14T19:21:04.530 に答える