1

Here is the part of my code that I think pose an issue:

import pygame
pygame.init()
fen=pygame.display.set_mode((320, 320))
loop=True

while loop:
    x=3
    y=0
    pygame.draw.rect(fen, (0, 0, 255), (x*10, y*10, x*10+10, y*10+10))
    pygame.display.update()

It is suppose to make a square in 10X10 but the x axis it is two time longer than the y axis and I don't undersand. Here is what it does (https://i.stack.imgur.com/J7GhH.png)

I tried puting more parenthesis or doing division but it is not stable and will change the shape of the rectangle at every changes.

Ygrub
  • 21
  • 5

1 Answers1

2

As per my comment (and also the next comment). The rect function needs to be used correctly.

here is an example:

import pygame
pygame.init()
fen=pygame.display.set_mode((320, 320))
clock = pygame.time.Clock()
loop=True

counter = 0
while loop:
    counter += 1
    top_x = 10
    top_y = 10
    width = 100
    height = 100
    pygame.draw.rect(fen, (0, 0, 255), (top_x, top_y, width, height))
    pygame.display.update()
    clock.tick(60)        

    if counter >= 100: loop = False

which gives this:

enter image description here

You can actually refer to the docts here: https://www.pygame.org/docs/ref/rect.html#pygame.Rect

D.L
  • 4,339
  • 5
  • 22
  • 45