home *** CD-ROM | disk | FTP | other *** search
- VERSION 4.00
- Begin VB.Form HilbertForm
- Caption = "Hilbert"
- ClientHeight = 4335
- ClientLeft = 2280
- ClientTop = 1185
- ClientWidth = 5175
- Height = 5025
- Left = 2220
- LinkTopic = "Form1"
- ScaleHeight = 289
- ScaleMode = 3 'Pixel
- ScaleWidth = 345
- Top = 555
- Width = 5295
- Begin VB.TextBox LevelText
- Height = 285
- Left = 600
- MaxLength = 3
- TabIndex = 0
- Text = "5"
- Top = 0
- Width = 375
- End
- Begin VB.PictureBox Canvas
- AutoRedraw = -1 'True
- Height = 4335
- Left = 1080
- ScaleHeight = 285
- ScaleMode = 3 'Pixel
- ScaleWidth = 269
- TabIndex = 3
- Top = 0
- Width = 4095
- End
- Begin VB.CommandButton CmdGo
- Caption = "Go"
- Default = -1 'True
- Height = 495
- Left = 120
- TabIndex = 1
- Top = 480
- Width = 735
- End
- Begin VB.Label Label1
- Caption = "Level"
- Height = 255
- Index = 0
- Left = 0
- TabIndex = 2
- Top = 0
- Width = 495
- End
- Begin VB.Menu mnuFile
- Caption = "&File"
- Begin VB.Menu mnuFileExit
- Caption = "E&xit"
- End
- End
- Attribute VB_Name = "HilbertForm"
- Attribute VB_Creatable = False
- Attribute VB_Exposed = False
- Option Explicit
- Dim TheLevel As Integer
- Dim StartLength As Integer
- ' Maximum space the curve can take up.
- Dim TotalLength As Integer
- Dim StartX As Integer
- Dim StartY As Integer
- Sub GetParameters()
- If Not IsNumeric(LevelText.Text) Then _
- LevelText.Text = "5"
- TheLevel = CInt(LevelText.Text)
- ' Compute the side length for this level.
- StartLength = TotalLength / (2 ^ TheLevel - 1)
- End Sub
- Private Sub CmdGo_Click()
- Dim i As Integer
- MousePointer = vbHourglass
- DoEvents
- Canvas.Cls
- ' Get the parameters.
- GetParameters
- ' Draw the curve.
- Canvas.CurrentX = StartX
- Canvas.CurrentY = StartY
- Hilbert TheLevel, StartLength, 0
- MousePointer = vbDefault
- End Sub
- ' ************************************************
- ' Draw a hilbert curve.
- ' ************************************************
- Sub Hilbert(level As Integer, dx As Integer, dy As Integer)
- If level > 1 Then Hilbert level - 1, dy, dx
- Canvas.Line -Step(dx, dy)
- If level > 1 Then Hilbert level - 1, dx, dy
- Canvas.Line -Step(dy, dx)
- If level > 1 Then Hilbert level - 1, dx, dy
- Canvas.Line -Step(-dx, -dy)
- If level > 1 Then Hilbert level - 1, -dy, -dx
- End Sub
- Private Sub Form_Resize()
- Dim unit As Single
- Dim vunit As Single
- Dim hunit As Single
- Canvas.Move Canvas.Left, 0, _
- ScaleWidth - Canvas.Left, ScaleHeight - 1
- ' See how big we can make the curve.
- If Canvas.ScaleHeight < Canvas.ScaleWidth Then
- TotalLength = 0.9 * Canvas.ScaleHeight
- Else
- TotalLength = 0.9 * Canvas.ScaleWidth
- End If
- StartX = (Canvas.ScaleWidth - TotalLength) / 2
- StartY = (Canvas.ScaleHeight - TotalLength) / 2
- End Sub
- Private Sub mnuFileExit_Click()
- Unload Me
- End Sub
-