Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 用pygame绘制未填充的抗锯齿圆_Python_Pygame_Geometry_Antialiasing - Fatal编程技术网

Python 用pygame绘制未填充的抗锯齿圆

Python 用pygame绘制未填充的抗锯齿圆,python,pygame,geometry,antialiasing,Python,Pygame,Geometry,Antialiasing,我正在创建一个python模块来简化Pygame,我发现它相当复杂。它具有可启用和禁用的抗锯齿模式 我可以使用pygame.draw轻松绘制不带抗锯齿的圆 但是我必须使用pygame.gfxdraw来进行抗锯齿。我可以通过组合gfxdraw.aacircle和filled_circle来绘制填充的抗锯齿圆,但我不能绘制非填充的抗锯齿圆,除非它们的厚度为1像素(gfxdraw.aacircle没有厚度参数)。我已经有了一个绘制厚抗锯齿线的函数,该函数与 我的问题是如何创建未填充的抗锯齿圆?我找到的

我正在创建一个python模块来简化Pygame,我发现它相当复杂。它具有可启用和禁用的抗锯齿模式

我可以使用pygame.draw轻松绘制不带抗锯齿的圆

但是我必须使用pygame.gfxdraw来进行抗锯齿。我可以通过组合gfxdraw.aacircle和filled_circle来绘制填充的抗锯齿圆,但我不能绘制非填充的抗锯齿圆,除非它们的厚度为1像素(gfxdraw.aacircle没有厚度参数)。我已经有了一个绘制厚抗锯齿线的函数,该函数与


我的问题是如何创建未填充的抗锯齿圆?我找到的解决方案是通过绘制多条连接线来手动绘制圆,但我不知道如何做到这一点,可能会有一个更快的解决方案。另外,我不能为圆心画一个大的圆和一个小的圆,因为圆心是不透明的。

基本上,我画了一个多边形,在圆心的轮廓上每隔3°画一个点,我在圆心和圆心的外侧画了一个点,然后所有的点都连接起来,形成了一个抗锯齿的厚圆。我也将其用于圆弧

def arc(center, xradius, yradius, start_angle, stop_angle, color=BLACK)
    arc_length = (stop_angle - start_angle)  # Arc length
    segment_length = math.radians(3) * min(xradius, yradius)  # Length of one segment
    segment_length = max((segment_length, 2))  # Minimum length of 2

    nb_pts = int(arc_length/2*xradius*yradius / segment_length) + 1  # Nb points
    angle = arc_length / (nb_pts-1)  # Angle between each points
    points = []
    width = line_width//2  # Line thickness (half on each side of the circle)
    for i in range(nb_pts):  # Inner border
        x = round(math.cos(start_angle + angle*i) * (xradius-width) + center[0])
        y = round(-math.sin(start_angle + angle*i) * (yradius-width) + center[1])  # - is for counter clockwise
        points.append((x, y))  # Add point

    for i in range(nb_pts-1, -1, -1):  # Outer border
        x = round(math.cos(start_angle + angle*i) * (xradius+width) + center[0])
        y = round(-math.sin(start_angle + angle*i) * (yradius+width) + center[1])
        points.append((x, y))  # Add point

    polygon(points, color, True)  # True is for filled polygon
我调用这样的函数来画一个圆,改变椭圆的x半径和yradius

arc(center, radius, radius, 0, 2*math.pi, color)

基本上,我画了一个多边形,每个3°在圆的轮廓上画一个点,我在圆的内外画了一个多边形,然后所有的点都连接起来,形成了一个抗锯齿的厚圆。我也将其用于圆弧

def arc(center, xradius, yradius, start_angle, stop_angle, color=BLACK)
    arc_length = (stop_angle - start_angle)  # Arc length
    segment_length = math.radians(3) * min(xradius, yradius)  # Length of one segment
    segment_length = max((segment_length, 2))  # Minimum length of 2

    nb_pts = int(arc_length/2*xradius*yradius / segment_length) + 1  # Nb points
    angle = arc_length / (nb_pts-1)  # Angle between each points
    points = []
    width = line_width//2  # Line thickness (half on each side of the circle)
    for i in range(nb_pts):  # Inner border
        x = round(math.cos(start_angle + angle*i) * (xradius-width) + center[0])
        y = round(-math.sin(start_angle + angle*i) * (yradius-width) + center[1])  # - is for counter clockwise
        points.append((x, y))  # Add point

    for i in range(nb_pts-1, -1, -1):  # Outer border
        x = round(math.cos(start_angle + angle*i) * (xradius+width) + center[0])
        y = round(-math.sin(start_angle + angle*i) * (yradius+width) + center[1])
        points.append((x, y))  # Add point

    polygon(points, color, True)  # True is for filled polygon
我调用这样的函数来画一个圆,改变椭圆的x半径和yradius

arc(center, radius, radius, 0, 2*math.pi, color)