
# draw.py
# lots of drawing examples

import pygame
from math import pi
from pygame.locals import *



# some colors
BLACK = (   0,   0,   0)
WHITE = ( 255, 255, 255)

RED   = ( 255,   0,   0)
GREEN = (   0, 255,   0)
BLUE  = (   0,   0, 255)

# -------------------------------

def drawStuff(screen):

    # draw a green line from (0,0) to (100,100); 5 pixels thick
    pygame.draw.line(screen, GREEN, (0, 0), (100, 100), 5)

    # draw several red lines from (0,10) to (100,110); 5 pixels thick
    for y in range(0, 100, 10):
        pygame.draw.line(screen, RED, (0, 10+y), (100, 110+y), 5)

    # compare normal and anti-aliased diagonal lines
    pygame.draw.line(screen, BLACK, (480, 425), (550, 325), 1)
    pygame.draw.aaline(screen, BLACK, (500, 425), (570, 325), 1)

    # draw a unfilled black rectangle;
    # top-left (x,y) = (20,20), (width,height) = (250,100)
    pygame.draw.rect(screen, BLACK, (20, 20, 250, 100), 2)


    # draw a filled (width == 0) blue circle at (340,60) radius 40
    pygame.draw.circle(screen, BLUE, (340, 60), 40, 0)

    # draw a mustard-colored ellipse, inside a rectangle defined as
    # top-left (x,y) = (400,20), (width,height) = (150,100)
    MUSTARD = (204, 204, 0)
    pygame.draw.ellipse(screen, MUSTARD, (400, 20, 150, 100), 0)

    # draw fours arc to form an ellipse;
    # an arc has a bounding rectangle, start angle, end angle, line width.
    # Use radians for the angles
    pygame.draw.arc(screen, BLACK,(20, 220, 250, 200), 0,      pi/2,   2)
    pygame.draw.arc(screen, GREEN,(20, 220, 250, 200), pi/2,   pi,     2)
    pygame.draw.arc(screen, BLUE, (20, 220, 250, 200), pi,     3*pi/2, 2)
    pygame.draw.arc(screen, RED,  (20, 220, 250, 200), 3*pi/2, 2*pi,   2)


    # draw a thick black triangle as a polygon
    # using a sequence of (x,y) points
    pygame.draw.polygon(screen, BLACK, ((100, 100), (0, 200), (200, 200)), 5)

    # draw a green filled polygon
    points = ( (237, 372), (332, 319),
               (483, 335), (422, 389),
               (447, 432), (359, 379),
               (320, 439), (232, 392) )
    pygame.draw.polygon(screen, GREEN, points, 0)


    # draw thick red connected lines (that looks like "Hi")
    points = ( (370, 110), (370, 187),
               (372, 143), (411, 144),
               (412, 187), (412, 110),
               (412, 187), (432, 177),
               (436, 146), (433, 180) )
    pygame.draw.lines(screen, RED, False, points, 3)


    # print("All system fonts:", sorted(pygame.font.get_fonts()))

    # 1. load font; set size, bold, not italic
    font = pygame.font.SysFont('comicsansms', 48, True, False)  
              # 'comicsansms', 'timesnewroman', 'arial'
    # font = pygame.font.Font(None, 48)
 
    # 2. render anti-aliased black text as an image
    textImage = font.render("Hello World", True, BLACK)

    # 3. draw text image with its top-left corner at (270,250)
    screen.blit(textImage, (270, 250))

    # use a custom font
    myFont = pygame.font.Font("GringoNights.ttf", 40)
    labelImage = myFont.render("Python in the Wild West", True, BLUE)
    screen.blit(labelImage, (200, 210))

    # load graphics; top-left at (70,245)
    image = pygame.image.load("saengthong.jpg").convert()
    screen.blit(image, (70,245))


# -------------- main --------------

pygame.init()

screen = pygame.display.set_mode((640, 480))
screen.fill(WHITE)
pygame.display.set_caption("Drawing Examples")

drawStuff(screen)

clock = pygame.time.Clock()

running = True
while running:  # game loop
    clock.tick(30)

    # handle events
    for event in pygame.event.get():
        if event.type == QUIT:
            running = False

    # update game state (nothing yet)
    # redraw game
    pygame.display.update()

pygame.quit()
