画线VB程序

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

方程为:Y=0.5X-1 中点画线法:

程序:

Private Sub Command1_Click()

Dim p1, p2 As Integer: Dim x, y As Single: Dim a, b As Single a = Text1: b = Text2

For x = Text1 To Text3

y = 0.5 * x - 1

p1 = Text2

Form1.Line Step(a, b)-Step(x, y), vbRed

p2 = p1 + 1

m = (p1 + p2) / 2

If m >= y Then

b = p1

Else

b = p2: p1 = p2

End If

a = x + 1

Form1.Line Step(x, y)-Step(a, b), vbRed

Next

End Sub

Bresenham 画线算法:

程序:

Private Sub Command1_Click()

Dim p1, p2 As Integer: Dim x, y As Single: Dim a, b As Single a = Text1: b = Text2

For x = Text1 To Text3

y = 0.5 * x - 1

p1 = Text2

Form1.Line Step(a, b)-Step(x, y), vbRed

p2 = p1 + 1

If (y - p1) <= (p2 - y) Then

b = p1

Else

b = p2: p1 = p2

End If

a = x + 1

Form1.Line Step(x, y)-Step(a, b), vbRed

End Sub

Private Sub Command1_Click() Dim a As Integer

Dim x(5) As Integer

x(1) = 13

x(2) = 8

x(3) = 10

x(4) = 6

x(5) = 2

For i = 1 To 4

For j = i + 1 To 5

If x(i) > x(j) Then

a = x(i): x(i) = x(j): x(j) = a End If

Next j

Next i

For k = 1 To 5

Print x(k)

Next k

End Sub

相关文档
最新文档