如何圆化多边形的边缘?

问题描述 投票:0回答:1

我想在 pygame 中圆化多边形的边缘,希望没有任何额外的模块。

这是我的一些代码:

import pygame

pg.init()

screen=pg.set_mode((200,200))
screen.fill(255,255,255)

#                                            top left  b/left   b/right  top right
pg.draw.polygon(self.screen, (230,255,100), ((90,125), (70,75), (80,75), (100,125)))
python pygame polygon
1个回答
0
投票

为了在 Pygame 中圆化多边形的边缘,此代码使用在顶点绘制的圆来近似多边形的圆角。

import pygame as pg
import math

pg.init()

screen = pg.display.set_mode((200, 200))
screen.fill((255, 255, 255))

def draw_rounded_polygon(surface, color, points, radius):
    # Draw the main body of the polygon
    pg.draw.polygon(surface, color, points)

    # Draw arcs at the vertices to round the corners
    for i in range(len(points)):
        x, y = points[i]
        pg.draw.circle(surface, color, (int(x), int(y)), radius)

# Define the points of the polygon
points = [(90, 125), (70, 75), (80, 75), (100, 125)]
# Set the radius for rounding
radius = 10

draw_rounded_polygon(screen, (230, 255, 100), points, radius)

# Update the display
pg.display.flip()

# Main loop
running = True
while running:
    for event in pg.event.get():
        if event.type == pg.QUIT:
            running = False

pg.quit()

请参考这篇文章,因为我已经参考了这篇文章GeeksForGeeks - 如何在 PyGame 中绘制带圆角的矩形?

请随时发表评论以获取更多帮助..

© www.soinside.com 2019 - 2024. All rights reserved.