pythonpygame

Can I make Pygame rectangle outline with two different color?


Image of rectangle I want to make from paint

if(blueBoxX!=redBoxX or blueBoxY!=redBoxY):
    pygame.draw.rect(scrn, (0, 100, 255), (blueBoxX*75, blueBoxY*75, 75, 75), 3)
    pygame.draw.rect(scrn, (255, 100, 0), (redBoxX*75, redBoxY*75, 75, 75), 3)
else:
    "when they collide I want it to show by showing two colors at one spot"

I was thinking of using just straight line by pygame.draw.line but wanted to know if pygame.draw.rect was possible option


Solution

  • No. pygame.draw.rect() has only one color and does not have the option of drawing only some sections or sides of the outline. I suggest to use pygame.draw.lines():

    x, y = blueBoxX, blueBoxY
    l1 = [(x*75, y*75 + 75), (x*75, y*75), (x*75 + 75, y*75)]
    l2 = [(x*75, y*75 + 75), (x*75 + 75, y*75 + 75), (x*75 + 75, y*75)]
    pygame.draw.lines(scrn, (0, 100, 255), False, l1, 3)
    pygame.draw.lines(scrn, (255, 100, 0), False, l2, 3)