python - 为什么绘制一个具有很厚边框的 PyGame 矩形会绘制一个加号形状?

标签 python pygame draw rectangles rect

所以我今天画了一个矩形:

my_rectangle = pygame.Rect(100, 100, 5, 5)
pygame.draw.rect(display, colour["black"], my_rectangle, 100)

它不是绘制一个细边框的矩形,而是绘制一个非常大的十字/加号。

enter image description here

发生这种情况是因为我在将矩形绘制到屏幕上时输入了“100”而不是“1”作为边框厚度。
但这背后的逻辑是什么?
边框厚度变得如此之大......?
有人想解释一下您认为或知道发生了什么吗?

最佳答案

参见pygame.draw.rect() :

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/

相关文章:

python - 重试时celery何时调用on_failure

python - 在 1&1 共享主机上部署 Flask 应用程序(使用 CGI)

多线程中的Python单元测试

python - 如何测试区域是否重叠 (Python)

python - 我如何在 python 3 中播放声音?

java - 无效方法仅在放入 'onDraw' 时有效

python - Python 列表的底层数据结构是什么?

python - 如何让 get_pressed 在 pygame 中工作?

java - 我的 Java 小程序没有出现

java - 你能用 Graphics g 绘制 Area 对象吗?