Pygame 学习练习(三):画图?
2014-03-05 23:04
260 查看
练习一:利用randint()函数随机产生区间大小的数字,座标随机,半径随机,颜色随机
#!/usr/bin/pytho #-*-coding:utf-8-*- #代码目的: 利用randint()函数产生随机数,然后即可作为随机坐标,然后在画布上随机任意位置花任意大小的圆形 import pygame from random import * # 这个主要为了生产出随机数 from pygame.locals import * from sys import exit pygame.init() screen = pygame.display.set_mode((800,480),0,32) pygame.display.set_caption("Testing random and draw ") # for i in range(0,100): #利用randint()函数随机产生区间大小的数字,座标随机,半径随机,颜色随机 circle_postion = (randint(0,800),randint(0,480)) radius = randint(0,160) circle_color = (randint(0,255),randint(0,255),randint(0,255)) pygame.draw.circle(screen,circle_color,circle_postion,radius) #pygame.draw.circle()为了在画布(surface对象上画圆形 #circle(Surface, color, pos, radius, width=0) -> Rect pygame.display.update() while True: for event in pygame.event.get(): #事件测试,获取事件队列里面的事件 if event.type == QUIT: #当事件类型为退出时候,一般是按下X图标时候 over_font = pygame.font.SysFont("",32) #产生字体Font对象 font_surface = over_font.render("Game Over!",True,(255,255,255)) #由字体产生surface对象 screen.blit(font_surface,(380,220)) #把字体对象贴到画布上,就是在屏幕上现实Game Over pygame.display.update() #当然,需要更新画布才看得见 else: pass
效果:
相关文章推荐
- Pygame 学习练习(一):什么是事件?
- Pygame 学习练习(二):字体?
- pygame学习笔记(1)——安装及矩形、圆型画图
- 《Hello World》python学习之pygame画图模块
- Pygame学习(3)-----如何对图像进行翻转,缩放,旋转
- Python计算机视觉编程练习4:glob模块学习
- Python画图功能学习
- 孙鑫VC学习笔记:第十讲画图 创建设置画笔的对话框 并且可以预览效果
- Matlab--学习笔记(一)-基础知识-画图
- 8-20学习练习[用两个tableview实现类似省市联动选择效果]
- IOS 开发学习 十四 与CGRect相关的几个结构体和画图有关的几个函数
- C++学习笔记:MyString类的重载 练习
- iOS Swift 模块练习/swift基础学习
- SSH与SSM学习之SSH实现CRM练习15——注册登录
- Hibernate学习笔记_关系映射_树状结构练习
- C语言学习历程——编程练习3——02
- Android画图学习总结(二)——Bitmap
- 【oracle学习】3.子查询和集合运算练习
- Android画图学习总结(五)——Paint
- Java学习·抽象类练习