diff options
author | cinap_lenrek <cinap_lenrek@localhost> | 2011-05-03 11:25:13 +0000 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@localhost> | 2011-05-03 11:25:13 +0000 |
commit | 458120dd40db6b4df55a4e96b650e16798ef06a0 (patch) | |
tree | 8f82685be24fef97e715c6f5ca4c68d34d5074ee /sys/src/cmd/python/Demo/tkinter/matt/pong-demo-1.py | |
parent | 3a742c699f6806c1145aea5149bf15de15a0afd7 (diff) |
add hg and python
Diffstat (limited to 'sys/src/cmd/python/Demo/tkinter/matt/pong-demo-1.py')
-rw-r--r-- | sys/src/cmd/python/Demo/tkinter/matt/pong-demo-1.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/sys/src/cmd/python/Demo/tkinter/matt/pong-demo-1.py b/sys/src/cmd/python/Demo/tkinter/matt/pong-demo-1.py new file mode 100644 index 000000000..7fcf800b6 --- /dev/null +++ b/sys/src/cmd/python/Demo/tkinter/matt/pong-demo-1.py @@ -0,0 +1,54 @@ +from Tkinter import * + +import string + + +class Pong(Frame): + def createWidgets(self): + self.QUIT = Button(self, text='QUIT', foreground='red', + command=self.quit) + self.QUIT.pack(side=LEFT, fill=BOTH) + + ## The playing field + self.draw = Canvas(self, width="5i", height="5i") + + ## The speed control for the ball + self.speed = Scale(self, orient=HORIZONTAL, label="ball speed", + from_=-100, to=100) + + self.speed.pack(side=BOTTOM, fill=X) + + # The ball + self.ball = self.draw.create_oval("0i", "0i", "0.10i", "0.10i", + fill="red") + self.x = 0.05 + self.y = 0.05 + self.velocity_x = 0.3 + self.velocity_y = 0.5 + + self.draw.pack(side=LEFT) + + def moveBall(self, *args): + if (self.x > 5.0) or (self.x < 0.0): + self.velocity_x = -1.0 * self.velocity_x + if (self.y > 5.0) or (self.y < 0.0): + self.velocity_y = -1.0 * self.velocity_y + + deltax = (self.velocity_x * self.speed.get() / 100.0) + deltay = (self.velocity_y * self.speed.get() / 100.0) + self.x = self.x + deltax + self.y = self.y + deltay + + self.draw.move(self.ball, "%ri" % deltax, "%ri" % deltay) + self.after(10, self.moveBall) + + def __init__(self, master=None): + Frame.__init__(self, master) + Pack.config(self) + self.createWidgets() + self.after(10, self.moveBall) + + +game = Pong() + +game.mainloop() |