Robotics C++ Physics II AP Physics B Electronics Java Astronomy Other Courses Summer Session  

Starburst Example

 

 

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Button1.Visible = False

        Dim GraphicsObject As Graphics

        GraphicsObject = Me.CreateGraphics

        Dim pen1 As New Pen(Color.Black)

        GraphicsObject.TranslateTransform(20, 350) 'move origin to this new location

        GraphicsObject.ScaleTransform(1.0, -1.0) 'up is now positive y direction

        GraphicsObject.DrawLine(pen1, 0, 0, 300, 0) 'draw horizontal axis

        GraphicsObject.DrawLine(pen1, 0, 0, 0, 300) 'draw vertical axis

 

        Dim StartX As Integer = 100

        Dim StartY As Integer = 100

        Dim randomizer As New Random

        For i As Integer = 1 To 100

            Dim endpointX As Integer = randomizer.Next(10, 191)

            Dim endpointY As Integer = randomizer.Next(10, 191)

            Dim red As Integer = randomizer.Next(0, 256)

            Dim green As Integer = randomizer.Next(9, 256)

            Dim blue As Integer = randomizer.Next(0, 256)

            Dim Pen2 As New Pen(Color.FromArgb(255, red, green, blue))

            GraphicsObject.DrawLine(Pen2, StartX, StartY, endpointX, endpointY)

        Next

     End Sub

End Class