Hi, a couple of months ago, I made a xmas chistmas "card" to this community( http://www.thescripts.com/forum/thread580722.html) Now its soon easter, and I hacked together something for easter as well.... -
import Tkinter
-
import random
-
import colorsys
-
import time
-
-
# Happy easter 2007 folks! from kudos@spray.no
-
-
playerx=170
-
bar = 0
-
ball = 0
-
ballvx = ballvy = 0.1
-
ballx = 200;
-
bally = 150;
-
-
def motion(event):
-
global playerx
-
playerx = event.x
-
if(playerx < 400-60):
-
w.coords(bar,playerx,250,playerx+60,250)
-
root = Tkinter.Tk()
-
w = Tkinter.Canvas(root, width=400, height=300, background="#000000")
-
w.bind("<Motion>", motion)
-
ball = w.create_oval(ballx-3,bally-3,ballx+3,bally+3,fill="#cccccc") # ball
-
blocks = []
-
k = 0.0
-
for j in range(10):
-
for i in range(10):
-
c = colorsys.hsv_to_rgb(k,0.5,0.4)
-
d = hex(int(c[0]*256)<<16 | int(c[1]*256)<<8 | int(c[2]*256));
-
d = "#"+d[2:len(d)]
-
k+=0.01
-
blocks.append(w.create_rectangle(40*i,(j*10)+10,40+(40*i),20+(j*10),fill=d))
-
bar = w.create_line(playerx,250,playerx+60,250,fill="#ffffff")
-
w.pack()
-
try:
-
while 1:
-
w.coords(ball,ballx-3,bally-3,ballx+3,bally+3)
-
if(ballx+ballvx > 400 or ballx+ballvx < 0):
-
ballvx*=(-1)
-
if(bally+ballvy < 0):
-
ballvy*=(-1)
-
for block in blocks:
-
crash = 0
-
co = w.coords(block)
-
if(ballx+ballvx > co[0] and ballx+ballvx < co[2] and bally > co[1] and bally < co[3]):
-
crash=1
-
ballvx*=(-1)
-
if(ballx > co[0] and ballx < co[2] and bally+ballvy > co[1] and bally+ballvy < co[3]):
-
crash=1
-
ballvy*=(-1)
-
if(crash == 1):
-
w.coords(block,-10,-10,-20,-20)
-
if( (bally > 248 and bally < 250) and (ballx > playerx and ballx < playerx + 60)):
-
ballvy*=-1
-
if(bally > 406):
-
ballvy = ballvx = 0.1
-
ballx = 200
-
bally = 150
-
ballx+=ballvx
-
bally+=ballvy
-
root.update_idletasks()
-
root.update()
-
except Tkinter.TclError:
-
pass
-
Note, I didn't include any kind of timer for this application, so if its slow/fast then increase/decrease ballvx and ballvy (or even better, write some code than handles timing :-)
-kudos
0 1125 Sign in to post your reply or Sign up for a free account.
Similar topics
by: eesun |
last post by:
Hi,
I've downloaded the dislin package for the scientific plotting. And I
have already created the application window with Tkinter (menu,
canvas, status bar..). I want to integrate the Dislin...
|
by: Tim Jarman |
last post by:
Apologies in advance for the long post - I wanted to be sure I included all
the relevant details. The answer is probably very, very simple.
I am doing something stupid here, but I don't know what...
|
by: jimfortune |
last post by:
From:
http://groups-beta.google.com/group/comp.databases.ms-access/msg/769e67e3d0f97a90?hl=en&
Errata:
19 solar years = 2939.6018 days should be
19 solar years = 6939.6018 days
Easter...
|
by: Gustavo G. Rondina |
last post by:
It is possible to caclulate every year's easter using simple
mathematical operations. Here is a code that does the trick:
http://www.brlivre.org/c/easter.c
I found the math scheme in an...
|
by: Jorge |
last post by:
Hi
I wish You all an happy easter hollidays.
Jorge
|
by: Thomas Ploch |
last post by:
Hello folks,
Since this is my first post on the list, a brief introduction of myself.
My name is Thomas, I am 26 years old, I am a student of Computational
Linguistics and I am a python...
|
by: Ben Finney |
last post by:
Howdy all,
Python programmers looking for a built-in GUI toolkit are told two
things: one, Python already comes with a GUI toolkit, and two, it
looks equally ugly on all platforms. This is...
|
by: kudos |
last post by:
Hi, a couple of months ago, I made a xmas chistmas "card" to this community(http://www.thescripts.com/forum/thread580722.html) Now its soon easter, and I hacked together something for easter as...
|
by: Simon Forman |
last post by:
Hi all,
I realize this is more of a Tk question than a python one, but since
I'm using python and don't know Tcl/Tk I figured I'd ask here first
before bugging the Tcl folks.
I am having a...
|
by: kudos |
last post by:
Its turned into a tradition, making small tkinter "cards". Here is one for the christmas and new year. Paste and run from python!
http://www.freewebs.com/jan_ma/look.png
import Tkinter...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |