简体   繁体   English

如何在 pygame 中创建菱形

[英]How to create a rhomboid in pygame

I want to create a rhomboid like this.我想创建一个像这样的菱形。 I can not do this I found the solution just for the diamond.我无法做到这一点,我只为钻石找到了解决方案。

图片

my code:我的代码:

import pygame as pg
pg.init()
screen = pg.display.set_mode((500, 700))
clock = pg.time.Clock()
BG_COLOR = pg.Color('gray12')
BLUE = pg.Color('dodgerblue')
points = [(200, 200), (250, 250), (200, 300), (150, 250)]
done = False
while not done:
    for event in pg.event.get():
        if event.type == pg.QUIT:
            done = True
    screen.fill(BG_COLOR)
    pg.draw.polygon(screen, BLUE, points)
    pg.display.flip()
    clock.tick()

Write a function that draws a rhomboid with a with , height and offset:编写一个 function 来绘制一个带有withheight和 offset 的菱形:

import pygame as pg

def drawRhomboid(surf, color, x, y, width, height, offset, thickness=0):
    points = [
        (x + offset, y), 
        (x + width + offset, y), 
        (x + width, y + height), 
        (x, y + height)]
    pg.draw.polygon(surf, color, points, thickness)

pg.init()
screen = pg.display.set_mode((500, 700))
clock = pg.time.Clock()
BG_COLOR = pg.Color('gray12')
BLUE = pg.Color('dodgerblue')

done = False
while not done:
    for event in pg.event.get():
        if event.type == pg.QUIT:
            done = True
    screen.fill(BG_COLOR)
    drawRhomboid(screen, BLUE, 50, 50, 300, 200, 100, 3)
    pg.display.flip()
    clock.tick()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM