模块 screen
屏幕类 cairo 绘图函数的子集。
参见 https://www.cairographics.org/tutorial/
函数
函数
- update_default ()
- 将缓冲区复制到屏幕。
- ping ()
- 重启屏幕保护程序计时器
- update_low_battery ()
- 低电量屏幕更新
- aa (state)
-
启用/禁用抗锯齿。
参数:
- state 开启(1) 或关闭(0)
- clear ()
- 清除。
- level (value)
-
设置级别(颜色/亮度)。
参数:
- value number 0-15 (0=关闭, 15=白色)
- line_width (w)
-
设置线宽。
参数:
- w number 线宽(以像素为单位,允许浮点数)
- line_cap (style)
-
设置线条端点样式。
参数:
- style 线条端点样式字符串("butt"、"round" 或 "square")。默认为 "butt"。
- line_join (style)
-
设置线条连接样式。
参数:
- style 线条连接样式字符串("miter"、"round" 或 "bevel")。默认为 "miter"
- miter_limit (limit)
-
设置斜接限制。
参数:
- limit 如果当前线条连接样式设置为 "miter",斜接限制用于确定线条是否应该用斜角而不是斜接连接。如果斜接长度除以线宽大于斜接限制,样式将转换为斜角。默认值 10。
- move (x, y)
-
移动绘图位置。
参数:
- x number x 位置
- y number y 位置
- move_rel (x, y)
-
相对于当前位置移动绘图位置。
参数:
- x number 相对 x 位置
- y number 相对 y 位置
- line (x, y)
-
绘制到指定点的线条。
参数:
- x number 目标 x
- y number 目标 y
- line_rel (x, y)
-
相对于当前位置绘制到指定点的线条。
参数:
- x number 相对目标 x
- y number 相对目标 y
- arc (x, y, r, angle1, angle2)
-
绘制圆弧。
参数:
- x number 圆心 x
- y number 圆心 y
- r number 半径
- angle1 number 起始角度
- angle2 number 结束角度
- circle (x, y, r)
-
绘制圆形。
参数:
- x number 原点 x
- y number 原点 y
- r number 半径
- rect (x, y, w, h)
-
绘制矩形。
参数:
- x number x 位置
- y number y 位置
- w number 宽度
- h number 高度
- curve (x1, y1, x2, y2, x3, y3)
-
绘制曲线(三次贝塞尔样条)。
参数:
- x1 number 控制点 1 x
- y1 number 控制点 1 y
- x2 number 控制点 2 x
- y2 number 控制点 2 y
- x3 number 目标 x
- y3 number 目标 y
- curve_rel (x1, y1, x2, y2, x3, y3)
-
绘制曲线(三次贝塞尔样条)相对坐标。
参数:
- x1 number 控制点 1 x
- y1 number 控制点 1 y
- x2 number 控制点 2 x
- y2 number 控制点 2 y
- x3 number 相对目标 x
- y3 number 相对目标 y
- close ()
- 闭合当前路径。
- stroke ()
- 描边当前路径。 使用当前选择的颜色。 在此调用后当前路径将被清除,因此 'relative' 函数 (move_rel、line_rel 和 curve_rel) 将不起作用 - 请使用它们的绝对 替代方案。
- fill ()
- 填充当前路径。 使用当前选择的颜色。 在此调用后当前路径将被清除,因此 'relative' 函数 (move_rel、line_rel 和 curve_rel) 将不起作用 - 请使用它们的绝对 替代方案。
- text (str)
-
绘制文本(左对齐)。
使用当前选择的字体。
参数:
- str string : 要写入的文本
- text_trim (str, w)
-
绘制左对齐文本,裁剪到指定宽度。
(从字符串末尾删除字符直到适合。)
使用当前选择的字体。
参数:
- str string 要写入的文本
- w number 宽度
- text_rotate (x, y, str, degrees)
-
绘制文本(左对齐)并旋转。
使用当前选择的字体。
参数:
- x number x 位置
- y number y 位置
- str string : 要写入的文本
- degrees number : 旋转角度
- text_right (str)
-
绘制文本,右对齐。
使用当前选择的字体
参数:
- str string : 要写入的文本。
- text_center (str)
-
绘制文本,居中对齐。
使用当前选择的字体。
参数:
- str string : 要写入的文本
- text_center_rotate (x, y, str, degrees)
-
绘制文本,居中对齐并旋转。
使用当前选择的字体。
参数:
- x number x 位置
- y number y 位置
- str string : 要写入的文本
- degrees number : 旋转角度
- text_extents (str)
-
根据当前字体和绘制状态计算文本宽度。
参数:
- str string : 要计算宽度的文本
- font_face (index)
-
选择字体。
参数:
- index
字体(参见列表,或 Screen.font_face_names)
- 1 norns (默认)
- 2 ALEPH
- 3 Roboto Thin
- 4 Roboto Light
- 5 Roboto Regular
- 6 Roboto Medium
- 7 Roboto Bold
- 8 Roboto Black
- 9 Roboto Thin Italic
- 10 Roboto Light Italic
- 11 Roboto Italic
- 12 Roboto Medium Italic
- 13 Roboto Bold Italic
- 14 Roboto Black Italic
- 15 VeraBd
- 16 VeraBI
- 17 VeraIt
- 18 VeraMoBd
- 19 VeraMoBI
- 20 VeraMoIt
- 21 VeraMono
- 22 VeraSeBd
- 23 VeraSe
- 24 Vera
- 25 bmp/tom-thumb
- 26 creep
- 27 ctrld-fixed-10b
- 28 ctrld-fixed-10r
- 29 ctrld-fixed-13b
- 30 ctrld-fixed-13b-i
- 31 ctrld-fixed-13r
- 32 ctrld-fixed-13r-i
- 33 ctrld-fixed-16b
- 34 ctrld-fixed-16b-i
- 35 ctrld-fixed-16r
- 36 ctrld-fixed-16r-i
- 37 scientifica-11
- 38 scientificaBold-11
- 39 scientificaItalic-11
- 40 ter-u12b
- 41 ter-u12n
- 42 ter-u14b
- 43 ter-u14n
- 44 ter-u14v
- 45 ter-u16b
- 46 ter-u16n
- 47 ter-u16v
- 48 ter-u18b
- 49 ter-u18n
- 50 ter-u20b
- 51 ter-u20n
- 52 ter-u22b
- 53 ter-u22n
- 54 ter-u24b
- 55 ter-u24n
- 56 ter-u28b
- 57 ter-u28n
- 58 ter-u32b
- 59 ter-u32n
- 60 unscii-16-full.pcf
- 61 unscii-16.pcf
- 62 unscii-8-alt.pcf
- 63 unscii-8-fantasy.pcf
- 64 unscii-8-mcr.pcf
- 65 unscii-8.pcf
- 66 unscii-8-tall.pcf
- 67 unscii-8-thin.pcf
- 68 Particle
- 69 04B_03 (别名到 norns.ttf)
- index
- font_size (size)
-
设置字体大小。
参数:
- size number 以像素高度为单位。
- pixel (x, y)
-
绘制单个像素(需要整数 x/y,之后需要填充)。
参数:
- x number 位置
- y number 位置
- export_screenshot (filename)
-
导出截图
参数:
- filename 保存到 dust/data/(script)/(filename).png
- display_png (filename, x, y)
-
显示 png
参数:
- filename
- x number x 位置
- y number y 位置
- load_png (filename)
-
将 png 加载到图像缓冲区
参数:
- filename
- create_image (width, height)
-
创建图像缓冲区
参数:
- width number 图像宽度
- height number 图像高度
- display_image (image, x, y)
-
显示图像缓冲区
参数:
- image
- x number x 位置
- y number y 位置
- display_image_region (image, left, top, width, height, x, y)
-
显示子区域图像缓冲区
参数:
- image
- left number 图像内左侧偏移
- top number 图像内顶部偏移
- width number 图像内从右侧的宽度
- height number 图像内从顶部的高度
- x number x 位置
- y number y 位置
- draw_to (image, func)
-
将提供的函数内的屏幕绘制直接绘制到图像而不是屏幕
参数:
- image image 要绘制到的图像
- func function 执行绘制的函数
- peek (x, y, w, h)
-
获取屏幕内容的矩形区域。返回的缓冲区每个像素包含一个字节(值 0 - 15),即 w * h 字节
参数:
- x number x 位置
- y number y 位置
- w number 宽度,默认 1
- h number 高度,默认 1
- poke (x, y, w, h, s)
-
设置屏幕内容的矩形区域。预期的缓冲区每个像素包含一个字节(值 0 - 15),即 w * h 字节
参数:
- x number x 位置
- y number y 位置
- w number 宽度
- h number 高度
- s string 要设置的屏幕内容
- rotate (r)
-
旋转
参数:
- r number 弧度
- translate (x, y)
-
移动原点位置
参数:
- x number 位置 x
- y number 位置 y
- save ()
- 保存
- blend_mode (index)
-
更改屏幕混合模式。
参数:
- index
number/string
混合模式(参见列表),字符串不区分大小写,单词间包含 '_'
更多信息请参见 https://www.cairographics.org/operators/
还有其他可用的操作符,请参见上述链接或在 REPL 中使用 tab.print(screen.BLEND_MODES) 查看完整列表。
0 Over (默认)
1 XOR: 清除任何重叠的像素。
2 Add: 将重叠像素的 alpha(亮度)相加。
3 Multiply: 将重叠像素的颜色相乘,结果总是比两个输入更暗。
4 Screen: 重叠像素的颜色被补码,相乘,然后它们的乘积被补码。结果总是比两个输入更亮。
5 Overlay: 如果目标像素级别 >= 8 则相乘颜色,如果目标像素级别 < 8 则屏幕颜色。
6 Darken: 保持重叠像素的较暗值。
7 Lighten: 保持重叠像素的较亮值。
8 Color_Dodge: 使被绘制的像素变亮。
9 Color_Burn: 使被绘制的像素变暗。
10 Hard_Light: 如果源像素级别 >= 8 则相乘颜色,如果源像素级别 < 8 则屏幕颜色。
11 Soft_Light: 根据源像素的颜色使用 Darken 或 Lighten。
12 Difference: 结果是目标像素和源像素差值的绝对值。
13 Exclusion: 类似于 Difference,但对比度较低。
用法:
-- 数字 vs. 字符串输入 screen.blend_mode(0) screen.blend_mode('over')
-- 不区分大小写 screen.blend_mode('hard_light') screen.blend_mode('hArD_lIgHt') screen.blend_mode('HARD_LIGHT')
- index
number/string
混合模式(参见列表),字符串不区分大小写,单词间包含 '_'