单击屏幕手动画贝赛尔曲线

"""
   单击屏幕手动画贝赛尔曲线
   为什么画到一定的点数后会和原点(0,0)相连?
"""

import pygame
import pygame.gfxdraw

def main():
    pygame.init()
    screen = pygame.display.set_mode((500,500))    
    pygame.display.set_caption("pygame单击屏幕手动画贝赛尔曲线程序示例www.lixingqiu.com")
    sur = pygame.Surface(screen.get_size(), pygame.SRCALPHA, 32)

    # 贝塞尔曲线上的坐标点
    points = []    
    color = (255,0,255)
    steps = 5
    running = True 
    while running:
        e = pygame.event.wait()
        if e.type == pygame.QUIT:running = False
        clicked = pygame.mouse.get_pressed()
        if clicked[0]:            # 如果单击左键增加一个点
            pos = pygame.mouse.get_pos()
            points.append(pos)    # 添加点后重绘sur
            pygame.draw.circle(sur,(250,250,250),pos,2)
            if len(points)>2:
               sur.fill((0,0,0))
               [pygame.draw.circle(sur,(250,250,250),p,2) for p in points]
               pygame.gfxdraw.bezier(sur, points,steps,color)

You must log in to read the rest of this article. Please log in or register as a user.