【原创】pygame学习笔记(1)----基本的线,矩形,圆形,弧形绘制

版权声明:一起学习,一起成长,欢迎关注犀牛先生的博客 https://blog.csdn.net/xuemanqianshan/article/details/83247496

PYgame的内容

(1)这个module很有意思

(2)书本至少来源于《Python游戏编程入门》

(3)官方权威说明:https://www.pygame.org/docs/

下面的尝试把各种图形在一个程序里绘制

注意点:

(1)特别注意,比如引用color=0,0,200这种

       要么是pygame.draw.line(screen,color,position,position2,width)

       要么是pygame.draw.line(screen,(0,0,200),position,position2,width)

      特别注意括号

# -*- coding:utf-8 -*-
import pygame
from pygame.locals import *
import sys
import math

white=255,255,255
blue=0,0,200
color=255,255,0  #yellow
position =300,250
radius=100
width=5
position2=300+radius,250

pygame.init()

screen=pygame.display.set_mode((600,500)) #注意,位置和颜色作为数组,都必须括起来作为参数!实际是双层括号
caption=pygame.display.set_caption("draw draw draw")
myfont=pygame.font.Font(None,100)
textImage=myfont.render("hello,Pygame",True,white)


while True:
	for event in pygame.event.get():
		if event.type in (QUIT,KEYDOWN):
			sys.exit()
	screen.fill((0,0,200))
	
	#display text
	screen.blit(textImage,(0,100))
	
	#draw a cycle
	pygame.draw.circle(screen,color,position,radius,width)
	
	#draw a line
	pygame.draw.line(screen,color,position,position2,width)
	
	#draw 2 rect
	position_r1=250,200,100,100
	position_r2=400,200,100,100
	pygame.draw.rect(screen,color,position_r1,width)
	pygame.draw.rect(screen,color,position_r2,0)

	#draw arc
	position_r3=150,150,200,200
	start_angle=math.radians(90)
	end_angle=math.radians(270)	
	pygame.draw.arc(screen,color,position_r3,start_angle,end_angle,width)
	
	pygame.display.update()
	
	
	

 

猜你喜欢

转载自blog.csdn.net/xuemanqianshan/article/details/83247496
今日推荐