def get_arrow_im(pt, fColor=Color(0.0, 0.0, 0.0), arrowWidth=3.0):
x, y = pt.x(), pt.y()
sz = int(np.ceil(max(abs(x), abs(y))))
data = np.zeros((sz, sz, 4), dtype=np.uint8)
surface = cairo.ImageSurface.create_for_data(data,
cairo.FORMAT_ARGB32, sz, sz)
cr = cairo.Context(surface)
#Create a transparent source
cr.set_source_rgba(1.0, 1.0, 1.0, 0.0)
cr.paint()
#Start making the arrow
cr.set_source_rgba(fColor.b, fColor.g, fColor.r, fColor.a)
if x>=0 and y>=0:
xSt, ySt = 0, 0
elif x>0 and y < 0:
xSt, ySt = 0, sz
elif x <0 and y<0:
xSt, ySt = sz, sz
else:
xSt, ySt = sz, 0
stPoint = gm.Point(xSt, ySt)
cr.move_to(xSt, ySt)
pt = pt + stPoint
dirVec = pt - stPoint
mag = dirVec.mag()
cr.line_to(pt.x(), pt.y())
cr.set_line_width(arrowWidth)
side1 = dirVec.rotate_point(-150)
side1.scale(0.2)
ang1 = pt + side1
cr.line_to(ang1.x(), ang1.y())
side2 = dirVec.rotate_point(150)
side2.scale(0.2)
ang2 = pt + side2
cr.move_to(pt.x(), pt.y())
cr.line_to(ang2.x(), ang2.y())
cr.stroke()
return cr, data, stPoint
评论列表
文章目录