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.


    Scene polygon function

    Pythonista
    3
    7
    3504
    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.
    • Webmaster4o
      Webmaster4o last edited by Webmaster4o

      How do I create a polygon from a list of points in scene? Like the function in PIL.ImageDraw? I'm trying to port the spinning cube I posted in Gif Art in Python to scene. It uses the polygon function in PIL. I've tried drawing images and then displaying them in my scene, but this is VERY slow.

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

        I really just need to draw 4 points, can I use image_quad somehow?

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

          import scene
          
          class MyScene (scene.Scene):
              def __init__(self, points):
                  self.points = points
                  scene.run(self)
                  scene.stroke(0, 1, 0)
                  scene.stroke_weight(4)
          
              def draw(self):
                  scene.background(0.0, 0.2, 0.3)
                  for point in self.points:
                      scene.line(*point)
                  
          lines = ((50, 50, 150, 50),
                      (150, 50, 150, 150),
                      (150, 150, 50, 150),
                      (50, 150, 50, 50))
          
          MyScene(lines)
          
          1 Reply Last reply Reply Quote 1
          • Webmaster4o
            Webmaster4o last edited by

            This is simple enough, but what about filling the polygon?

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

              While ui and canvas include Paths that can be filled, scene does not.
              If you need a simple parallelogram, you could use rotate folled by scale. You would have to work out the math.

              1 Reply Last reply Reply Quote 1
              • ccc
                ccc last edited by

                Could we please see some benchmarks that prove that drawing images with PIL is VERY slow? Are you on Pythonista v1.5 (PIL) or v1.6 beta (Pillow)?

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

                  Only tested on 1.5. However, just found a solution for my specific case. My scene now looks like

                  # coding: utf-8
                  import scene
                  from PIL import Image
                  
                  class Polygon(scene.Scene):
                  	def setup(self):
                  		self.color = '#abcdef'
                  		self.coords = (170,120,120,120,170,190,130,200)
                  	def draw(self):
                  		color = scene.load_pil_image(Image.new('RGBA', (10,10), self.color))
                  		scene.image_quad(color, *self.coords)
                  scene.run(Polygon())
                  

                  A functional example is here.

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