美文网首页
11-Python笔记整理(pygame)

11-Python笔记整理(pygame)

作者: 李小萌mmm | 来源:发表于2018-07-27 20:03 被阅读0次

pygame

 #1.初始化pygame
pygame.init()
#2.设置窗口的大小,单位为像素
screen = pygame.display.set_mode((600,400))
#3.窗口背景颜色
screen.fill((255,255,255))
RGB.png

color->灰色(x,x,x)


文字

字体设置
#字体设置
    #1.创建字体对象
    font = pygame.font.SysFont('宋体',50)

    #创建自定义字体
    #Font(字体文件路径,字体大小)
    font =pygame.font.Font('./font/aa.ttf',25)
#2.根据字体创建显示对象(文字)
    surface=font.render('今天 好开心呀 hahaha ',True,(0,0,0))

显示控制

    #3.将内容添加到窗口上
    #blit(需要显示的对象,显示的位置)
    screen.blit(surface,(100,100))

    #4.将窗口上的内容展示出来
    pygame.display.flip()

检测事件

while True
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                print('关闭被点击')
                exit()

图片

    image = pygame.image.load('./144.jpg')

   
    transform( 形变):包括缩放,旋转和平移

    #scale(缩放对象,新的大小)
    image = pygame.transform.scale(image, (360, 600))

    #rotate(旋转对象,选择大小)
    image = pygame.transform.rotate(image,-90)

    #rotozoom(旋转对象,旋转角度,缩放比例)
    image = pygame.transform.rotozoom(image,90,1)

     #图片渲染到窗口上
    screen.blit(image, (0, 0))
    #获得图片大小
    image_size = image.get_size()
    print(image_size)


图形

'''
    1,画直线
    line(Surface,color,start_pos,end_pos,width=1)
    Surface - 画在哪个地方
    color - 线的颜色
    start_pos-起点
    end_pos-终点
    width - 宽度
    pygame.draw.line(screen,(255,0,0),(0,0),(300,300),5)


    lines(画线的位置,颜色,closed,点的列表,width=1)
    '''
    pygame.draw.lines(screen, (255, 0, 0), False , [(0,20),(10,100),(200,200)],2)



    #2.画曲线(arc)
    #arc(Surface, color, Rect, start_angle, stop_angle, width=1)
    from math import pi
    pygame.draw.arc(screen,(0,0,0),(0,0,200,200),pi/2,pi)

    #3.画矩形(rect)
    pygame.draw.rect(screen,(255,255,0),(0,0,200,200))

   
    import random
    #4.画圆(circle)
    pygame.draw.circle(screen,(random.randint(0,255),random.randint(0,255),random.randint(0,255)),\
                               (300,200),100)

相关文章

  • 11-Python笔记整理(pygame)

    pygame color->灰色(x,x,x) 文字 字体设置 显示控制 检测事件 图片 图形

  • pygame

    学习pygame如果不了解pygame是什么的可以参考百度或者去官网去看介绍pygame急忙趁着三分的热度,整理一...

  • Pygame 模块简单整理

    Pygame 模块简单整理 2018.07.07 Juttachen 概述 如何打开一个游戏窗口? 如何进行鼠标键...

  • 12-Python笔记整理(pygame2)

    event.pos获得当前的位置event.key属性,被按的按键对应值的编码,在通过chr()把编码转换成字符集...

  • 2018-09-04-pygame

    一、pygame基本操作 import pygame——导入pygame模块 pygame.init()——初始化...

  • Pygame入门--飞机大战案例

    Pygame的快速入门 #导入pygame模块 import pygame #游戏初始化 pygame.init(...

  • Day_10 异常与pygame

    异常捕获 pygame操作流程 pygame显示文字 pygame显示图片与图片操作 pygame基本显示

  • Pygame-hello world

    使用pygame 模块名功能pygame.cdrom访问光驱pygame.cursors加载光标pygame.di...

  • pygame - alphabet

    pygame install pygame install[https://www.pygame.org/wiki...

  • pygame学习笔记

    用pygame写一个框 先看代码 #!/usr/bin/env python# coding=utf-8impor...

网友评论

      本文标题:11-Python笔记整理(pygame)

      本文链接:https://www.haomeiwen.com/subject/drogmftx.html