I’m working on a little Pythonista module that mocks the DrawBot API atop the built in canvasmodule. I need to implement DrawBot’s BezierPath class since I use it a lot. I’ve tried using objc_util.ObjCClass to get a UIBezierPath, draw to it and then paint it, but it doesn’t display. I’ve also tried usingui.Path` With the same results. I’m obviously doing something very wrong. Does anyone have any tips? Any help would be greatly appreciated.
“””
Draw a white square containing
red, green and blue squares.
“””
import canvas
import ui
from objc_util import *
canvas.clear()
canvas.set_fill_color(1, 1, 1, 1)
canvas.fill_rect(0, 0, 150, 150)
# UIBezierPath
canvas.set_fill_color(1, 0, 0, 1)
path = ObjCClass("UIBezierPath").bezierPath()
path.moveToPoint_((0, 0))
path.lineToPoint_((0, 50))
path.lineToPoint_((50, 50))
path.lineToPoint_((50, 0))
path.closePath()
path.fill()
# ui.Path
canvas.set_fill_color(0, 1, 0, 1)
path = ui.Path()
path.move_to(50, 50)
path.line_to(50, 100)
path.line_to(100, 100)
path.line_to(100, 50)
path.close()
path.fill()
# canvas (sanity check)
canvas.set_fill_color(0, 0, 1, 1)
canvas.move_to(100, 100)
canvas.add_line(100, 150)
canvas.add_line(150, 150)
canvas.add_line(150, 100)
canvas.add_line(100, 100)
canvas.close_path()
canvas.fill_path()