数模论坛

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

程序之四

[复制链接]
发表于 2005-1-24 23:15:30 | 显示全部楼层 |阅读模式
<>程序之四</P>
<>立方体程序:
Private centerx1 As Integer
Private centery1  As Integer
Private Const size = 50
Private curx0 As Integer
Private cury0 As Integer
Private curz0 As Integer
Private moveto As Integer
Private Const move_left = 0
Private Const move_right = 1
Private Const move_up = 2
Private Const move_down = 3
Private Const move_forward = 4
Private Const move_backward = 5
Public Sub eraseblock()
x = curx0: y = cury0: z = curz0
xs = (centerx1 + x * size) - z * (size / 2)
ys = (centery1 - y * size) + z * (size / 2)
Line (xs, ys)-(xs + size, ys - size), BackColor, BF
Line (xs - size / 2, ys + size / 2)-(xs + size / 2, ys - size / 2), BackColor, BF
For i = 1 To size / 2
Line (xs - i, ys + i)-(xs - i, ys + i - size - 1), BackColor
Line (xs - i + size, ys + i)-(xs - i + size, ys + i - size), BackColor
Next
End Sub</P>
<>
Public Sub drawblock()
Line (centerx1, centery1)-(centerx1 + size * 6, centery1 - size * 6), vbBlue, B
Line (centerx1, centery1)-(centerx1 - size * 6 / 2, centery1 + size * 6 / 2), vbBlue
Line (centerx1, centery1 - size * 6)-(centerx1 - size * 6 / 2, centery1 + size * 6 / 2 - size * 6), vbBlue
Line (centerx1 + 1, centery1 - 1)-(centerx1 + size * 6 - 1, centery1 - size * 6 + 1), RGB(0, 60, 0), BF
For i = 1 To size * 6 / 2 - 1
Line (centerx1 - i - 1, centery1 + i)-(centerx1 - i - 1, centery1 + i - size * 6 + 1), RGB(0, 60 + i * 2, 0)
Next
x = curx0: y = cury0: z = curz0
col = 10 + z * 20
xs = (centerx1 + x * size) - z * (size / 2)
ys = centery1 + z * (size / 2)
For i = 1 To size / 2
Line (xs - i, ys + i)-(xs - i + size, ys + i), vbBlack
Next
ys = (centery1 - y * size) + z * (size / 2)
Line (xs - size / 2 + 1, ys + size / 2 - 1)-(xs + size / 2 - 1, ys - size / 2 + 1), RGB(col + 120, 0, 0), BF
Line (xs + 1, ys - 1)-(xs + size - 1, ys - size + 1), RGB(col, 0, 0), BF
For i = 1 To size / 2  '绘制立方体的表面
Line (xs - i, ys + i)-(xs - i + size, ys + i), RGB(col + i * 8, 0, 0)
Line (xs - i, ys + i)-(xs - i, ys + i - size), RGB(col + i * 8, 0, 0)
Line (xs - i + size, ys + i)-(xs - i + size, ys + i - size), RGB(col + i * 8, 0, 0)
Next
Line (centerx1 - size * 6 / 2, centery1 + size * 6 / 2)-(centerx1 + size * 6 / 2, centery1 - size * 6 / 2), vbBlue, B
Line (centerx1 + size * 6, centery1)-(centerx1 + size * 6 - size * 6 / 2, centery1 + size * 6 / 2), vbBlue
Line (centerx1 + size * 6, centery1 - size * 6)-(centerx1 + size * 6 - size * 6 / 2, centery1 + size * 6 / 2 - size * 6), vbBlue</P>
<P>
End Sub
Private Sub form_keydown(keycode As Integer, shift As Integer)
Select Case keycode
Case vbKeyLeft
If curx0 &gt; 0 Then
eraseblock
curx0 = curx0 - 1
drawblock</P>
<P>End If
Case vbKeyRight
If curx0 &lt; 5 Then
eraseblock
curx0 = curx0 + 1
drawblock
End If
Case vbKeyUp
If shift = 0 Then
  If cury0 &lt; 5 Then
   eraseblock
    cury0 = cury0 + 1
        drawblock
       End If
ElseIf shift = 1 Then
  
  If curz0 &gt; 0 Then
  
  eraseblock
  curz0 = curz0 - 1
  drawblock
  End If
End If
Case vbKeyDown
If shift = 0 Then
If cury0 &gt; 0 Then
eraseblock
cury0 = cury0 - 1
drawblock
End If
ElseIf shift = 1 Then
If curz0 &lt; 5 Then
eraseblock
curz0 = curz0 + 1
drawblock
End If
End If
End Select
End Sub</P>
<P>Private Sub Form_Load()
Show
Height = 5610
Width = 6285
ScaleHeight = 500
ScaleWidth = 500
WindowState = 0
'设定当前的坐标系
centerx1 = ScaleWidth / 3
centery1 = ScaleHeight / 1.5
drawblock
Label1.Caption = "按方向键来使小立方体旋转:"</P>
<P>End Sub</P>
您需要登录后才可以回帖 登录 | 注-册-帐-号

本版积分规则

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

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

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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