#! /usr/bin/env python2.7# -*- coding:utf-8 -*-#File:PG6.py#Date:2013-8-1#Author:wangyu"""昨天晚上下大雨,一下把我家的玉米弄得一片損毀,剛剛打電話給兄弟,一會回來一起和我在路邊煮玉米,賣玉米,難道我這個暑假要在加賣玉米了?"""import pygamefrom pygame.locals import *from sys import *from random import *from math import pipygame.init()screen=pygame.display.set_mode((640,480),0,32)points=[]while True: for event in pygame.event.get(): if event.type ==QUIT: exit() if event.type ==KEYDOWN: points=[] screen.fill((255,255,255)) if event.type ==MOUSEBUTTONDOWN: screen.fill((255,255,255))#隨機矩形 rc=(randint(0,255),randint(0,255),randint(0,255)) rp=(randint(0,639),randint(0,479)) rs=(639-randint(rp[0],639),479-randint(rp[1],479)) pygame.draw.rect(screen,rc,Rect(rp,rs))#隨機原型 rc=(randint(0,255),randint(0,255),randint(0,255)) rp=(randint(0,639),randint(0,479)) rr=randint(0,200) pygame.draw.circle(screen,rc,rp,rr)#獲得當前滑鼠的點擊位置 x,y=pygame.mouse.get_pos() points.append((x,y))#根據點擊位置畫弧線 angle=(x/639.)*pi*2. pygame.draw.arc(screen,(0,0,0),(0,0,639,479),0,angle,3)#根據隨機點畫橢圓 pygame.draw.ellipse(screen,(0,255,0),(0,0,x,y))#從左上和右下畫兩根線串連到點擊位置 pygame.draw.line(screen,(0,0,255),(0,0),(x,y)) pygame.draw.line(screen,(255,0,0),(640,480),(x,y)) pygame.display.update()
在python中有很多的函數,甚至有能製造子彈的方法!