2018-10-22作业

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、

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • import pygame """ 1.鼠标事件: 事件类型:event.type MOUSEBUTTONDOWN...
    d_d_z阅读 1,300评论 0 0
  • 1.recode 1.json数据json数据的要求:a.一个json对应一个数据b.json中的数据一定是jso...
    芽菜包66阅读 1,618评论 0 0
  • recode """ 1.json数据 json数据的要求:a.一个json对应一个数据b.json中的数据一定是...
    我才是鳄鱼宝宝阅读 1,898评论 0 0
  • 1recode 1.json数据json数据的要求:a.一个json对应一个数据b.json中的数据一定是json...
    大漠判官1阅读 2,994评论 0 0
  • 爱与性就像是一对姐妹,千丝万缕,纠葛不清。有人因爱而性,也有人由性而爱。人们对于钱的爱,毫无疑问,是由性而...
    流浪者们阅读 10,900评论 2 2