-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_draw.py
More file actions
36 lines (29 loc) · 847 Bytes
/
test_draw.py
File metadata and controls
36 lines (29 loc) · 847 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import numpy as np
from PIL import Image, ImageFont
from PyDrawille import CanvasSurface
# 定义画布 canvas,即实例化 CanvasSurface 类
canvas = CanvasSurface()
# 使用 NumPy 生成一个余弦曲线
arr = np.arange(canvas.surface_width)
yarr = np.intc(np.cos(arr / 10) * canvas.surface_height / 3 + canvas.surface_height / 2)
# 生成一个一次函数曲线
mxg = min(canvas.surface_width, canvas.surface_height)
mxgarr = np.arange(mxg)
# 开始绘制
canvas.set_points(zip(mxgarr, mxgarr)) # type: ignore
canvas.set_pixels(
arr,
yarr,
)
# 画一条横穿中心的横线
canvas.set_line(canvas.surface_height // 2)
# 打印在控制台上
print(canvas.dump())
# 生成图片
canvas.dump_image(
ImageFont.truetype(font="./DejaVuSansCondensed.ttf", size=32, encoding="utf-8"),
0,
255,
).save(
"test.png",
)