# 「数学Day」前座
べろべろに酔っ払ったコンパスがいる。
よたよたふらふらと歩き回るが歩幅は一定。
このよいどれコンパスを広場の真ん中に置き去りにする。
コンパスはどんな軌跡を描くだろうか。
雰囲気的に「中心が濃く、中心から遠ざかるほど薄い雲」になりそう。
ホントカナ?
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
bmp = New Bitmap(PictureBox1.Width, PictureBox1.Height)
PictureBox1.Image = bmp
x = PictureBox1.Width / 2
y = PictureBox1.Height / 2
End Sub
Private bmp As Bitmap
Private x As Integer
Private y As Integer
Private r As New Random()
Private Sub start_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles start.Click
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim theta As Double = r.NextDouble() * 2.0 * 3.1416
x = x + 5 * Math.Sin(theta)
y = y + 5 * Math.Cos(theta)
If (x > 0 AndAlso x < PictureBox1.Width) Then
If (y >= 0 AndAlso y < PictureBox1.Height) Then
bmp.SetPixel(x, y, Color.Red)
PictureBox1.Image = bmp
End If
End If
End Sub
乱数の精度に依存しそうですねー。