画图

pygmame 封装了一些通用的游戏操作: 鼠标键盘图片音乐 …
pip3 install pygame

游戏的框架
import pygame
#from pygame.locals import *
pygame.init()

screen = pygame.display.set_mode((800,600))
pygame.display.set_caption('测试游戏')
clock = pygame.time.Clock()
#三原色 rgb 红绿蓝,每种颜色的取值为 0-255
BLACK = (0,0,0)
WHITE = (255,255,255)
RED = (255,0,0)

while True:
    screen.fill(WHITE)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            exit()

    pygame.display.update()
    clock.tick(10)
画各种常见图形

画矩形
import pygame
#from pygame.locals import *
pygame.init()

screen = pygame.display.set_mode((800,600))
pygame.display.set_caption('测试游戏')
clock = pygame.time.Clock()
#三原色 rgb 红绿蓝,每种颜色的取值为 0-255
BLACK = (0,0,0)
WHITE = (255,255,255)
RED = (255,0,0)

while True:
    screen.fill(WHITE)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            exit()
    #方法一
    # pygame.draw.rect(screen,RED,(200,100,300,200),2)
    # pygame.draw.rect(screen,RED,(200,100,300,200))

    #方法二
    sur = pygame.Surface((300,200))
    sur.fill(RED)
    screen.blit(sur,(200,200))

    pygame.display.update()
    clock.tick(10)    
画其它图形方法
import pygame
#from pygame.locals import *
pygame.init()

screen = pygame.display.set_mode((800,600))
pygame.display.set_caption('测试游戏')
clock = pygame.time.Clock()
#三原色 rgb 红绿蓝,每种颜色的取值为 0-255
BLACK = (0,0,0)
WHITE = (255,255,255)
RED = (255,0,0)

while True:
    screen.fill(WHITE)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            exit()
    #多边形
    # pygame.draw.polygon(screen,RED,((200,200),(300,400),(600,400),(400,100)))
    # pygame.draw.polygon(screen,RED,((200,200),(300,400),(600,400),(400,100)),3)
    #画圆
    # pygame.draw.circle(screen,RED,(400,300),100,2)
    #画椭圆
    # pygame.draw.ellipse(screen,RED,(200,100,300,200))
    #画弧形,一个圆是360角度或2pi弧度,这里的开始和结束使用的是弧度
    # pygame.draw.arc(screen,RED,(200,100,300,200),0,3.14)
    #画单根线
    # pygame.draw.line(screen,RED,(200,200),(600,400),10)
    # pygame.draw.aaline(screen,RED,(100,100),(700,500),10)
    # 画多根线
    # pygame.draw.lines(screen,RED,False,((200,200),(300,400),(600,400),(400,100)),2)
    # pygame.draw.aalines(screen,RED,True,((200,200),(300,400),(600,400),(400,100)),2)
    #得到某一个点上的色值
    # color = screen.get_at((100,100))
    # print(color)
    #点n个点
    x,y = 100,100
    for i in range(10):
        x += 10
        y += 10
        screen.set_at((x,y),RED)

    pygame.display.update()
    clock.tick(10)
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值