pygame.draw.line



import traceback
import math
import pygame
from 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


@prepare
def main():
    while True:
        if not cin():
            break
        draw()
        
            
if __name__ == '__main__':
    try:
        main()
    except:
        traceback.print_exc()
        pygame.quit()
        input()

            


### 2 左右两边蓝不一样宽, ### 1 和 ### 3 不一样宽 

 ==> 先按照元线段上色,再在右边上色,再在左边上色,所以左右长度各为 width / 2 - 1, width / 2 + 1


### 5 

==> PyGame 画弧线真难看。


### 6 若要填充矩形,先计算好。(连小学数学也要为难我。。。。)

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值