Pygame में ड्राइंग
Pygame मल्टीमीडिया/गेम लाइब्रेरी है। pygame.draw मॉड्यूल से वृत्त, दीर्घवृत्त, आयत, रेखा, बहुभुज आदि बना सकते हैं।
पूर्ण कोड उदाहरण
import pygame
pygame.init()
# रंग परिभाषित करें (RGB)
WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
BLUE = (0, 0, 150)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
# विंडो आयाम
X, Y = 400, 400
# डिस्प्ले सतह बनाएं
display_surface = pygame.display.set_mode((X, Y))
pygame.display.set_caption('आकृतियाँ बनाना')
# पृष्ठभूमि भरें
display_surface.fill(WHITE)
# वृत्त: draw.circle(surface, color, center, radius, width=0)
pygame.draw.circle(display_surface, BLACK, (300, 250), 80, 0)
# दीर्घवृत्त: draw.ellipse(surface, color, rect, width)
# rect = (x, y, width, height)
pygame.draw.ellipse(display_surface, RED, (50, 200, 100, 150), 4)
# आयत: draw.rect(surface, color, rect, width=0)
pygame.draw.rect(display_surface, BLUE, (50, 50, 150, 100))
# मुख्य लूप
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.display.update()
pygame.quit()
मुख्य ड्राइंग फ़ंक्शन्स
| फ़ंक्शन | पैरामीटर्स | विवरण |
|---|---|---|
circle | surface, color, center, radius, width | वृत्त (width=0 भरा हुआ) |
ellipse | surface, color, rect, width | दीर्घवृत्त |
rect | surface, color, rect, width | आयत |
line | surface, color, start, end, width | रेखा |
polygon | surface, color, points, width | बहुभुज |
arc | surface, color, rect, start_angle, stop_angle, width | चाप |
आउटपुट
सफेद पृष्ठभूमि पर: काला वृत्त (दाएं), लाल दीर्घवृत्त (बाएं नीचे), नीला आयत (बाएं ऊपर)।
