1、pygame 画猫
#Author ddz
import pygame, math
def lines():
pygame.draw.lines(screen, (25,25,25),True,
[(200,100), (300,400), (500,400), (600,100), (700,400), (700,600), (500,800), (300,800), (100,600), (100,400)])
pygame.display.flip()
def circle(x,y):
pygame.draw.circle(screen, (255,255,0), (x,y),60,0)
pygame.display.flip()
def main():
while 1:
for eventin pygame.event.get():
if event.type== pygame.QUIT:
exit()
lines()
circle(250,550)
circle(550,550)
arc()
pygame.draw.lines(screen, (25,25,25),True,[(300,750), (500,750)])
pygame.display.flip()
def arc():
pi = 80
pygame.draw.arc(screen, (0,20,24), (300,700,200,100), math.pi/1,0)
pygame.display.flip()
if __name__== '__main__':
pygame.init()
screen= pygame.display.set_mode((800,900))
screen.fill((255,255,255))
pygame.display.flip()
main()
2、pygame 鼠标画线
#Author ddz
import pygame, random
def rand_color():
return (random.randint(0,255), random.randint(0,255), random.randint(0,255))
def line(start_pos):
end_pos= (0,0)
i= 1
while i:
for eventin pygame.event.get():
if event.type== pygame.QUIT:
exit()
elif event.type== pygame.MOUSEBUTTONDOWN:
print('1鼠标按下:', event.pos)
end_pos= event.pos
i= 0
pygame.draw.line(screen, rand_color(),start_pos, end_pos)
pygame.display.flip()
def main():
while 1:
for eventin pygame.event.get():
if event.type== pygame.QUIT:
exit()
elif event.type== pygame.MOUSEBUTTONDOWN:
line(event.pos)
if __name__== '__main__':
pygame.init()
screen= pygame.display.set_mode((800,800))
screen.fill((255,255,255))
pygame.display.flip()
main()
3、pygame 鼠标画圆
#Author ddz
import pygame, random,math
def rand_color():
return (random.randint(0,255), random.randint(0,255), random.randint(0,255))
def circle(center_pos):
end_pos= (0,0)
i= 1
while i:
for eventin pygame.event.get():
if event.type== pygame.QUIT:
exit()
elif event.type== pygame.MOUSEBUTTONDOWN:
#print('1鼠标按下:', event.pos)
end_pos= event.pos
i= 0
radius= int(math.sqrt(((center_pos[0]-end_pos[0])**2)+((center_pos[1]-end_pos[1])**2)))
pygame.draw.circle(screen, rand_color(),center_pos, radius,0)
pygame.display.flip()
def main():
while 1:
for eventin pygame.event.get():
if event.type== pygame.QUIT:
exit()
elif event.type== pygame.MOUSEBUTTONDOWN:
circle(event.pos)
if __name__== '__main__':
pygame.init()
screen= pygame.display.set_mode((800,800))
screen.fill((255,255,255))
pygame.display.flip()
main()
4、
网友评论