pygame初学篇三: 绘制弧线的方法
绘制圆形方法:pygame.draw.arc(Surface, color, Rect, start_angle, stop_angle,width), pygame 官网介绍说明方法:http://www.pygame.org/docs/ref/draw.html# pygame.draw.circle
arc方法介绍: Surfuce参数: 传入需要在该Surface对象上绘制圆形的Surface对象; color参数: 需要绘制圆形的线的颜色,传入一个rgb三原色元组 . Rect参数: 表示需要绘制区域的矩形框, 当矩形框为正方形时,绘制的为圆。start_angle 参数: 起始的角度,stop_angle参数: 终止的角度,width参数:表示绘制圆的线的宽度.
示例: 在白色背景上,分别绘制两端弧线。
# -*- coding: utf-8 -*-
# @Author: 四叶草
# @Date: 2017-11-04 19:15:46
# @Last Modified by: Administrator
# @Last Modified time: 2017-11-07 20:40:52
import pygame
import sys
from pygame.locals import *
# pygame 初始化
pygame.init()
# 设置背景颜色和线条颜色
WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
RED = (255, 0, 0)
BLUE = (0, 0, 255)
# 设置背景框大小
size = width, height = 600, 600
#position = width // 2, height // 2
# 设置帧率,返回clock 类
clock = pygame.time.Clock()
screen = pygame.display.set_mode(size)
pygame.display.set_caption("llls make")
while True:
for event in pygame.event.get():
# 查找关闭窗口事件
if event.type == QUIT:
sys.exit()
# 填充背景色
screen.fill(WHITE)
# 画两段弧线
pygame.draw.arc(screen, GREEN, (100, 100, 400, 100), 0, math.pi, 1)
pygame.draw.arc(screen, GREEN, (100, 100, 400, 400), math.pi, math.pi * 2, 1)
# 刷新图
pygame.display.flip()
clock.tick(60)
# @Author: 四叶草
# @Date: 2017-11-04 19:15:46
# @Last Modified by: Administrator
# @Last Modified time: 2017-11-07 20:40:52
import pygame
import sys
from pygame.locals import *
# pygame 初始化
pygame.init()
# 设置背景颜色和线条颜色
WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
RED = (255, 0, 0)
BLUE = (0, 0, 255)
# 设置背景框大小
size = width, height = 600, 600
#position = width // 2, height // 2
# 设置帧率,返回clock 类
clock = pygame.time.Clock()
screen = pygame.display.set_mode(size)
pygame.display.set_caption("llls make")
while True:
for event in pygame.event.get():
# 查找关闭窗口事件
if event.type == QUIT:
sys.exit()
# 填充背景色
screen.fill(WHITE)
# 画两段弧线
pygame.draw.arc(screen, GREEN, (100, 100, 400, 100), 0, math.pi, 1)
pygame.draw.arc(screen, GREEN, (100, 100, 400, 400), math.pi, math.pi * 2, 1)
# 刷新图
pygame.display.flip()
clock.tick(60)
版权声明:本文为FourLeafCloverLLLS原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。