Pygame. Draw. Line

Source: Internet
Author: User



import tracebackimport mathimport pygamefrom pygame.locals import *pygame.display.init()pygame.font.init()sizes = {    "screen" : ( 300, 480 )}colors = {    "line" : ( 255, 255, 255 ),    "rect" : ( 100, 100, 100 ),    "circle" : ( 100, 100, 100 ),    "border" : ( 52, 135, 184 ),    "background" : ( 255, 255, 255 )}screen = pygame.display.set_mode( sizes["screen"], 0, 32 )def cin():    for e in pygame.event.get():        mouse_pos = pygame.mouse.get_pos()        print mouse_pos        if e.type == KEYDOWN:            if e.key == K_ESCAPE:                return False    return True            def draw():    screen.fill( colors["background"] )    ### 1    pygame.draw.line( screen,                      colors["border"],                      ( 0, 0 ),                      ( 0, sizes["screen"][1] ),                      10 )    pygame.draw.line( screen,                      colors["line"],                      ( 0, 0 ),                      ( 0, sizes["screen"][1] ),                      1 )    ### 2    pygame.draw.line( screen,                      colors["border"],                      ( 100, 0 ),                      ( 100, 300 ),                      10 )    pygame.draw.line( screen,                      colors["line"],                      ( 100, 0 ),                      ( 100, 300 ),                      1 )    ### 3    pygame.draw.line( screen,                      colors["border"],                      ( 200, 100 ),                      ( 200, -100 ),                      10 )    pygame.draw.line( screen,                      colors["line"],                      ( 200, 100 ),                      ( 200, -100 ),                      1 )    ### 4    pygame.draw.line( screen,                      colors["border"],                      ( sizes["screen"][0], 0 ),                      ( sizes["screen"][0], sizes["screen"][1] ),                      10 )    pygame.draw.line( screen,                      ( 255, 255, 255 ),                      ( sizes["screen"][0], 0 ),                      ( sizes["screen"][0], sizes["screen"][1] ),                      1 )    ### 5    pygame.draw.circle( screen, colors["circle"], ( 100, 100 ), 50 )    pygame.draw.arc( screen, colors["circle"], ( 150, 150, 100, 100 ), 0, math.pi, 2 )    ### 6    X = 10 / 2 + 1    DX = 100 - ( ( ( 10 / 2 ) + 1 ) + ( ( 10 / 2 ) - 1 ) )    pygame.draw.rect( screen,                      colors["rect"],                      ( X, 200, DX, 50 ) )    pygame.display.update()def prepare( func ):    def _pre():        pygame.event.set_grab( True )        func()        pygame.event.set_grab( False )        pygame.quit()    return _pre@preparedef main():    while True:        if not cin():            break        draw()                    if __name__ == '__main__':    try:        main()    except:        traceback.print_exc()        pygame.quit()        input()            


### 2 the left and right sides of blue are different in width, ### 1 and ### 3 are different in width

==> First, color the line segments on the right and then on the left. Therefore, the left and right lengths are respectively width/2-1, width/2 + 1.


### 5

==> Pygame is really ugly to draw an arc.


### 6 if you want to fill the rectangle, calculate it first. (Even in elementary school mathematics, it is difficult for me ....)

Pygame. Draw. Line

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.