美文网首页
PYGAME BASIC

PYGAME BASIC

作者: gaoljay | 来源:发表于2016-09-05 14:42 被阅读0次

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

    相关文章

      网友评论

          本文标题:PYGAME BASIC

          本文链接:https://www.haomeiwen.com/subject/asurettx.html