Arcade基本绘图方法
在绘图之前首先说明下在arcade中的坐标,arcade中的坐标是按数学中的直角坐标系来进行计算,是以窗口左下角为坐标原点进行计算。
绘制实心圆弧。
参数:
center_x (float)
:圆弧中心点距离窗口左边的距离(不包括窗口边框
)center_y (float)
:圆弧中心点距离窗口下边的距离(不包括窗口边框
)width (float)
:实心圆弧的宽度height (float)
:实心圆弧的高度color (arcade.Color)
:颜色,以RGB
或RGBA
格式start_angle (float)
:实心圆弧的起始角度,以度为单位end_angle (float)
:实心圆弧的结束角度,以度为单位tilt_angle (float)
:实心圆弧倾斜度数num_segments (float)
:用于绘制圆弧的线段数,数值越大越接近实心圆弧,越高质量越好,但是渲染时间越慢
import arcade
WIDTH = 1900
HEIGHT = 980
TITLE = "窗体测试标题"
class MyGame(arcade.Window):
def __init__(self, width, height, title):
super().__init__(width, height, title)
self.background_color = arcade.color.BLACK
self.set_location(10, 30)
def on_draw(self):
arcade.start_render()
# 宽高不同,开始度数为0,结束度数为360,倾斜度数为0时图形是一个标准实心椭圆
arcade.draw_arc_filled(center_x=55, center_y=850, width=100, height=200,
color=arcade.color.RED, start_angle=0, end_angle=360, tilt_angle= 0, num_segments=360)
# 宽高不同,存在开始度数与结束度数,倾斜度为0时图形是一个不标准实心扇形
arcade.draw_arc_filled(center_x=200, center_y=850, width=100, height=200,
color=arcade.color.RED, start_angle=30, end_angle=180, tilt_angle= 0, num_segments=360)
# 宽高不同,存在开始度数为0结束度数为360倾斜度时图形是一个倾斜指定角度的实心椭圆
arcade.draw_arc_filled(center_x=350, center_y=850, width=100, height=200,
color=arcade.color.RED, start_angle=0, end_angle=360, tilt_angle= 36, num_segments=360)
# 宽高不同,存在开始度数为0结束度数为360绘画线条数很少时图形是一个实心多边形
arcade.draw_arc_filled(center_x=500, center_y=850, width=100, height=200,
color=arcade.color.RED, start_angle=0, end_angle=360, tilt_angle= 0, num_segments=5)
# 宽高相同,开始度数0结束度数360时图形是一个标准实心圆
arcade.draw_arc_filled(center_x=700, center_y=850, width=200, height=200,
color=arcade.color.RED, start_angle=0, end_angle=360, tilt_angle= 0, num_segments=810)
# 宽高相同,开始度数90结束度数180时图形是一个标准实心扇形
arcade.draw_arc_filled(center_x=950, center_y=850, width=200, height=200,
color=arcade.color.RED, start_angle=90, end_angle=180, tilt_angle= 0, num_segments=810)
# 宽高相同,开始度数90结束度数180倾斜度时图形是一个倾斜指定角度的标准实心扇形
arcade.draw_arc_filled(center_x=1100, center_y=850, width=200, height=200,
color=arcade.color.RED, start_angle=90, end_angle=180, tilt_angle= 30, num_segments=810)
# 开始度数大于结束度数时图形不绘制
arcade.draw_arc_filled(center_x=1300, center_y=750, width=300, height=300,
color=arcade.color.RED, start_angle=30, end_angle=20, tilt_angle= 0, num_segments=810)
def main():
game = MyGame(WIDTH, HEIGHT, TITLE)
arcade.run()
if __name__ == "__main__":
main()
绘制圆弧的外边缘,绘制曲线很有用,与
draw_arc_filled
方法唯一区别就是不是实心图形。
参数:
center_x (float)
:弧中心点距离窗口左边的距离(不包括窗口边框
)center_y (float)
:弧中心点距离窗口下边的距离(不包括窗口边框
)width (float)
:弧的宽度height (float)
:弧的高度color (arcade.Color)
:颜色,以RGB
或RGBA
格式start_angle (float)
:弧的起始角度,以度为单位end_angle (float)
:弧的结束角度,以度为单位tilt_angle (float)
:倾斜度数num_segments (float)
:用于绘制弧的线段数,数值越大越接近圆弧,越高质量越好,但是渲染时间越慢
import arcade
WIDTH = 1900
HEIGHT = 980
TITLE = "窗体测试标题"
class MyGame(arcade.Window):
def __init__(self, width, height, title):
super().__init__(width, height, title)
self.background_color = arcade.color.BLACK
self.set_location(10, 30)
def on_draw(self):
arcade.start_render()
# 宽高不同,开始度数为0,结束度数为360,倾斜度数为0时图形是一个标准椭圆圆环
arcade.draw_arc_outline(center_x=55, center_y=850, width=100, height=200,
color=arcade.color.RED, start_angle=0, end_angle=360, tilt_angle= 0, num_segments=360)
# 宽高不同,存在开始度数与结束度数,倾斜度为0时图形是一个不标准曲线
arcade.draw_arc_outline(center_x=200, center_y=850, width=100, height=200,
color=arcade.color.RED, start_angle=30, end_angle=180, tilt_angle= 0, num_segments=360)
# 宽高不同,存在开始度数为0结束度数为360倾斜度时图形是一个倾斜指定角度的标准椭圆圆环
arcade.draw_arc_outline(center_x=350, center_y=850, width=100, height=200,
color=arcade.color.RED, start_angle=0, end_angle=360, tilt_angle= 36, num_segments=360)
# 宽高不同,存在开始度数为0结束度数为360绘画线条数很少时图形是一个多边形环
arcade.draw_arc_outline(center_x=500, center_y=850, width=100, height=200,
color=arcade.color.RED, start_angle=0, end_angle=360, tilt_angle= 0, num_segments=5)
# 宽高相同,开始度数0结束度数360时图形是一个标准圆圆环
arcade.draw_arc_outline(center_x=700, center_y=850, width=200, height=200,
color=arcade.color.RED, start_angle=0, end_angle=360, tilt_angle= 0, num_segments=810)
# 宽高相同,开始度数90结束度数180时图形是一个标准曲线
arcade.draw_arc_outline(center_x=950, center_y=850, width=200, height=200,
color=arcade.color.RED, start_angle=90, end_angle=180, tilt_angle= 0, num_segments=810)
# 宽高相同,开始度数90结束度数180倾斜度时图形是一个倾斜指定角度的标准曲线
arcade.draw_arc_outline(center_x=1100, center_y=850, width=200, height=200,
color=arcade.color.RED, start_angle=90, end_angle=180, tilt_angle= 30, num_segments=810)
# 开始度数大于结束度数时图形不绘制
arcade.draw_arc_outline(center_x=1300, center_y=750, width=300, height=300,
color=arcade.color.RED, start_angle=30, end_angle=20, tilt_angle= 0, num_segments=810)
def main():
game = MyGame(WIDTH, HEIGHT, TITLE)
arcade.run()
if __name__ == "__main__":
main()
画一个实心圆。
参数:
center_x (float)
:实心圆圆心点距离窗口左边的距离(不包括窗口边框
)center_y (float)
:实心圆圆心点距离窗口下边的距离(不包括窗口边框
)radius (float)
:圆的半径color (arcade.Color)
:颜色,以RGB
或RGBA
格式num_segments (int)
:组成圆的形段数量,越高质量越好,但是渲染时间越慢,默认值-1
表示自动根据圆的大小计算合理数量的线段
import arcade
WIDTH = 900
HEIGHT = 500
TITLE = "窗体测试标题"
class MyGame(arcade.Window):
def __init__(self, width, height, title):
super().__init__(width, height, title)
self.background_color = arcade.color.BLACK
self.set_location(50, 50)
def on_draw(self):
arcade.start_render()
arcade.draw_circle_filled(center_x=100, center_y=300, radius=64, color=arcade.color.RED)
arcade.draw_circle_filled(center_x=250, center_y=300, radius=64,
color=arcade.color.RED, num_segments=8)
arcade.draw_circle_filled(center_x=390, center_y=300, radius=64,
color=arcade.color.RED, num_segments=1000)
def main():
game = MyGame(WIDTH, HEIGHT, TITLE)
arcade.run()
if __name__ == "__main__":
main()
画一个标准圆环。
参数:
center_x (float)
:圆环圆心点距离窗口左边的距离(不包括窗口边框
)center_y (float)
:圆环圆心点距离窗口下边的距离(不包括窗口边框
)radius (float)
:圆环的半径color (arcade.Color)
:颜色,以RGB
或RGBA
格式border_width (float)
:圆环轮廓的宽度,以像素为单位num_segments (int)
:组成圆环的形段数量,越高质量越好,但是渲染时间越慢,默认值-1
表示自动根据圆的大小计算合理数量的线段
import arcade
WIDTH = 900
HEIGHT = 500
TITLE = "窗体测试标题"
class MyGame(arcade.Window):
def __init__(self, width, height, title):
super().__init__(width, height, title)
self.background_color = arcade.color.BLACK
self.set_location(50, 50)
def on_draw(self):
arcade.start_render()
arcade.draw_circle_outline(center_x=100, center_y=300, radius=64,
color=arcade.color.RED, border_width=36)
# 圆环宽度大于半径时会变成实心圆
arcade.draw_circle_outline(center_x=250, center_y=300, radius=64,
color=arcade.color.RED, border_width=64)
arcade.draw_circle_outline(center_x=390, center_y=300, radius=64,
color=arcade.color.RED, border_width=9, num_segments=1000)
def main():
game = MyGame(WIDTH, HEIGHT, TITLE)
arcade.run()
if __name__ == "__main__":
main()
绘制一个实心椭圆
参数:
center_x (float)
:实心椭圆圆心点距离窗口左边的距离(不包括窗口边框
)center_y (float)
:实心椭圆圆心点距离窗口下边的距离(不包括窗口边框
)width (float)
:椭圆的宽度height (float)
:椭圆的高度color (arcade.Color)
:颜色,以RGB
或RGBA
格式tilt_angle (浮动)
:椭圆倾斜度数num_segments (int)
:组成实心椭圆的形段数量,越高质量越好,但是渲染时间越慢,默认值-1
表示自动根据圆的大小计算合理数量的线段
import arcade
WIDTH = 900
HEIGHT = 500
TITLE = "窗体测试标题"
class MyGame(arcade.Window):
def __init__(self, width, height, title):
super().__init__(width, height, title)
self.background_color = arcade.color.BLACK
self.set_location(50, 50)
def on_draw(self):
arcade.start_render()
arcade.draw_ellipse_filled(center_x=50, center_y=300, width=50, height=100,
color=arcade.color.RED)
# 宽高相同时其实是一个标准实心圆
arcade.draw_ellipse_filled(center_x=150, center_y=300, width=100, height=100,
color=arcade.color.RED)
arcade.draw_ellipse_filled(center_x=300, center_y=300, width=50, height=100,
color=arcade.color.RED, tilt_angle=30)
def main():
game = MyGame(WIDTH, HEIGHT, TITLE)
arcade.run()
if __name__ == "__main__":
main()
绘制一个椭圆圆环
参数:
center_x (float)
:椭圆圆环圆心点距离窗口左边的距离(不包括窗口边框
)center_y (float)
:椭圆圆环圆心点距离窗口下边的距离(不包括窗口边框
)width (float)
:椭圆圆环的宽度height (float)
:椭圆圆环的高度color (arcade.Color)
:颜色,以RGB
或RGBA
格式border_width (float)
:椭圆圆环的宽度,以像素为单位。tilt_angle (浮动)
:椭圆圆环倾斜度数num_segments (int)
:组成椭圆圆环的形段数量,越高质量越好,但是渲染时间越慢,默认值-1
表示自动根据圆的大小计算合理数量的线段
import arcade
WIDTH = 900
HEIGHT = 500
TITLE = "窗体测试标题"
class MyGame(arcade.Window):
def __init__(self, width, height, title):
super().__init__(width, height, title)
self.background_color = arcade.color.BLACK
self.set_location(50, 50)
def on_draw(self):
arcade.start_render()
arcade.draw_ellipse_outline(center_x=50, center_y=300, width=50, height=100,
color=arcade.color.RED)
# 宽高相同时其实是一个标准圆环
arcade.draw_ellipse_outline(center_x=150, center_y=300, width=100, height=100,
color=arcade.color.RED)
arcade.draw_ellipse_outline(center_x=300, center_y=300, width=50, height=100,
color=arcade.color.RED, tilt_angle=30)
# 当环宽度超过宽高最大值时会变成实心椭圆,且椭圆大小会变
arcade.draw_ellipse_outline(center_x=500, center_y=300, width=50, height=100,
color=arcade.color.RED, border_width=100)
# 椭圆圆环宽高相同,圆环宽度等于宽高时为一个实心圆
arcade.draw_ellipse_outline(center_x=700, center_y=300, width=100, height=100,
color=arcade.color.RED, border_width=100)
def main():
game = MyGame(WIDTH, HEIGHT, TITLE)
arcade.run()
if __name__ == "__main__":
main()
画一条线。
参数:
start_x (float)
:直线起点距离窗口左边的距离(不包括窗口边框
)的x位置start_y (float)
:线起点距离窗口左边的距离(不包括窗口边框
)的y位置end_x (float)
:线终点距离窗口左边的距离(不包括窗口边框
)的x位置end_y (float)
:线终点距离窗口左边的距离(不包括窗口边框
)的y位置color (arcade.Color)
:颜色,以RGB
或RGBA
格式line_width (float)
:线的宽度,以像素为单位
import arcade
WIDTH = 900
HEIGHT = 500
TITLE = "窗体测试标题"
class MyGame(arcade.Window):
def __init__(self, width, height, title):
super().__init__(width, height, title)
self.background_color = arcade.color.BLACK
self.set_location(50, 50)
def on_draw(self):
arcade.start_render()
arcade.draw_line(start_x=50, start_y=390, end_x=300, end_y=390, color=arcade.color.RED)
# 变成矩形
arcade.draw_line(start_x=100, start_y=350, end_x=600, end_y=350,
color=arcade.color.RED, line_width=30)
arcade.draw_line(start_x=100, start_y=330, end_x=300, end_y=200,
color=arcade.color.RED)
def main():
game = MyGame(WIDTH, HEIGHT, TITLE)
arcade.run()
if __name__ == "__main__":
main()
画一条多点线,类似于折线。
参数:
point_list (arcade.PointList)
:组成每条线的x,y点的列表color (arcade.Color)
:线的颜色,以RGB
或RGBA
格式line_width (float)
:线的宽度
import arcade
WIDTH = 900
HEIGHT = 500
TITLE = "窗体测试标题"
class MyGame(arcade.Window):
def __init__(self, width, height, title):
super().__init__(width, height, title)
self.background_color = arcade.color.BLACK
self.set_location(50, 50)
def on_draw(self):
arcade.start_render()
arcade.draw_line_strip(point_list=[(
1, 1), (899, 499), (899, 0), (0, 499), (15, 300), (200, 100)], color=arcade.color.RED)
def main():
game = MyGame(WIDTH, HEIGHT, TITLE)
arcade.run()
if __name__ == "__main__":
main()
画一组线,在指定的每对点之间画一条线。
参数:
point_list (arcade.PointList)
:组成线的点的列表,每个点都在列表中。color (arcade.Color)
:线的颜色,以RGB
或RGBA
格式line_width (float)
:线的宽度
import arcade
WIDTH = 900
HEIGHT = 500
TITLE = "窗体测试标题"
class MyGame(arcade.Window):
def __init__(self, width, height, title):
super().__init__(width, height, title)
self.background_color = arcade.color.BLACK
self.set_location(50, 50)
def on_draw(self):
arcade.start_render()
arcade.draw_lines(point_list=[(1, 1), (899, 499), (899, 0), (0, 499)], color=arcade.color.RED)
def main():
game = MyGame(WIDTH, HEIGHT, TITLE)
arcade.run()
if __name__ == "__main__":
main()
通过指定左,右,上和下边缘来绘制实心矩形。
参数:
left (float)
:实心矩形左边缘距离窗口左边的距离(不包括窗口边框
)的x坐标。right (float)
:实心矩形右边缘距离窗口左边的距离(不包括窗口边框
)的x坐标。top (float)
:实心矩形顶部距离窗口左边的距离(不包括窗口边框
)的y坐标。bottom (float)
:实心矩形底部距离窗口左边的距离(不包括窗口边框
)的y坐标。color (arcade.Color)
:实心矩形的颜色,以RGB
或RGBA
格式- 当
left
>right
或top
<bottom
,则引发引发AttributeError
错误
import arcade
WIDTH = 900
HEIGHT = 500
TITLE = "窗体测试标题"
class MyGame(arcade.Window):
def __init__(self, width, height, title):
super().__init__(width, height, title)
self.background_color = arcade.color.BLACK
self.set_location(50, 50)
def on_draw(self):
arcade.start_render()
arcade.draw_lrtb_rectangle_filled(left=50, right=600, top=390, bottom=300,color=arcade.color.RED)
def main():
game = MyGame(WIDTH, HEIGHT, TITLE)
arcade.run()
if __name__ == "__main__":
main()
通过指定左,右,上和下边缘来绘制矩形框。
参数:
left (float)
:矩形框左边缘距离窗口左边的距离(不包括窗口边框
)的x坐标。right (float)
:矩形框右边缘距离窗口左边的距离(不包括窗口边框
)的x坐标。top (float)
:矩形框顶部距离窗口左边的距离(不包括窗口边框
)的y坐标。bottom (float)
:矩形框底部距离窗口左边的距离(不包括窗口边框
)的y坐标。color (arcade.Color)
:矩形框的颜色,以RGB
或RGBA
格式border_width (float)
:边框的宽度,以像素为单位,默认为1- 当
left
>right
或top
<bottom
,则引发引发AttributeError
错误
import arcade
WIDTH = 900
HEIGHT = 500
TITLE = "窗体测试标题"
class MyGame(arcade.Window):
def __init__(self, width, height, title):
super().__init__(width, height, title)
self.background_color = arcade.color.BLACK
self.set_location(50, 50)
def on_draw(self):
arcade.start_render()
arcade.draw_lrtb_rectangle_outline(left=50, right=600, top=390, bottom=300,
color=arcade.color.RED)
arcade.draw_lrtb_rectangle_outline(left=50, right=600, top=280, bottom=200,
color=arcade.color.RED, border_width=9)
def main():
game = MyGame(WIDTH, HEIGHT, TITLE)
arcade.run()
if __name__ == "__main__":
main()