Tuesday 8 December 2015

Pygame: Draw simple tree

Following application draws a tree using rectangle and two triangles.
#import pygame
import pygame

#initialize game engine
pygame.init()

window_width=500
window_height=500

animation_increment=10
clock_tick_rate=20

#Open a window
size = (window_width, window_height)
screen = pygame.display.set_mode(size)

#Set title to the window
pygame.display.set_caption("Hello World")

dead=False

#Initialize values for color (RGB format)
WHITE=(255,255,255)
RED=(255,0,0)
GREEN=(0,255,0)
BLUE=(0,0,255)
BLACK=(0,0,0)
BROWN=(165,42,42)

clock = pygame.time.Clock()
screen.fill(WHITE)

def draw_tree():
    pygame.draw.rect(screen, BROWN, [260, 400, 30, 100])
    pygame.draw.polygon(screen, GREEN, [[350, 400], [275, 250], [200, 400]])
    pygame.draw.polygon(screen, GREEN, [[340, 350], [275, 230], [210, 350]])

while(dead==False):
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            dead = True
    draw_tree()
    pygame.display.flip()
    clock.tick(clock_tick_rate)




Previous                                                 Next                                                 Home

No comments:

Post a Comment