|
<>程序之五</P>
<>旋转立方体程序:</P>
<>
Private x(8) As Integer
Private y(8) As Integer
Private Const pi = 3.14159265358979
Private centerx As Integer
Private centery As Integer
Private Const size = 250
Private radius As Integer
Private angle As Integer
Private curx As Integer
Private cury As Integer
Private cubecorners(1 To 8, 1 To 3) As Integer
Private Sub Drawcube()</P>
<P>Cls
'将三维坐标系转化为二维的坐标系
For i = 1 To 8
x(i) = centerx + cubecorners(i, 1) + cubecorners(i, 3) / 8
y(i) = centery + cubecorners(i, 2) + Sgn(cubecorners(i, 2)) * cubecorners(i, 3) / 8
Next
Line (x(3), y(3))-(x(4), y(4))
Line (x(4), y(4))-(x(8), y(8))
Line (x(3), y(3))-(x(7), y(7))
Line (x(7), y(7))-(x(8), y(8))
Line (x(1), y(1))-(x(3), y(3))
Line (x(1), y(1))-(x(2), y(2))
Line (x(5), y(5))-(x(6), y(6))
Line (x(5), y(5))-(x(1), y(1))
Line (x(5), y(5))-(x(7), y(7))
Line (x(6), y(6))-(x(8), y(8))
Line (x(2), y(2))-(x(4), y(4))
Line (x(2), y(2))-(x(6), y(6))
Line (x(1), y(1))-(x(4), y(4))
Line (x(2), y(2))-(x(3), y(3))
Line (x(4), y(4))-(x(8), y(8))
Line (x(3), y(3))-(x(7), y(7))
DoEvents</P>
<P>End Sub</P>
<P>Private Sub Command1_Click()
Unload Me</P>
<P>End Sub</P>
<P>Private Sub Form_Load()
Show
AutoRedraw = True
froecolor = vbBlue</P>
<P>DrawWidth = 3
Timer1.Interval = 1
Height = 3600
Width = 4800
ScaleHeight = 500
ScaleWidth = 500
widowstate = 2
centerx = ScaleWidth / 2
centery = ScaleHeight / 2
angle = 0
radius = Sqr(2 * (size / 2) ^ 2)
cubecorners(1, 2) = size / 2
cubecorners(2, 2) = size / 2
cubecorners(3, 2) = -size / 2
cubecorners(4, 2) = -size / 2
cubecorners(5, 2) = size / 2
cubecorners(6, 2) = size / 2
cubecorners(7, 2) = -size / 2
cubecorners(8, 2) = -size / 2
Command1.Caption = "退出"</P>
<P>End Sub</P>
<P>Private Sub Form_MouseMove(Button As Integer, shift As Integer, x As Single, y As Single)
curx = x
cury = y</P>
<P>End Sub</P>
<P>Private Sub Timer1_Timer()
Select Case curx</P>
<P>Case Is > ScaleWidth / 2
angle = angle + Abs(curx - ScaleWidth / 2) / 20
If angle = 360 Then angle = 0
Case Else
angle = angle - Abs(curx - ScaleWidth / 2) / 20
If angle = 0 Then angle = 360
End Select
For i = 1 To 3 Step 2
cubecorners(i, 3) = radius * Cos((angle) * pi / 180)
cubecorners(i, 1) = radius * Sin((angle) * pi / 180)
Next
For i = 2 To 4 Step 2
cubecorners(i, 3) = radius * Cos((angle + 2 * 45) * pi / 180)
cubecorners(i, 1) = radius * Sin((angle + 2 * 45) * pi / 180)
Next</P>
<P>For i = 5 To 7 Step 2
cubecorners(i, 3) = radius * Cos((angle + 6 * 45) * pi / 180)
cubecorners(i, 1) = radius * Sin((angle + 6 * 45) * pi / 180)
Next</P>
<P>For i = 6 To 8 Step 2
cubecorners(i, 3) = radius * Cos((angle + 4 * 45) * pi / 180)
cubecorners(i, 1) = radius * Sin((angle + 4 * 45) * pi / 180)
Next
Drawcube</P>
<P>
End Sub</P>
|
|