Skip to content

Commit 77bb4be

Browse files
committed
draw
1 parent cf767d0 commit 77bb4be

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

python_game/7.draw/draw.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env python
2+
#coding:utf-8
3+
import pygame
4+
from pygame.locals import *
5+
from sys import exit
6+
from random import *
7+
from math import pi
8+
9+
pygame.init()
10+
screen = pygame.display.set_mode((1024,800),0,32)
11+
points = []
12+
13+
while True:
14+
for event in pygame.event.get():
15+
if event.type == QUIT:
16+
exit()
17+
if event.type == KEYDOWN:
18+
points =[]
19+
screen.fill((255,255,255))
20+
if event.type == MOUSEBUTTONDOWN:
21+
screen.fill((255,255,255))
22+
23+
rc = (randint(0,255),randint(0,255),randint(0,255))
24+
rp = (randint(0,1023),randint(0,799))
25+
rs = (639-randint(rp[0],1023),799-randint(rp[1],799))
26+
pygame.draw.rect(screen,rc,Rect(rp,rs))
27+
28+
rc = (randint(0,255),randint(0,255),randint(0,255))
29+
rp = (randint(0,1023),randint(0,799))
30+
rr = randint(1,200)
31+
pygame.draw.circle(screen,rc,rp,rr)
32+
33+
34+
x,y = pygame.mouse.get_pos()
35+
points.append((x,y))
36+
37+
angle = (x/639.)*pi*2.
38+
pygame.draw.arc(screen,(0,0,0),(0,0,1024,799),0,angle,3)
39+
40+
pygame.draw.ellipse(screen,(0,255,0),(0,0,x,y))
41+
42+
pygame.draw.line(screen,(0,0,255),(0,0),(x,y))
43+
pygame.draw.line(screen,(255,0,0),(1024,800),(x,y))
44+
45+
if len(points)>1:
46+
pygame.draw.lines(screen(155,155,0),False,points,2)
47+
48+
for p in points:
49+
pygame.draw.circle(screen,(155,155,155),p,3)
50+
pygame.display.update()
51+
52+

0 commit comments

Comments
 (0)