在 Python3 中使用 Arcade 绘制抛物线
Arcade 是一个用于开发二维游戏的Python库。 Arcade 需要支持 OpenGL 3.3+。在街机中,基本绘图不需要了解如何定义函数或类或如何进行循环,只需我们有用于绘制图元的内置函数。
用于绘制抛物线的 Arcade 内置函数:-
1. arcade.draw_parabola_outline( ):该函数绘制抛物线的轮廓。
Syntax: arcade.draw_parabola_outline(start_x , start_y, end_x , height , color, border_width, tilt_angle)
Parameters:
- start_x : The starting x position of the parabola
- start_y : The starting y position of the parabola
- end_x : The ending x position of the parabola
- height : The height of the parabola
- color : The color of the parabola
- border_width: The width of the parabola
- tilt_angle : The angle of the tilt of the parabola.
例子:
Python3
# import module
import arcade
# Open the window. Set the window title and dimensions (width and height)
arcade.open_window(600, 600, "Draw a parabola for GfG ")
# set background
arcade.set_background_color(arcade.color.WHITE)
# Start the render process.
arcade.start_render()
# function to draw a parabola
arcade.draw_parabola_outline(50, 80, 100, 120, arcade.color.GREEN, 10, 0)
# finish drawing
arcade.finish_render()
Python3
# import module
import arcade
# Open the window. Set the window title and dimensions (width and height)
arcade.open_window(600, 600, "Draw a parabola for GfG ")
# set background
arcade.set_background_color(arcade.color.WHITE)
# Start the render process.
arcade.start_render()
# function to draw a parabola
arcade.draw_parabola_filled(25, 80, 100, 110, arcade.color.GREEN ,0)
# finish drawing
arcade.finish_render()
# to display everything
arcade.run()
Python3
# import module
import arcade
# Open the window. Set the window title and dimensions (width and height)
arcade.open_window(600, 600, "Draw a parabola for GfG ")
#set background
arcade.set_background_color(arcade.color.WHITE)
# Start the render process.
arcade.start_render()
# function to draw a rainbow parabola
arcade.draw_parabola_filled(25, 80, 500, 300, arcade.color.RED ,0)
arcade.draw_parabola_filled(50, 80, 470, 280, arcade.color.ORANGE ,0)
arcade.draw_parabola_filled(75, 80, 440, 260, arcade.color.YELLOW ,0)
arcade.draw_parabola_filled(100, 80, 410, 240, arcade.color.GREEN ,0)
arcade.draw_parabola_filled(125, 80, 380, 220, arcade.color.SKY_BLUE ,0)
arcade.draw_parabola_filled(150, 80, 350, 200, arcade.color.VIOLET ,0)
arcade.draw_parabola_filled(175, 80, 325, 180, arcade.color.INDIGO ,0)
# finish drawing
arcade.finish_render()
# to display everything
arcade.run()
输出:
2. arcade.draw_parabola_filled( ):该函数用于绘制彩色场抛物线。
Syntax: arcade.draw_parabola_outline(start_x , start_y, end_x , height , color, tilt_angle)
Parameters:
- start_x : The starting x position of the parabola
- start_y : The starting y position of the parabola
- end_x :The ending x position of the parabola
- height : The height of the parabola
- color : The color of the parabola
- tilt_angle : The angle of the tilt of the parabola.
例子 :
蟒蛇3
# import module
import arcade
# Open the window. Set the window title and dimensions (width and height)
arcade.open_window(600, 600, "Draw a parabola for GfG ")
# set background
arcade.set_background_color(arcade.color.WHITE)
# Start the render process.
arcade.start_render()
# function to draw a parabola
arcade.draw_parabola_filled(25, 80, 100, 110, arcade.color.GREEN ,0)
# finish drawing
arcade.finish_render()
# to display everything
arcade.run()
输出:
示例:使用一系列抛物线绘制彩虹的程序
蟒蛇3
# import module
import arcade
# Open the window. Set the window title and dimensions (width and height)
arcade.open_window(600, 600, "Draw a parabola for GfG ")
#set background
arcade.set_background_color(arcade.color.WHITE)
# Start the render process.
arcade.start_render()
# function to draw a rainbow parabola
arcade.draw_parabola_filled(25, 80, 500, 300, arcade.color.RED ,0)
arcade.draw_parabola_filled(50, 80, 470, 280, arcade.color.ORANGE ,0)
arcade.draw_parabola_filled(75, 80, 440, 260, arcade.color.YELLOW ,0)
arcade.draw_parabola_filled(100, 80, 410, 240, arcade.color.GREEN ,0)
arcade.draw_parabola_filled(125, 80, 380, 220, arcade.color.SKY_BLUE ,0)
arcade.draw_parabola_filled(150, 80, 350, 200, arcade.color.VIOLET ,0)
arcade.draw_parabola_filled(175, 80, 325, 180, arcade.color.INDIGO ,0)
# finish drawing
arcade.finish_render()
# to display everything
arcade.run()
输出: