Saturday, February 4, 2017

Ex06. 4 Arcs

Arcs are same as an ellipse with start angle of 0 and stop angle of 360.


Here we have 4 arcs based on the same ellipse (and its bounding rectangle), with different start and stop angles.



# Ex06.py 
# 4 Arcs

import pygame as pg
from math import radians as rad

colors = ['red','green','blue','cyan',
    'purple','brown','magenta','orange']
cmap = list(map(pg.Color,colors))


pg.init()

screen = pg.display.set_mode((640, 480))
pg.display.set_caption('Ex06. 4 Arcs')

rect = pg.Rect(50,50,540,380)

screen.fill(pg.Color("white"))

def get_rad(start,stop):
 return rad(start), rad(stop)

# arc angles
arc1_start, arc1_stop = get_rad(0,45)
arc2_start, arc2_stop = get_rad(60,180)
arc3_start, arc3_stop = get_rad(190,255)
arc4_start, arc4_stop = get_rad(260,355)

pg.draw.arc(screen,cmap[0],rect,arc1_start,arc1_stop,3)
pg.draw.arc(screen,cmap[1],rect,arc2_start,arc2_stop,3)
pg.draw.arc(screen,cmap[2],rect,arc3_start,arc3_stop,3)
pg.draw.arc(screen,cmap[3],rect,arc4_start,arc4_stop,3)

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