how to inegrate own functions #81
-
what is the proper way to work with own functions in drawSvg? import drawSvg as dw
def mySquare(x1,x2,y1,y2,**args):
p = dw.Path()
p.append(dw.Line(x1,y1,x2,y2,**args))
return p
d = dw.Drawing(842,595,displayInline=False)
l = mySquare(100,200,300,400,stroke='green')
d.append(l)
d but it throws this error: thanks in advance for help or examples - |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Your use of a function is not the issue. See this example for how to use |
Beta Was this translation helpful? Give feedback.
-
thanks for your answer and the help! this makes perfect sense.
i am wondering what is the best way to write functions like this. i
tried to append to the drawng inside the function, and set the
draw.Drawing ID as default to 'd', but this does not work. it works
when i set it explicitely, but i am wondering whether there is a better
way to do it?
import drawSvg as dw
def note(x,y,h=10,dir=1,id=d,**args):
x_rad = h*0.7
y_rad = h*0.45
x_pnt = x + h*0.67*dir
y_pnt = y + h*0.17*dir
l_pnt = h*2.5*dir
id.append(dw.Ellipse(x,y,x_rad,y_rad,transform='rotate(-22,%f,%f)'%(x,-y),**args))
id.append(dw.Line(x_pnt,y_pnt,x_pnt,y_pnt+l_pnt,stroke='black'))
d = dw.Drawing(200,300,displayInline=False)
l = note(100,200,20,id=d,stroke='green') # does not work without the
explicit id=d
d.append(l)
d
…On 15/12/2022 20:53, Casey Duckering wrote:
Your use of a function is not the issue. |Path| cannot contain other
drawing elements. You must use the special "path commands" like |p.M(x,
y)| or |p.L(x, y)|.
See this example for how to use |drawSvg.Path|:
https://github.com/cduck/drawsvg#basic-drawing-elements
<https://github.com/cduck/drawsvg#basic-drawing-elements>
How to use SVG paths:
https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths
<https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths>
—
Reply to this email directly, view it on GitHub
<#81 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAQYHKX6MXNYLCDVWP7PTTLWNNZMJANCNFSM6AAAAAAS76IE2Y>.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
Your use of a function is not the issue.
Path
cannot contain other drawing elements. You must use the special "path commands" likep.M(x, y)
orp.L(x, y)
.See this example for how to use
drawSvg.Path
: https://github.com/cduck/drawsvg#basic-drawing-elementsHow to use SVG paths: https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths