draw ui.Path within the coordinate system of a node
I do not really understand how the frame of an
ui.Pathobject works. If have cooked up a small scene that illustrates the problems I have. I am trying to draw an
ui.Paththat is matching points (coordinates) in the frame of a node. It seems that an
ui.Pathis always being centered on the center of the presenting
So my question is: How do I draw a path which is not centered on the center of its presenting
ShapeNode- for example one that only lives in the x+y+ frame ? I would like to be able to actually draw within the coordinates system/frame of the presenting ShapeNode .
from scene import * class MyScene (Scene): def setup(self): sx, sy = self.size.w * .5, self.size.h * .5 # I would expect the white rect to have its lower left corner # at the center of the screen. But it does not, it is sitting # on the origin of the node, x and y seem to have no effect. self.white = ShapeNode(ui.Path.rect(sx, sy, 200, 200), parent=self, position=(0, 0)) # a reference rect as our white rect is kinda off screen self.red = ShapeNode(ui.Path.rect(0, 0, 150, 150), parent=self, fill_color = 'red', position=(sx, sy)) # Here I would expect a line from the right top corner # of the red rect going to a point (25, 50) in the # top right direction. But again the path is centered # on the node and also the y coordinate is being inverted. path = ui.Path() path.move_to(75, 75) path.line_to(sx + 100, sy + 125) path.line_width = 3 self.cyan = ShapeNode(path, parent=self.red, stroke_color='cyan', position=(0, 0)) if __name__ == '__main__': run(MyScene(), show_fps=False)```
Thx cvp but I don’t know how to download a module into Pythonista
@mikeno use, and keep for the future, this script
import requests import os url = 'https://raw.githubusercontent.com/mikaelho/pythonista-gestures/master/gestures.py' response = requests.get(url) content = str(response.content.decode('utf-8')) file_path = os.path.expanduser('~/Documents/site-packages/gestures.py') with open(file_path,mode='wt',encoding='utf-8') as fil: fil.write(content)
Super, thank you
content = str(response.content.decode('utf-8'))
text = response.text
@ccc you're right here with a script but I'm sure that I had to use decode in the past for some web page containing special characters...But never mind, your code is better.
@mikeno, your script did not redraw on touch because your method did not get called with the drawing context that
drawdoes. To make it work, trigger the
For installing stuff, recommend taking the time to install stash, for
But keep @cvp’s install script around, most of the little things we build do not end up in pip/PyPI.
To make it work, trigger the draw with self.set_needs_display().
Forgotten, halala this too old memory 😢
I do have a follow up question though. Is it possible to access the points of a path after it has been created? edit: and with access I mean read them.
@rajputaman04, unfortunately no.