justvanrossum / drawbot-skia

A cross-platform subset of the DrawBot drawing API, using Skia
Apache License 2.0
77 stars 8 forks source link

functions not possible? #62

Closed joachimheintz closed 2 years ago

joachimheintz commented 2 years ago

i cannot get functions to use, for instance:

def myline(x1,y1,x2,y2): line((x1,x2),(y1,y2))

size(700,250) myline(100,100,200,50)

no error, but also no output.

i also tried different variants, like:

def myline(x1,y1,x2,y2): path = BezierPath() path.line((x1,y1),(x2,y2)) path.closePath() drawPath(path)

am i missing anything, or is this simply not supposed to work?

justvanrossum commented 2 years ago

You have to set the stroke color: for example stroke(1, 0, 0)

joachimheintz commented 2 years ago

this does not change it for me. for instance, i have put the tests/apitests/arc.py example in a function like this:

def myArc(): path = BezierPath() path.moveTo((100, 100)) path.arc((100, 100), 80, 230, 170, False) path.arc((100, 100), 60, 30, 120, True) path.closePath() stroke(0) fill(None) strokeWidth(4) drawPath(path)

but when i call it i get no output:

size(700,250) myArc()

justvanrossum commented 2 years ago

How do you run the script?

It works for me if I call it like this:

$ drawbot test.py test.png
def myArc():
    path = BezierPath()
    path.moveTo((100, 100))
    path.arc((100, 100), 80, 230, 170, False)
    path.arc((100, 100), 60, 30, 120, True)
    path.closePath()
    stroke(0)
    fill(None)
    strokeWidth(4)
    drawPath(path)

# but when i call it i get no output:

size(700,250)
myArc()
joachimheintz commented 2 years ago

ah yes now i see that it is a problem of my workflow. of course i have to write the function in the file, too, rather than just having it in my python environment ... thanks for the quick help!