2009年4月2日 星期四

摩天輪基礎

image 

Public Class Form1
    Dim g As Graphics
    Dim x1, y1, x2(24), y2(24) As Single
    Dim r
    Dim angle
    Dim pic(24) As PictureBox
    Dim i

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Width = 600
        Me.Height = 600
        g = Me.CreateGraphics
        Me.BackColor = Color.White

        pic(1) = PictureBox1
        pic(2) = PictureBox2
        pic(3) = PictureBox3
        pic(4) = PictureBox4
        pic(5) = PictureBox5
        pic(6) = PictureBox6
        pic(7) = PictureBox7
        pic(8) = PictureBox8
        pic(9) = PictureBox9
        pic(10) = PictureBox10
        pic(11) = PictureBox11
        pic(12) = PictureBox12
        pic(13) = PictureBox13
        pic(14) = PictureBox14
        pic(15) = PictureBox15
        pic(16) = PictureBox16
        pic(17) = PictureBox17
        pic(18) = PictureBox18
        pic(19) = PictureBox19
        pic(20) = PictureBox20
        pic(21) = PictureBox21
        pic(22) = PictureBox22
        pic(23) = PictureBox23
        pic(24) = PictureBox24

        For i = 1 To 24
            pic(i).Image = Choose(i Mod 6 + 1, My.Resources.seatRed, My.Resources.seatOrange, My.Resources.seatYellow, My.Resources.seatGreen, My.Resources.seatBlue, My.Resources.seatPurple)
        Next

        Timer1.Enabled = True
        Timer1.Interval = 100

        x1 = 300
        y1 = 250

        r = 200
        angle = 0
    End Sub

    Sub draw()
        For i = 1 To 24
            g.DrawLine(Pens.Black, x1, y1, x2(i), y2(i))
            pic(i).Left = x2(i)
            pic(i).Top = y2(i)
        Next
    End Sub

    Sub drawWhite()
        For i = 1 To 24
            g.DrawLine(Pens.White, x1, y1, x2(i), y2(i))
        Next
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        drawWhite()
        angle = angle + 1
        For i = 1 To 24
            x2(i) = x1 + r * Math.Cos((angle + 15 * i) * 3.14 / 180) '弳度 = 角度 * 3.14/180
            y2(i) = y1 + r * Math.Sin((angle + 15 * i) * 3.14 / 180)
        Next
        draw()
    End Sub
End Class

沒有留言:

張貼留言