pip install pygame 然后导入Pygame库: import pygame import sys 2、初始化Pygame 在使用Pygame绘图之前,需要初始化Pygame,并设置窗口的大小和标题。 pygame.init() 设置窗口大小和标题 window_size = (800, 600) screen = pygame.display.set_mode(window_size) pygame.display.set_caption("Draw Circle with Py...
简单一个例子: 效果: 代码: import pygame from pygame.locals import * def DrawCircle(screen): BLUE = (0, 0, 255) position = 300,250 radius = 100 width = 10 pygame.draw.circle( screen, BLUE, positio…
fill(blue) # 圆绘制 pygame.draw.circle(screen, color, position, radius, width) positionX += movX positionY += movY if positionX>380 or positionX<0: movX = -movX if positionY>753 or positionY<0: movY = -movY posNew = positionX,positionY,100,100 # 矩形绘制 pygame.draw.rect(screen,...
')# 设置窗口的背景色 screen.fill((0,0,0))clock=(255,255,255)# 绘制矩形 # 显示窗口,(颜色),(左,顶,宽,高) pygame.draw.rect(screen,clock,(20,20,50,20),1)# 或者((左,上),(宽,高)
pygame.draw.circle(win,color,position,radius,width)'''结束绘制圆形'''pygame.display_setcaption('圆形的绘制')# 刷新窗口 pygame.display.update() 如果将线条宽度改为和半径一样,就变成了一个实体圆 绘制弧形 绘制弧形的步骤与绘制圆形的步骤是一样的,只不过绘制弧形需要使用到pygame.draw.arc()函数 ...
在示例程序中(Learn python by create game 通过制作游戏学习python编程系列 第二篇《PyGame 的Hello,World》),我们使用了两个在屏幕上进行绘制的命令: screen.fill() fill()方法来填充背景 pygame.draw.circle() circle()方法来绘制一个圆 现在您将学习第三种在屏幕上绘制的方法: 使用 Surface。 回想一下,Surf...
先从整体来看pygame.draw有哪些函数: pygame.draw.rect: 绘制矩形 pygame.draw.polygon: 绘制任意边数的多边形 pygame.draw.circle: 绘制圆 pygame.draw.ellipse: 在矩形内绘制椭圆 pygame.draw.arc: 绘制圆弧(或者椭圆的一部分) pygame.draw.line: 绘制直线(线段) ...
pygame.draw.circle(screen, color, [self.pos_x, self.pos_y], self.r) 八、构造方法:向目标移动 1、根据上文给出的思路计算横向速度与纵向速度,分别加到小球的x坐标与y坐标上 2、需要的的参数:target_x目标x轴坐标,target_y目标y轴坐标 deftrack(self, target_x, target_y): ...
pygame.draw.circle(screen, color, position, radius, width) 其次是食物模块: np.random.randint用于产生边界之内的坐标,如果与贪吃蛇的坐标重合,那么就继续生成新的随机坐标。 # 食物classFood(object):def__init__(self): self.item = (4,5)# 画出食物def_draw(self, screen, i, j): ...