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.
How do I do to play the movements registered in the scene?
-
Hi all,
After recording the movement of the finger on the screen... How do I do to play the movements registered in the scene?Cheers
My (naive) code:
import scene # for recording x and y... pointX = [] pointY = [] class MyScene(scene.Scene): def __init__(self, in_dot_color=scene.Color(0, 0, 0, 1)): super().__init__() self.dot_color = in_dot_color self.touch = None def draw(self): scene.background(0, 0, 0) if self.touch: scene.fill('red') x, y = self.touch.location scene.ellipse(x - 50, y - 50, 100, 100) scene.text(str(x) + ', ' + str(y), 'Futura', 20, 100, 50) pointX.append(x) pointY.append(y) def touch_began(self, touch): pointX.clear() pointY.clear() self.touch = touch def touch_moved(self, touch): self.touch = touch def touch_ended(self, touch): self.touch = None scene.run(MyScene(), show_fps=True)
-
Ideas...
import scene # for recording x and y... points = [] class MyScene(scene.Scene): def __init__(self, in_dot_color=scene.Color(0, 0, 0, 1)): super().__init__() self.dot_color = in_dot_color self.touch = None def draw(self): scene.background(0, 0, 0) if self.touch: scene.fill('red') loc = self.touch.location scene.ellipse(loc.x - 50, loc.y - 50, 100, 100) scene.text('{}, {}'.format(*loc), 'Futura', 20, 100, 50) points.append(loc) # is it be useful to check if loc == prev_loc? elif points: scene.fill('blue') for loc in points: scene.ellipse(loc.x - 50, loc.y - 50, 100, 100) def touch_began(self, touch): points.clear() self.touch = touch def touch_moved(self, touch): self.touch = touch def touch_ended(self, touch): self.touch = None scene.run(MyScene(), show_fps=True)
-
Hi, thank you ccc...
my intention was to circle to scour the home path to end, but no wake, i.e. see the circle in motion following the route drawn.
Cheers,
David -
Any idea?... :)
-
are you trying to replay with the same timing as the original? In that case, you would need to store a list of touches, which includes a timestamp, then in your scene update method you would need to find the nearest time in the list and draw that circle.
or iirc there are also some animation nodes that you could program to interpolate. but maybe start with just recording and playing back touches, then can work on smoothing it out if needed.
-
You migt want to take a look at Sprite or ShapeNode, and use an Action.Sequence, consisting of Action.move_to's based on the recorded timing. That way you just specify the x,y and time to the next point, and scene takes care of doing it smoothly.
-
You could omit the repeat_forever, but it creates a fun effect, where you can have multiple spots repeating at once. But you should get the idea here...
import scene,ui class MyScene(scene.Scene): def __init__(self, in_dot_color=scene.Color(0, 0, 0, 1)): super().__init__() self.dot_color = in_dot_color self.touch = None self.points=[] self.timing=[] def draw(self): ''' real time drawing only''' scene.background(0, 0, 0) if self.touch: scene.fill(self.spot_color) loc = self.touch.location scene.ellipse(loc.x - 50, loc.y - 50, 100, 100) scene.text('{}, {}'.format(*loc), 'Futura', 20, 100, 50) def touch_began(self, touch): '''register initial point and time''' self.points=[touch] self.timing=[0] self.touch = touch self.t0=self.t loc=touch.location self.spot_color=(loc.x/self.bounds.width, loc.y/self.bounds.height, .5) def touch_moved(self, touch): '''Record points and relative timing ''' self.touch = touch self.points.append(touch) self.timing.append(self.t-self.t0) def touch_ended(self, touch): '''instantiate a shapenode, and animate it''' self.touch = None self.spot=scene.ShapeNode(path=ui.Path.oval(0,0,100,100),parent=self) self.spot.fill_color=self.spot_color self.spot.position=self.points[0].location actions=[] for i in range(len(self.points)-1): duration=self.timing[i+1]-self.timing[i] loc=self.points[i].location actions.append(scene.Action.move_to(*loc,duration)) self.spot.run_action(scene.Action.repeat_forever(scene.Action.sequence(actions))) s=MyScene() scene.run(s, show_fps=True)