PyGame পরিচিতি
Pygame হলো পাইথনের একটি মাল্টিমিডিয়া লাইব্রেরি যা গেম এবং মাল্টিমিডিয়া অ্যাপ্লিকেশন তৈরিতে ব্যবহৃত হয়। এটি SDL (Simple DirectMedia Layer) লাইব্রেরির ওপর তৈরি।
প্রোগ্রাম: বৃত্ত, উপবৃত্ত, আয়ত আঁকা
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('Drawing Shapes')
# ব্যাকগ্রাউন্ড সাদা করুন
display_surface.fill(WHITE)
# ১. বৃত্ত আঁকুন: pygame.draw.circle(surface, color, center, radius, width)
# width=0 মানে ফিল্ড বৃত্ত
pygame.draw.circle(display_surface, BLACK, (300, 250), 80, 0)
# ২. উপবৃত্ত আঁকুন: pygame.draw.ellipse(surface, color, rect, width)
# rect = (x, y, width, height)
pygame.draw.ellipse(display_surface, RED, (50, 200, 100, 150), 4)
# ৩. আয়ত আঁকুন: pygame.draw.rect(surface, color, rect)
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()
প্রধান ফাংশনস
| ফাংশন | প্যারামিটারস | বিবরণ |
|---|---|---|
pygame.draw.circle | surface, color, center, radius, width=0 | বৃত্ত আঁকে। width=0 ফিল্ড, >0 আউটলাইন épaisseur |
pygame.draw.ellipse | surface, color, rect, width=0 | উপবৃত্ত আঁকে। rect=(x, y, w, h) |
pygame.draw.rect | surface, color, rect, width=0 | আয়ত আঁকে। |
pygame.draw.line | surface, color, start_pos, end_pos, width=1 | রেখা আঁকে। |
pygame.draw.polygon | surface, color, points, width=0 | বহুভুজ আঁকে। points=[(x1,y1), (x2,y2), ...] |
চলানোর নির্দেশনা
pip install pygameইনস্টল করুন।- কোড সেভ করুন
draw_shapes.pyনামে। python draw_shapes.pyরান করুন।- উইন্ডো বন্ধ করতে クローズ বাটন চাপুন।
নোট: pygame.display.update() বা pygame.display.flip() লুপের ভেতরে থাকতে হয় যাতে ড্রইং রিফ্রেশ হয়।