所以我今天画了一个矩形:
my_rectangle = pygame.Rect(100, 100, 5, 5)
pygame.draw.rect(display, colour["black"], my_rectangle, 100)
它不是绘制一个细边框的矩形,而是绘制一个非常大的十字/加号。
发生这种情况是因为我在将矩形绘制到屏幕上时输入了“100”而不是“1”作为边框厚度。
但这背后的逻辑是什么?
边框厚度变得如此之大......?
有人想解释一下您认为或知道发生了什么吗?
最佳答案
rect(surface, color, rect, width=0) -> Rect
width (int) -- (optional) used for line thickness or to indicate that the rectangle is to be filled (not to be confused with the width value of the rect parameter)
- if width > 0, used for line thickness
Note When using width values > 1, the edge lines will grow outside the original boundary of the rect.
因此,您实际上是沿着矩形的边缘绘制 4 条长度为 5、厚度为 100 的线。由于线条排列成正方形并且粗大于长,因此最终形状看起来是十字形。
关于python - 为什么绘制一个具有很厚边框的 PyGame 矩形会绘制一个加号形状?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65890797/