简单的大饼游戏,掌握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 (以及简单图形训练)的更多相关文章

  1. 学习笔记:HTML5 Canvas绘制简单图形

    HTML5 Canvas绘制简单图形 1.添加Canvas标签,添加id供js操作. <canvas id="mycanvas" height="700" ...

  2. [ASP.NET] 图形验证码破解-以简单图形为例

    原文 http://www.dotblogs.com.tw/joysdw12/archive/2013/06/08/captcha-cracked.aspx 前言 这次来讲个比较有趣的主题,就是该如何 ...

  3. Java入门:绘制简单图形

    在上一节,我们学习了如何使用swing和awt工具创建一个空的窗口,本节学习如何绘制简单图形. 基本绘图介绍 Java中绘制基本图形,可以使用Java类库中的Graphics类,此类位于java.aw ...

  4. 输出简单图形(StringBuilder代替双重循环)

    在有些题目中打印简单图形必须使用StringBuilder或者StringBuffer,否则会运行超时(用String都会超时). 因为在题目的要求中说到输入的n是小于1000的,用双重循环就会超时, ...

  5. c语言实现一些简单图形的打印

    1 #define _CRT_SECURE_NO_WARNINGS 1 因为笔者采用的是VS的编译环境所以有了上面的这一句话 我们都知道平面图形是由一条条线段构成,所以我们就先实现线段的打印 1 // ...

  6. Win32简单图形界面程序逆向

    Win32简单图形界面程序逆向 前言 为了了解与学习底层知识,从 汇编开始 -> C语言 -> C++ -> PE文件 ,直至今天的Win32 API,着实学的令我头皮发麻(笑哭). ...

  7. GDI+图形图像处理技术中Pen和Brush的简单使用和简单图形的绘制(C#)

    1.Graphics Graphics对象是GDI+绘图表面,因此在Windows窗体应用程序中要使用GDI+创建绘图,必须要先创建Graphics.在给窗体注册一个Paint事件后,Graphics ...

  8. Quartz 2D绘制简单图形

    在Quartz 2D中,绘图是通过图形上下文进行绘制的,以下绘制几个简单的图形 首先先创建一个QuartzView.swift文件继承自UIView,然后实现drawRect方法: import UI ...

  9. Golang 绘图基础 -绘制简单图形

    前一节讲的是 绘图到不同输出源,请看地址: http://www.cnblogs.com/ghj1976/p/3440856.html 上一节的例子效果是通过设置每一个点的的RGBA属性来实现的,这是 ...

随机推荐

  1. Gvim插件管理Vundle

    之前关于gvim的博客中提到的很多插件安装比较繁琐,这一篇来介绍一下gvim管理插件的插件--vundle的安装以及使用,让givm的插件安装更加的简单 首先给出vundle的git地址 https: ...

  2. php返回数据库查询时出现Resource id #2

    1.使用php调用MySQL数据库的过程是不是先用mysql_query(SELECT*...)或mysql_list_dbs()等查询函数返回结果指针(mysql查询函数中还有没有这样的返回指针函数 ...

  3. windbg学习.formats--转换成各种进制

    .formats 命令在当前线程和进程上下文下对一个表达式或符号进行求值,并以多种数字格式显示出来. 0:002> .formats 000ad3a0 Evaluate expression: ...

  4. Struts2,Spring, Hibernate三大框架SSH的整合步骤

    整合步骤 创建web工程 引入相应的jar包 整合spring和hibernate框架 编写实体类pojo和hbm.xml文件 编写bean-base.xml文件 <!-- 1) 连接池实例 - ...

  5. CentOS6.5源码安装python3.5.2

    前提: 1.实现自动补全需要安装模块 readline-devel (yum install -y readline-devel) 2.实现支持SSL协议需安装模块 openssl-devel (yu ...

  6. try--catch--finally中return返回值执行的顺序(区别)

    1.try块中没有抛出异常,try.catch和finally块中都有return语句 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 public static int ...

  7. 多线程爬取 threading.Thread 文件名支持gbk编码

    # - *- coding:utf-8-*-import urllib2import reimport osimport threadingimport sysreload(sys)sys.setde ...

  8. Camstar Portal modeling user guid --自定义用户菜单

    通过studio 创建 menu definition 创建菜单 创建成功后到employee界面设置对应菜单就可以了

  9. 【UVA11082】Matrix Decompressing(有上下界的网络流)

    题意:给出一个矩阵前i列所有元素的和,和前j行所有元素的和,求这个矩阵解压以后的原型.(答案不唯一) n,m<=20,1<=a[i,j]<=20 思路:这道题把边上的流量作为原先矩阵 ...

  10. JAVA异常初步

    1,1个图.Throwable是所有异常类的老祖宗,万恶之源.Error正常是系统级错误,控制不了,Exception类又分RuntimeException及别的异常,RuntimeException ...