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
-
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.
-
I really just need to draw 4 points, can I use
image_quad
somehow? -
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)
-
This is simple enough, but what about filling the polygon?
-
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. -
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)?
-
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.