在Python中使用 Arcade 库绘制椭圆
先决条件:街机图书馆
Arcade库是一个现代Python模块,用于开发具有迷人图形和声音的 2D 视频游戏。它是一个面向对象的库。它可以像 IDE 中的任何其他Python包一样安装。
Arcade模块有两个用于绘制椭圆的内置函数,即arcade.draw_ellipse_outline()和 arcade.draw_ellipse_filled() 。这是Arcade模块中的一个加分点,否则,您一定已经注意到,在诸如turtle之类的Python模块中,您需要创建一个函数来绘制任何原始设计。
1) arcade.draw_ellipse_outline():该方法用于绘制椭圆的轮廓。
Syntax: arcade.draw_ellipse_outline(centre_x, centre_y, width, height, color, border_width, tilt_angle, num_segments)
1. centre_x: x position that is the center of the ellipse.
2. centre_y: y position that is the center of the ellipse.
3. Width: Width of the ellipse.
4. Height: Height of the ellipse.
5. Color: This is used to define the colors used for making outline of the ellipse with the help of arcade.color function.
6. border_width: Width of the ellipse outline in pixels.
7. tilt_angle: Angle in degrees to tilt the ellipse.
8. num_segments: Number of triangle segments that make up this ellipse. The default value is -1 that clearly means that arcade will calculate amount of segments based on the size of the ellipse.
上述方法的实现:
Python3
# Import required modules
import arcade
# Specify Parameters
SCREEN_WIDTH = 600
SCREEN_HEIGHT = 800
SCREEN_TITLE = "Welcome to GeeksForGeeks "
# Open the window
arcade.open_window(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)
# Set the background color
arcade.set_background_color(arcade.color.BABY_BLUE)
# Start drawing
arcade.start_render()
# Draw ellipse
arcade.draw_ellipse_outline(
400, 363, 250, 130, arcade.color.AMBER, 10, 180, -1)
# Finish drawing
arcade.finish_render()
# Display everything
arcade.run()
Python3
# Import required modules
import arcade
# Specify Parameters
SCREEN_WIDTH = 600
SCREEN_HEIGHT = 800
SCREEN_TITLE = "Welcome to GeeksForGeeks "
# Open the window
arcade.open_window(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)
# Set the background color
arcade.set_background_color(arcade.color.BABY_BLUE)
# start drawing
arcade.start_render()
# Draw ellipse
arcade.draw_ellipse_filled(400, 363, 250, 130, arcade.color.AMBER, 180, -1)
# Finish drawing
arcade.finish_render()
# Display everything
arcade.run()
输出:
2) arcade.draw_ellipse_filled():该方法用于绘制填充椭圆。
Syntax: arcade.draw_ellipse_filled(centre_x, centre_y, width, height, color, tilt_angle, num_segments)
1. centre_x: x position that is the center of the ellipse.
2. centre_y: y position that is the center of the ellipse.
3. Width: Width of the ellipse.
4. Height: Height of the ellipse.
5. Color: This is used to define the colors used for making outline of the ellipse with the help of arcade.color function.
6. border_width: Width of the ellipse outline in pixels.
7. tilt_angle: Angle in degrees to tilt the ellipse.
8. num_segments: Number of triangle segments that make up this ellipse. The default value is -1 that clearly means that arcade will calculate amount of segments based on the size of the ellipse.
除了 border_width 之外,所有其他参数都与arcade.draw_ellipse_outline ()相同。在arcade.draw_ellipse_filled()中,我们不需要 border_width。
上述方法的实现:
蟒蛇3
# Import required modules
import arcade
# Specify Parameters
SCREEN_WIDTH = 600
SCREEN_HEIGHT = 800
SCREEN_TITLE = "Welcome to GeeksForGeeks "
# Open the window
arcade.open_window(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)
# Set the background color
arcade.set_background_color(arcade.color.BABY_BLUE)
# start drawing
arcade.start_render()
# Draw ellipse
arcade.draw_ellipse_filled(400, 363, 250, 130, arcade.color.AMBER, 180, -1)
# Finish drawing
arcade.finish_render()
# Display everything
arcade.run()
输出: