Use the following controls on form1:
- button named button1
- picturebox named XY
- checkbox named checkbox1
past the following code in the editor:
and tell me how (different ways?) I can detect when the mouse collides with any yellow point on screen. The collision detection should return the appropriate index from the t()-array.
- button named button1
- picturebox named XY
- checkbox named checkbox1
past the following code in the editor:
Code:
Public Class Form1
Public bmp As Bitmap
Public gfx As Graphics
Public numpoints As Integer = 10000
Public t(numpoints) As Point
Private Sub XY_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles XY.Paint
XY.Image = bmp
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.WindowState = FormWindowState.Maximized
bmp = New Bitmap(XY.Width, XY.Height)
gfx = Graphics.FromImage(bmp)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
gfx.Clear(Color.Black)
For r = 1 To numpoints
t(r).X = CInt(Rnd() * (XY.Width - 1))
t(r).Y = CInt(Rnd() * (XY.Height - 1))
Next
If CheckBox1.Checked Then
gfx.DrawLines(Pens.DarkOliveGreen, t)
End If
For r = 1 To numpoints
bmp.SetPixel(t(r).X, t(r).Y, Color.Yellow)
Next
End Sub
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
gfx.Clear(Color.Black)
If CheckBox1.Checked Then
gfx.DrawLines(Pens.DarkOliveGreen, t)
End If
For r = 1 To numpoints
bmp.SetPixel(t(r).X, t(r).Y, Color.Yellow)
Next
End Sub
End Class