Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame, sys, random, time, math
- from pygame.locals import *
- pygame.init()
- width1 = 500
- height1 = 340
- scr1 = pygame.display.set_mode((width1,height1), 0, 32)
- bimage = "gradient.jpg"
- mimage = "ball.png"
- background = pygame.image.load(bimage).convert()
- mouse_c = pygame.image.load(mimage).convert_alpha()
- ball = [0,0]
- def generate_inc():
- theta = random.random() * 2 * math.pi
- x_inc = math.cos(theta)
- y_inc = math.sin(theta)
- print "Generated new increment:", (x_inc, y_inc)
- return x_inc, y_inc
- x_inc, y_inc = generate_inc()
- count = 0
- while True:
- for event in pygame.event.get():
- if event.type == QUIT:
- pygame.quit()
- sys.exit()
- if event.type == KEYDOWN:
- x_inc, y_inc = generate_inc()
- if count == 2000:
- count = 0
- x_inc, y_inc = generate_inc()
- scr1.blit(background, (0,0))
- scr1.blit(mouse_c, tuple(ball))
- ball[0] = (ball[0] + x_inc)# % width1
- if ball[0] >= width1 or ball[0] <= 0:
- x_inc = -1 * x_inc
- ball[1] = (ball[1] + y_inc)# % height1
- if ball[1] >= height1 or ball[1] <= 0:
- y_inc = -1 * y_inc
- pygame.display.update()
- count += 1
- ##from Tkinter import *
- ##
- ##master = Tk()
- ##
- ##w = Canvas(master, width = 200, height = 100)
- ##w.pack()
- ##
- ##w.create_line(0, 0, 200, 100)
- ##w.create_line(0, 100, 200, 0, fill="red", dash = (4, 4))
- ##
- ##
- ##
- ##w.create_rectangle(50,25,150,75, fill="blue")
- ##
- ##mainloop()
Advertisement
Add Comment
Please, Sign In to add comment