📜  在Python中使用 Arcade 绘制三角形

📅  最后修改于: 2022-05-13 01:55:36.947000             🧑  作者: Mango

在Python中使用 Arcade 绘制三角形

Arcade 是一个用于开发二维游戏的Python库。 Arcade 需要支持 OpenGL 3.3+。在街机中,基本绘图不需要了解如何定义函数或类或如何进行循环,只需我们有用于绘制图元的内置函数。

用于绘制三角形的 Arcade 内置函数:

1: arcade.draw_traingle_outline():该函数用于绘制三角形的轮廓。

让我们看一个例子来更好地理解它的功能。

Python3
#import module
import arcade
  
# Open the window. Set the window title and
# dimensions (width and height)
arcade.open_window(600, 600, "Draw  a triangle for GfG ")
  
# set background color
arcade.set_background_color(arcade.color.BLACK)
  
# Start the render process.
arcade.start_render()
  
# triangle function
arcade.draw_triangle_outline(300, 200,
                             80, 80,
                             100, 300,
                             arcade.color.YELLOW, 1)
  
  
# finished drawing
arcade.finish_render()
  
# display everything
arcade.run()


Python3
# import
import arcade
  
# Open the window. Set the window title and 
# dimensions (width and height)
arcade.open_window(600, 600, "Draw  a triangle for GfG ")
  
# set background color
arcade.set_background_color(arcade.color.BLACK)
  
# Start the render process.
arcade.start_render()
  
# draw triangle
arcade.draw_triangle_filled(300, 200,
                            80, 80,
                            100, 300,
                            arcade.color.YELLOW)
  
# finish drawing
arcade.finish_render()
  
# display everything
arcade.run()


输出:

2: arcade.draw_triangle_fill():该函数用于绘制一个填充颜色的三角形。

例子:

蟒蛇3

# import
import arcade
  
# Open the window. Set the window title and 
# dimensions (width and height)
arcade.open_window(600, 600, "Draw  a triangle for GfG ")
  
# set background color
arcade.set_background_color(arcade.color.BLACK)
  
# Start the render process.
arcade.start_render()
  
# draw triangle
arcade.draw_triangle_filled(300, 200,
                            80, 80,
                            100, 300,
                            arcade.color.YELLOW)
  
# finish drawing
arcade.finish_render()
  
# display everything
arcade.run()

输出: