pygame 练习之 PIE game (以及简单图形训练)
简单的大饼游戏,掌握pygame中直线以及圆弧的画法,以及对输入的响应。
import math
import pygame, sys
from pygame.locals import *
pygame.init()
screen = pygame.display.set_mode((600, 500))
pygame.display.set_caption("The Pie Game -- Press 1 2 3 4")
myfont = pygame.font.Font(None, 60) color = 200, 80, 60
width = 5
x = 300
y = 250
radius = 200
position = x - radius, y - radius, radius*2, radius*2 piece1 = False
piece2 = False
piece3 = False
piece4 = False # main game loop
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
elif event.type == KEYUP:
if event.key == pygame.K_ESCAPE:
pygame.quit()
sys.exit()
elif event.key == pygame.K_1:
piece1 = True
elif event.key == pygame.K_2:
piece2 = True
elif event.key == pygame.K_3:
piece3 = True
elif event.key == pygame.K_4:
piece4 = True
#clear the screen
screen.fill((0,0,200)) textImg1 = myfont.render("", True, color)
screen.blit(textImg1, (x+radius/2, y-radius/2)) textImg2 = myfont.render("", True, color)
screen.blit(textImg2, (x-radius/2, y-radius/2)) textImg3 = myfont.render("", True, color)
screen.blit(textImg3, (x-radius/2, y+radius/2)) textImg4 = myfont.render("", True, color)
screen.blit(textImg4, (x+radius/2, y+radius/2)) #should the pieces be drawn?
if piece1:
start_angle = math.radians(0)
end_angle = math.radians(90)
pygame.draw.arc(screen, color, position, start_angle, end_angle, width)
pygame.draw.line(screen, color, (x, y), (x, y-radius), width)
pygame.draw.line(screen, color, (x, y), (x+radius, y), width) if piece2:
start_angle = math.radians(90)
end_angle = math.radians(180)
pygame.draw.arc(screen, color, position, start_angle, end_angle, width)
pygame.draw.line(screen, color, (x, y), (x, y-radius), width)
pygame.draw.line(screen, color, (x, y), (x-radius, y), width) if piece3:
start_angle = math.radians(180)
end_angle = math.radians(270)
pygame.draw.arc(screen, color, position, start_angle, end_angle, width)
pygame.draw.line(screen, color, (x, y), (x-radius, y), width)
pygame.draw.line(screen, color, (x, y), (x, y+radius), width) if piece4:
start_angle = math.radians(270)
end_angle = math.radians(360)
pygame.draw.arc(screen, color, position, start_angle, end_angle, width)
pygame.draw.line(screen, color, (x, y), (x, y+radius), width)
pygame.draw.line(screen, color, (x, y), (x+radius, y), width) #finished?
if piece1 and piece2 and piece3 and piece4:
color = 0, 255, 0 pygame.display.update()
效果图:

绘制椭圆:
pygame 练习之 PIE game (以及简单图形训练)的更多相关文章
- 学习笔记:HTML5 Canvas绘制简单图形
HTML5 Canvas绘制简单图形 1.添加Canvas标签,添加id供js操作. <canvas id="mycanvas" height="700" ...
- [ASP.NET] 图形验证码破解-以简单图形为例
原文 http://www.dotblogs.com.tw/joysdw12/archive/2013/06/08/captcha-cracked.aspx 前言 这次来讲个比较有趣的主题,就是该如何 ...
- Java入门:绘制简单图形
在上一节,我们学习了如何使用swing和awt工具创建一个空的窗口,本节学习如何绘制简单图形. 基本绘图介绍 Java中绘制基本图形,可以使用Java类库中的Graphics类,此类位于java.aw ...
- 输出简单图形(StringBuilder代替双重循环)
在有些题目中打印简单图形必须使用StringBuilder或者StringBuffer,否则会运行超时(用String都会超时). 因为在题目的要求中说到输入的n是小于1000的,用双重循环就会超时, ...
- c语言实现一些简单图形的打印
1 #define _CRT_SECURE_NO_WARNINGS 1 因为笔者采用的是VS的编译环境所以有了上面的这一句话 我们都知道平面图形是由一条条线段构成,所以我们就先实现线段的打印 1 // ...
- Win32简单图形界面程序逆向
Win32简单图形界面程序逆向 前言 为了了解与学习底层知识,从 汇编开始 -> C语言 -> C++ -> PE文件 ,直至今天的Win32 API,着实学的令我头皮发麻(笑哭). ...
- GDI+图形图像处理技术中Pen和Brush的简单使用和简单图形的绘制(C#)
1.Graphics Graphics对象是GDI+绘图表面,因此在Windows窗体应用程序中要使用GDI+创建绘图,必须要先创建Graphics.在给窗体注册一个Paint事件后,Graphics ...
- Quartz 2D绘制简单图形
在Quartz 2D中,绘图是通过图形上下文进行绘制的,以下绘制几个简单的图形 首先先创建一个QuartzView.swift文件继承自UIView,然后实现drawRect方法: import UI ...
- Golang 绘图基础 -绘制简单图形
前一节讲的是 绘图到不同输出源,请看地址: http://www.cnblogs.com/ghj1976/p/3440856.html 上一节的例子效果是通过设置每一个点的的RGBA属性来实现的,这是 ...
随机推荐
- android 开发 程序中下载安装APK文件 问题汇总 解析程序包时出现问题
1 若把APK文件保存到应用程序的files目录下,则一定注意保存时使用 FileOutputStream os = openFileOutput(fileName, MODE_WORLD_READA ...
- js 下载图片与下载文件的方式一样;保存至本地 ASP.NET 方式
<asp:Button ID="btnDownLoad" runat="server" style="display: none" T ...
- 关于js中的for(var in)遍历属性报错问题
之前遇到过这个问题,但是没找到问题的所在,将for(var i in array){} 改成了for(var i ;i<array.length;i++)循环,但是今天又遇到了,mark一下错 ...
- 打出10的n次方,上标,下标等处理方法(mac)
我使用mac系统遇到的需求,需要在项目中显示10的6次方 用来做单位,找了很多方案,word等文本编辑工具很好实现(word是使用ctrl + shift + =)(mac 版的word是 Comm ...
- 通过dataGridView控件中的checkBox控件对数据库进行批量删除
string id_s = ""; ; i < dataGridView1.Rows.Count; i++) //遍历所有行 { if (dataGridView1.Rows ...
- Struts2 的 值栈和ActionContext
1.ValueStack 和 ActionContext 的关系与区别: -- 相同点:它们都是在一次HTTP请求的范围内使用的,它们的生命周期都是一次请求 -- 不同点:ValueStack 分为对 ...
- Android Studio启动模拟器
创建模拟器时出现vt x is disabled in bios 出现错误提示:"Intel HAXM is required to run this AVD,VT-x is disable ...
- SQL Server更新表(用一张表的数据更新另一张表的数据)
a) 写法轻松,更新效率高: update table1 set field1=table2.field1,field2=table2.field2 from table2 where table1. ...
- Java实现文件压缩与解压
Java实现ZIP的解压与压缩功能基本都是使用了Java的多肽和递归技术,可以对单个文件和任意级联文件夹进行压缩和解压,对于一些初学者来说是个很不错的实例.(转载自http://www.puiedu. ...
- Java Iterator, ListIterator 和 foreach语句使用
Java Iterator, ListIterator 和 foreach语句使用 foreach语句结构: for(part1:part2){part3}; part2 中是一个数组对象,或者是带 ...