Skip to content

DRAW


用于按序绘制像素的语句

语法

Draw [target,] cmd

参数

target

要绘制的缓冲区

cmd

包含命令序列的字符串

说明

绘制将在 ScreenSet 设置的当前工作页面上进行,或者如果指定了 target,则在 Get/Put 缓冲区上进行。

Draw 语句可以一次发出多个绘图命令;它对于快速绘制图形非常有用。命令字符串接受以下命令:

绘制像素的命令:

命令说明
绘制像素的命令:
B可选前缀:移动但不绘制。
N可选前缀:绘制但不移动。
M x,y移动到指定屏幕位置。如果 x 前面有 '+' 或 '-' 符号,则移动相对于当前光标位置。x 的符号不影响 y 的符号。
U [n]向上移动 n 个单位。如果省略 n,默认为 1。
D [n]向下移动 n 个单位。如果省略 n,默认为 1。
L [n]向左移动 n 个单位。如果省略 n,默认为 1。
R [n]向右移动 n 个单位。如果省略 n,默认为 1。
E [n]向右上方移动 n 个单位。如果省略 n,默认为 1。
F [n]向右下方移动 n 个单位。如果省略 n,默认为 1。
G [n]向左下方移动 n 个单位。如果省略 n,默认为 1。
H [n]向左上方移动 n 个单位。如果省略 n,默认为 1。
颜色命令:
C n将当前前景颜色更改为 n。
P p,b用颜色 p 对边框颜色为 b 的区域进行填充(flood fill)。
缩放和旋转命令:
S n设置当前单位长度,默认为 4。单位长度 4 等于 1 个像素。
A n旋转 n*90 度(n 范围 0-3)。
TA n旋转 n 度(n 范围 0-359)。
额外命令:
X p执行 p 处的命令,其中 p 是一个 STRING PTR(字符串指针)。

设置颜色、大小和角度的命令将对后续所有 Draw 操作生效。

Draw 遵守 View (Graphics) 语句设置的当前裁剪区域,但其坐标不受自定义坐标系的影响。

示例

start GeSHi

vb
Screen 13

'Move to (50,50) without drawing
Draw "BM 50,50"

'Set drawing color to 2 (green)
Draw "C2"

'Draw a box
Draw "R50 D30 L50 U30"

'Move inside the box
Draw "BM +1,1"

'Flood fill with color 1 (blue) up to border color 2
Draw "P 1,2"

Sleep

end GeSHi

start GeSHi

vb
'' Draws a flower on-screen

Dim As Integer i, a, c
Dim As String fill, setangle

'' pattern for each petal
Dim As Const String petal = _
    _
    ("X" & VarPtr(setangle)) _ '' link to angle-setting string
    _
    & "C15" _       '' set outline color (white)
    & "M+100,+10" _ '' draw outline
    "M +15,-10" _
    "M -15,-10" _
    "M-100,+10" _
    _
    & "BM+100,0" _              '' move inside petal
    & ("X" & VarPtr(fill)) _    '' flood-fill petal (by linking to fill string)
    & "BM-100,0"                '' move back out

'' set screen
ScreenRes 320, 240, 8

'' move to center
Draw "BM 160, 120"

'' set initial angle and color number
a = 0: c = 32

For i = 1 To 24

    '' make angle-setting and filling command strings
    setangle = "TA" & a
    fill = "P" & c & ",15"

    '' draw the petal pattern, which links to angle-setting and filling strings
    Draw petal
   
    '' short delay
    Sleep 100

    '' increment angle and color number
    a += 15: c += 1

Next i

Sleep

end GeSHi

与 QB 的区别

  • target 是 FreeBASIC 新增的
  • QB 使用特殊指针关键字 VARPTR$ 与 X p 命令配合。
  • FB 目前不支持子像素移动:所有移动都四舍五入到最近的整数坐标。

另请参阅

  • Draw String
  • Screen (Graphics)
  • VarPtr
  • Paint

返回 目录

基于 FreeBASIC 官方文档翻译 如有侵权请联系我们删除
FreeBASIC 是开源项目,与微软公司无隶属关系