数模论坛

 找回密码
 注-册-帐-号
搜索
热搜: 活动 交友 discuz
查看: 4039|回复: 1

旋转立方体程序

[复制链接]
发表于 2005-1-24 23:16:34 | 显示全部楼层 |阅读模式
<>程序之五</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 &gt; 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>
发表于 2005-2-28 01:35:45 | 显示全部楼层
哥们,能用C写吗?
您需要登录后才可以回帖 登录 | 注-册-帐-号

本版积分规则

小黑屋|手机版|Archiver|数学建模网 ( 湘ICP备11011602号 )

GMT+8, 2024-11-27 00:19 , Processed in 0.055205 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表