• WannabeMaker

    @chriswilson Thank you, Chris - I will check it out. I appreciate your help.

    posted in Pythonista read more
  • WannabeMaker

    @JonB Thank you - that's perfect. And, as with all the best code, totally obvious in retrospect. Much appreciated!

    posted in Pythonista read more
  • WannabeMaker

    Very newbie question - apologies if there's obvious documentation on this; I haven't found it.

    Ultimately, my code should draw a line segment starting at a specific coordinate on the screen (x, y) and ending at an offset (x + dx, y + dy). Importantly, dx and dy can be positive or negative. It will then change color over time, so I'd like to use a scene.ShapeNode that I can animate.

    For starters, I'm testing by creating a line segment that starts at my touch point. However, getting the line to start at the touch point seems only to work with a somewhat unwieldy set of conditions to set the anchor_point (see below). I think this is because of the way the ShapeNode bounding rectangle, and therefore its coordinate system, changes as the size of the shape changes.

    Is there some smarter, cleaner, more elegant way to get this done?

    For bonus points, am I right in thinking that the +y direction for a Sprite is down, but the y coordinate of a touchPosition increases as you go up the screen? Thoughts on why?

    def drawSeg(self, touchPosition):
        segPath = ui.Path()
        segPath.move_to(0, 0)
        dx = randint(-100, 100)
        dy = randint(-100, 100)
        segPath.line_to(dx, dy)
        seg = ShapeNode(path = segPath, position = touchPosition)
        seg.stroke_color = (255,255,255)
        seg.fill_color = "clear"
        if dx >= 0:
            if dy >= 0:
                    seg.anchor_point = (0, 1)
            else:
                seg.anchor_point = (0, 0)
        else:
            if dy >= 0:
                seg.anchor_point = (1, 1)
            else:
                seg.anchor_point = (1, 0)
                    
        self.add_child(seg)
    
    

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!