Two five sided polygons are drawn, one on top of another Each gets five coordinates in a for loop.
Since we did not specify a width, it is filled with the color, either cmap[0]=red, or cmap[2]=blue for the two polygons.
# Ex03.py
# Polygon
import pygame as pg
from math import sin,cos,radians
colors = ['red','green','blue','cyan',
'purple','brown','magenta','orange']
cmap = tuple(map(pg.Color,colors))
pg.init()
screen = pg.display.set_mode((640, 480))
pg.display.set_caption('Ex03. Polygon')
center = 300,240
radius = 200
screen.fill(pg.Color("white"))
poly1 = []
for i in range(5):
angDeg = 45*i
angRad = radians(angDeg)
poly1.append((center[0]+radius*cos(angRad),
center[1]+radius*sin(angRad) ) )
poly2 = []
for i in range(4,9):
angDeg = 45*i
angRad = radians(angDeg)
poly2.append((center[0]+radius*cos(angRad),
center[1]+radius*sin(angRad) ) )
pg.draw.polygon(screen,cmap[0],poly1)
pg.draw.polygon(screen,cmap[2],poly2)
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