# Scene polygon function browsing

• posted
0

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.

• posted
0

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

• posted
1

``````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)
``````

• posted
0

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

• posted
1

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.

• posted
0

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)?

• posted
0

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.

Internal error.

Oops! Looks like something went wrong!