PYGAME BASIC

Color:

red 0-255
green 0-255
blue 0-255

Coordinate:

(x, y)
x: from left to right
y: from top to bottom

Display String:

import pygame
import sys
from pygame.locals import *

initialization

pygame.init()

initial your screen

screen = pygame.display.set_mode((600,500))

initial the font you want to use--font, size

my_font = pygame.font.Font(None, 60)

set up colors

white = 255, 255, 255
blue = 0, 0, 255

set up text you want to write in your screen---string, alias, color

textImage = my_font.render("Hello Pygame", True, white)

how to draw

1. clean screen

2. draw it

3. display it in screen


screen.fill(blue)

screen.blit(textImage, (100, 100))

pygame.display.update()


add loop so it will not close

while True:
for event in pygame.event.get():
if event.type in (QUIT, KEYDOWN):
sys.exit()
screen.fill(blue)
screen.blit(textImage, (100, 100))
pygame.display.update()

Draw a line:

 pygame.draw.line(screen, color, positionX1,positionX2, width)

Draw a circle:

 pygame.draw.circle(screen, color, position, radius, width)

Draw a rectangle:

position = 0, 0, 100, 100
pygame.draw.rect(screen, color, position, width)

Draw an arc:

position = 0, 0, 100, 100
pygame.draw.arc(screen, color, position, start_angle, end_angle, width)

wertyuiop[]

你可能感兴趣的:(PYGAME BASIC)