Public Class Form1
Inherits System.Windows.Forms.Form
'###
' Windows Form Designer generated code
'###
Private TheTimer As Timer
Private BM1 As New Bitmap(100, 100)
Private fgr As Graphics = Me.CreateGraphics
Private StepX As Double = 16 ^ -1
Private StepY As Double = 12 ^ -1
Private StepZ As Double = 8 ^ -1
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
If TheTimer Is Nothing Then
UpdateInfo()
TheTimer = New Timer
TheTimer.Interval = 50
AddHandler TheTimer.Tick, AddressOf Draw
TheTimer.Enabled = True
Else
TheTimer.Enabled = Not TheTimer.Enabled
End If
End Sub
Private Sub Draw(ByVal Sender As Object, ByVal e As System.EventArgs)
Static OffsetX As Double = 0
Static OffsetY As Double = 0
Static OffsetZ As Double = 0
Static z As Integer = 0
Dim y As Integer
Dim xred As Integer
Dim ygreen As Integer
Dim zblue As Integer = CInt((1 + Math.Sin(OffsetZ + z / BM1.Width * 2 * Math.PI)) * 127)
For x As Integer = 0 To BM1.Width - 1
xred = CInt((1 + Math.Sin(OffsetX + x / BM1.Width * 2 * Math.PI)) * 127)
For y = 0 To BM1.Height - 1
ygreen = CInt((1 + Math.Sin(OffsetY + y / BM1.Height * 2 * Math.PI)) * 127)
BM1.SetPixel(x, y, Color.FromArgb(xred, ygreen, zblue))
Next y
Next x
fgr.DrawImage(BM1, 0, 0, 600, 600)
OffsetX += 2 * Math.PI * StepX
If OffsetX > 2 * Math.PI Then OffsetX -= 2 * Math.PI
OffsetY += 2 * Math.PI * StepY
If OffsetY > 2 * Math.PI Then OffsetY -= 2 * Math.PI
OffsetZ += 2 * Math.PI * StepZ
If OffsetZ > 2 * Math.PI Then OffsetZ -= 2 * Math.PI
End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles MyBase.MouseMove
Const MaxStep As Double = 1 / 10
If e.Button = MouseButtons.Left Then
StepX = (1 + 2 * (e.X - Me.Width) / Me.Width) * MaxStep
StepY = (1 + 2 * (e.Y - Me.Width) / Me.Width) * MaxStep
UpdateInfo()
End If
End Sub
Private Sub UpdateInfo()
Me.Text = "StepX:" & StepX.ToString("0.###") & _
" StepY:" & StepY.ToString("0.###") & _
" StepZ:" & StepZ.ToString("0.###")
End Sub
Private Sub Form1_MouseWheel(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles MyBase.MouseWheel
If Not e.Delta.Equals(0) Then
Select Case e.Delta > 0
Case True
StepZ += 0.005
If StepZ > 0.1 Then StepZ = 0.1
Case False
StepZ -= 0.005
If StepZ < -0.1 Then StepZ = -0.1
End Select
UpdateInfo()
End If
End Sub
End Class