omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Canvas and UIBezierPath

    Pythonista
    2
    3
    1226
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • typesupply
      typesupply last edited by

      I’m working on a little Pythonista module that mocks the DrawBot API atop the built in canvas module. 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 using ui.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()
      
      1 Reply Last reply Reply Quote 0
      • ccc
        ccc last edited by ccc

        https://forum.omz-software.com/search/UIBezierPath

        1 Reply Last reply Reply Quote 0
        • typesupply
          typesupply last edited by

          Thanks. I read through those before posting, but didn’t see anything about using UIBezierPath with canvas. Those posts all seemed to be about working with ui. I used canvas because it’s a static 2D context like the one in DrawBot. Are you suggesting that it would be better to build atop ui instead of canvas? I just looked back through the ui docs and it looks like I could build a custom DrawBotView that presents the output image. (This post is helpful.)

          Thanks again for the help. I’ve done tons of PyObjC work on the Mac and have used Pythonista on my iPad for a few years, but this is the first time I’m trying to do anything *visual *with Pythonista. I’m just trying to get some code development visualization working across devices... :)

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors