读书人

怎么用line画一个立体方块?

发布时间: 2012-01-23 21:57:28 作者: rapoo

如何用line画一个立体方块????
如题,100分相送!

/\
/ \
/ \
|\ \
| \ /|
\ \ / |
\ \/ /
\ | /
\|/

[解决办法]
Private Function Draw3D(ByRef DrawObj As Object, ByVal Height As Long)
'画一个立方体
'DrawObj - 支持Line方法的对象,窗体,图片框等
'Height - 指定立方体高度
Dim Line1(4) As LineXY
Dim I As Long

DrawObj.ScaleMode = 3 '设置为像素

With Line1(1) '这里的坐标指定立方体形状
.X = 350
.Y = 80
End With
With Line1(2)
.X = 230
.Y = 160
End With
With Line1(3)
.X = 80
.Y = 100
End With
With Line1(4)
.X = 200
.Y = 30
End With
For I = 1 To 4
With Line1(I)
DrawObj.Line (.X, .Y)-(.X, .Y + Height)
End With
DrawObj.Line (Line1(I).X, Line1(I).Y)-(Line1(IIf(I = 4, 1, I + 1)).X, Line1(IIf(I = 4, 1, I + 1)).Y)
DrawObj.Line (Line1(I).X, Line1(I).Y + Height)-(Line1(IIf(I = 4, 1, I + 1)).X, Line1(IIf(I = 4, 1, I + 1)).Y + Height)
Next I
End Function

调用:

Call Draw3D(Me,160)

参数要自己调整啦.
[解决办法]
Private Sub Form_click()
Dim x As Single, y As Single, l As Single
Me.AutoRedraw = True
Me.Cls
Me.DrawStyle = 0
Randomize
x = 3000 * Rnd(): y = 3000 * Rnd(): l = 1000
Me.Line (x, y)-(x, y + l), vbGreen
Me.Line -(x + l, y + l), vbGreen
Me.Line -(x + l, y), vbGreen
Me.Line -(x, y), vbGreen

Me.Line (x, y)-(x + 1 / 2 * l, y - 1 / 2 * l), vbGreen
Me.Line -(x + 1 / 2 * l + l, y - 1 / 2 * l), vbGreen
Me.Line -(x + l, y), vbGreen

Me.Line (x + 1 / 2 * l + l, y - 1 / 2 * l)-(x + 1 / 2 * l + l, y - 1 / 2 * l + l), vbGreen
Me.Line -(x + l, y + l), vbGreen


Me.DrawStyle = 1
Me.Line (x, y + l)-(x + 1 / 2 * l, y + l - 1 / 2 * l), vbGreen
Me.Line -(x + 1 / 2 * l, y - 1 / 2 * l), vbGreen
Me.Line (x + 1 / 2 * l, y + l - 1 / 2 * l)-(x + l + 1 / 2 * l, y + l - 1 / 2 * l), vbGreen

End Sub

读书人网 >VB

热点推荐