Source code berikut untuk membuat efek Star Motion pada background form di Visual Basic. Bintang-bintang berwarna-warni bergerak menyebar secara random di tengah-tengah form.
Buat 1 project dengan :
1 Form
1 Timer
Copy source code berikut pada Form :
Dim X(100), Y(100), Z(100) As IntegerDim tmpX(100), tmpY(100), tmpZ(100) As IntegerDim K As IntegerDim Zoom As IntegerDim Speed As IntegerPrivate Sub Form_Activate() Speed = -1 K = 2038 Zoom = 256 Timer1.Interval = 1 For i = 0 To 100 X(i) = Int(Rnd * 1024) – 512 Y(i) = Int(Rnd * 1024) – 512 Z(i) = Int(Rnd * 512) – 256 Next iEnd SubPrivate Sub Timer1_Timer() For i = 0 To 100 Circle (tmpX(i), tmpY(i)), 5, BackColor Z(i) = Z(i) + Speed If Z(i) > 255 Then Z(i) = -255 If Z(i) < -255 Then Z(i) = 255 tmpZ(i) = Z(i) + Zoom tmpX(i) = (X(i) * K / tmpZ(i)) + (Form1.Width / 2) tmpY(i) = (Y(i) * K / tmpZ(i)) + (Form1.Height / 2) Radius = 1 StarColor = 256 - Z(i) Circle (tmpX(i), tmpY(i)), 5, RGB(StarColor, StarColor, StarColor) Next iEnd Sub


0 komentar:
Post a Comment