Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
630 views
in Technique[技术] by (71.8m points)

python - Why did drawing a PyGame rectangle with very thick borders draw a plus shape instead?

So I drew a rectangle today:

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

Instead of drawing a thin bordered rectangle it draw a really big cross/plus sign.

enter image description here

This happened because i typed "100" instead of "1" for the border thickness when drawing the rect onto the screen.
But whats the logic behind this?
the border thickness grew so large that....?
anyone want to explain what you think or know has occurred?

question from:https://stackoverflow.com/questions/65890797/why-did-drawing-a-pygame-rectangle-with-very-thick-borders-draw-a-plus-shape-ins

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

See 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.

Therefore you are actually drawing 4 lines 5 in length but 100 in thickness along the edges of the rectangle. Since the lines are arranged in a square and are thicker than they are long, the final shape appears to be a cross.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...