We use the rectangles from Example 1. For the rectangle we need a center point obtained by rect1.center, etc.
We also need a radius which we have set to 100.
# Ex05.py
# 4 Circles
import pygame as pg
white = pg.Color('white')
blue = pg.Color('blue')
red = pg.Color('red')
green = pg.Color('green')
purple = pg.Color('purple')
pg.init()
screen = pg.display.set_mode((640, 480))
pg.display.set_caption('Ex05. 4 Circles')
w,h = 250,200 # dimensions of each rectangle
# top row - blue, red
# bottom row - green, purple
padx,pady = 20,10
radius = 100
rect = pg.Rect(0,0,w,h)
rect1 = rect.copy()
rect1.bottomright=(320-padx,240-pady)
rect2 = rect.copy()
rect2.bottomleft=(320+padx,240-pady)
rect3 = rect.copy()
rect3.topright=(320-padx,240+pady)
rect4 = rect.copy()
rect4.topleft=(320+padx,240+pady)
screen.fill(white)
pg.draw.circle(screen,blue,rect1.center,radius)
pg.draw.circle(screen,red,rect2.center,radius)
pg.draw.circle(screen,green,rect3.center,radius)
pg.draw.circle(screen,purple,rect4.center,radius)
pg.display.update()
done = False
while not done:
for event in pg.event.get():
if event.type == pg.QUIT:
done = True
pg.quit()
This is the output:
No comments:
Post a Comment