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:

<pre>import pygame
import sys
from pygame.locals import *
</br>

initialization

pygame.init()
</br>

initial your screen

screen = pygame.display.set_mode((600,500))
</br>

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

my_font = pygame.font.Font(None, 60)
</br>

set up colors

white = 255, 255, 255
blue = 0, 0, 255
</br>

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

textImage = my_font.render("Hello Pygame", True, white)
</br>

how to draw

1. clean screen

2. draw it

3. display it in screen

</br>

screen.fill(blue)

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

pygame.display.update()

</br>

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()
</pre>

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[]

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容