How to add two shapes
janaaron97 last edited by
I'm trying to use the example program that discusses the gravity() function in Pythonista to learn the "scene" library.
What I want to do is have a square and a circle move around on the screen when I tilt the phone, at the same time. However, right now, there is only one shape.
How do I get both shapes to move on the screen?
Heres the code
from scene import * class dumb (Scene): def setup(self): self.x = self.size.w * 0.5 self.y = self.size.h * 0.5 def draw(self): background(0.00, 0.00, 0.00) fill(1.00,1.00,1.00) g = gravity() self.x += g.x * 10 self.y += g.y * 10 self.x = min(self.size.w - 100, max(0, self.x)) self.y = min(self.size.h - 100, max(0, self.y)) ellipse(self.x,self.y,100,100) class real (Scene): def setup(self): self.x = self.size.w * 0.4 self.y = self.size.h * 0.4 def draw(self): background(0.00, 0.00, 0.00) fill(1.00,1.00,1.00) g = gravity() self.x += g.x * 10 self.y += g.y * 10 self.x = min(self.size.w - 100, max(0, self.x)) self.y = min(self.size.h - 100, max(0, self.y)) rect(self.x,self.y,100,100) run(dumb()) run(real())
ccc last edited by
- Put both shapes into ONE scene.
- Search this forum for multiscene
- Check out chained scenes http://omz-forums.appspot.com/pythonista/post/5876387541942272
janaaron97 last edited by
How do I put both shapes into the same scene?
zencuke last edited by
Put the ellipse and rect commands after each other in the draw method of the same class. Delete the other class.
You shouldn't post the same question a second time.
wradcliffe last edited by
@janaaron97 - your original posting just says that you want to simply draw these two objects on the screen and have them both react to gravity. If that is true then you have gone down the wrong path by creating two scenes. You stumbled onto a gravity example that seems to be using Scene to represent a single object to be drawn. Scenes are much more then that and this was done just to keep the code as simple as possible. Scenes are the objects that handle the whole display. You are allowed have more than one of these in a script, but doing so is only for unusual use cases. For what you say you want to do, the normal pattern would be to create objects to represent the circle and the ellipse and then simply draw each of these objects from within the same Scene.draw method. The system also supports the concept of Layers that are specifically designed to make it easy to draw multiple objects but also to animate them. There are many many examples and tutorials on this that you can find by searching the forum. You should also grab this repo scene tutorials and educate yourself on what is possible.