无论如何我可以为使用绘制的每条线使用不同的颜色pygame.draw.lines吗?这是我的代码:
import pygame
pygame.init()
screen = pygame.display.set_mode((640, 480), pygame.SCALED)
screen.fill('white')
pygame.draw.lines(screen, 'red', True, [(10, 100), (20, 200), (30, 100)]) # all lines are red
while True:
pygame.display.update()
Run Code Online (Sandbox Code Playgroud)
我得到的输出:
我想要的输出:
我试过的:
pygame.draw.lines(screen, ['green', 'blue', 'orange'], True, [(10, 100), (20, 200), (30, 100)])
Run Code Online (Sandbox Code Playgroud)
错误:
ValueError: invalid color argument
Run Code Online (Sandbox Code Playgroud)
换句话说,我想在下面的代码中实现我想要的但是使用 pygame.draw.lines
pygame.draw.line(screen, 'green', (10, 100), (20, 200))
pygame.draw.line(screen, 'blue', (20, 200), (30, 100))
pygame.draw.line(screen, 'orange', (30, 100), (10, 100))
Run Code Online (Sandbox Code Playgroud)
我检查了pygame.draw.lines 文档,但我不确定color那里的参数是否采用我给出的列表。它只提到“ Color or int or tuple(int, int, …
玩弄isinstance,我想知道它如何用于子类检查。
class A:
pass
class B(A):
pass
class C(B):
pass
print(isinstance(C(), C)) # True, I understand this fine
print(isinstance(C(), B)) # True, Ok, but how is this `True`?
print(isinstance(C(), A)) # True, this too?
Run Code Online (Sandbox Code Playgroud)
type() 和 isinstance() 有什么区别?解释这isinstance确实适用于我的第二个和第三个print语句中所见的子类。我的问题不是那个,但是,它是如何工作的?当 classA被定义时,它没有关于 classB或 class存在的信息C,同样B没有关于C.
根据isinstance 如何为 List 工作? __instancecheck__被调用isinstance,所以如果我的课A是之前创建B和C如何做到这一点的Python知道,C()确实是子类的一个实例(B的子类A)或子类的子类A …