0
点赞
收藏
分享

微信扫一扫

pygame 画图练习

南陵王梁枫 2022-02-04 阅读 76
import pygame

def main():
    # 初始化导入的pygame中的模块
    pygame.init()
    # 初始化用于显示的窗口并设置窗口尺寸
    screen = pygame.display.set_mode((600, 400))
    # 设置当前窗口的标题
    pygame.display.set_caption('画图练习')
    # 设置窗口的背景色(颜色是由红绿蓝三原色构成的元组)
    screen.fill((225, 225, 225))
    # 绘制一个圆(参数分别是: 屏幕, 颜色, 圆心位置, 半径, 0表示填充圆)
    pygame.draw.circle(screen, (0, 255, 0,), (100, 100), 30, 0)

    #定义了一个黄色,宽80,高30,左上角顶点在300,500
    #位置的矩形
    line_width = 2
    rect_color = 255, 255, 0
    rect_x = 300
    rect_y = 50
    rect_width = 80
    rect_height = 30
    pygame.draw.rect(screen, rect_color, [rect_x, rect_y, rect_width, rect_height], line_width)
    #定义了一个黄色,从x=50,y=120的点连接到x=300,y=160的点的线段
    line_color = 255, 255, 0
    pygame.draw.line(screen, line_color, [50, 120], [300, 160], line_width)
    #定义了一个白色,字体大小为60,在x=300,y=300处开始绘制的文字
    myfont = pygame.font.Font(None, 60)
    white = 255, 255, 255
    textImage = myfont.render("hello world!", True, white)
    screen.blit(textImage, (300, 300))




    # 刷新当前窗口(渲染窗口将绘制的图像呈现出来)
    pygame.display.flip()
    running = True
    # 开启一个事件循环处理发生的事件
    while running:
        # 从消息队列中获取事件并对事件进行处理
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False


if __name__ == '__main__':
    main()
举报

相关推荐

pygame

安装 pygame

【pygame游戏】

PYGAME - 美化(CNT)

pygame游戏开发

PyGame游戏编程

0 条评论