Friday, February 3, 2017

Ex02. 180 Radial Lines

180 lines are draw from 300, 240 in different directions.


All the lines have a length of 200. They have a width of 5 and have the 8 colors defined in the colors list. It is converted to pygame colors in cmap tuple.



# Ex02.py 
# 180 Radial Lines

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('Ex02. 180 Radial Lines')

center = 300,240
radius = 200

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

for i in range(180):
 angDeg = 2*i
 angRad = radians(angDeg)
 pos = ( center[0]+radius*cos(angRad),
   center[1]+radius*sin(angRad)  )
 pg.draw.line(screen,cmap[i%8],center,pos,5)

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