Saturday, February 4, 2017

Ex04. 4 Ellipses

4 ellipses are drawn. We use the same bounding rectangles as in example 1.


Thus we change the draw.rectangle to draw.ellipse from that example.



# Ex04.py 
# 4 Ellipses

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('Ex01. 4 Ellipses')

w,h = 250,200 # dimensions of each rectangle
# top row - blue, red
# bottom row - green, purple

padx,pady = 20,10

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.ellipse(screen,blue,rect1)
pg.draw.ellipse(screen,red,rect2)
pg.draw.ellipse(screen,green,rect3)
pg.draw.ellipse(screen,purple,rect4)

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:


4 comments:

  1. It was a beneficial workout for me to go through your webpage. Private tutor Gladwyne It definitely stretches the limits with the mind when you go through very good info and make an effort to interpret it properly. I am going to glance up this web site usually on my PC. Thanks for sharing

    ReplyDelete
  2. You have done an outstanding job of writing Private tutor Tampa

    ReplyDelete
  3. The way you have guided ellipses via example is very useful for me Private tutor Windermere

    ReplyDelete