几何图形识别 python_pygame能识别简单的几何图形吗?

我想用pygame创建一组简单的几何图形(彩色矩形、三角形、正方形…),然后分析它们之间的关系和特征。我第一次尝试了turtle,但显然这只是一个图形库,无法跟踪它创建的形状,我想知道这是否适用于Pygame。为了说明这一点,假设我有以下脚本:# Import a library of functions called 'pygame'

import pygame

from math import pi

# Initialize the game engine

pygame.init()

# Define the colors we will use in RGB format

BLACK = ( 0, 0, 0)

WHITE = (255, 255, 255)

BLUE = ( 0, 0, 255)

GREEN = ( 0, 255, 0)

RED = (255, 0, 0)

# Set the height and width of the screen

size = [800, 600]

screen = pygame.display.set_mode(size)

pygame.display.set_caption("Example code for the draw module")

#Loop until the user clicks the close button.

done = False

clock = pygame.time.Clock()

while not done:

# This limits the while loop to a max of 10 times per second.

# Leave this out and we will use all CPU we can.

clock.tick(10)

for event in pygame.event.get(): # User did something

if event.type == pygame.QUIT: # If user clicked close

done=True # Flag that we are done so we exit this loop

screen.fill(WHITE)

# Draw a rectangle outline

pygame.draw.rect(screen, BLACK, [75, 10, 50, 20], 2)

# Draw a solid rectangle

pygame.draw.rect(screen, BLACK, [150, 10, 50, 20])

# Draw an ellipse outline, using a rectangle as the outside boundaries

pygame.draw.ellipse(screen, RED, [225, 10, 50, 20], 2)

# Draw a circle

pygame.draw.circle(screen, BLUE, [60, 250], 40)

# Go ahead and update the screen with what we've drawn.

# This MUST happen after all the other drawing commands.

pygame.display.flip()

# Be IDLE friendly

pygame.quit()

它会创建这样的图像:

现在,假设我保存了Pygame创建的图像。Pygame有没有一种方法可以检测图像中的形状、颜色和坐标?在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值