.:: Android Brownian Motion Simulator ::.
Android Brownian Motion Simulator
This program simulates borwnian motion on an android. It also uses the accelerometer to affect the forces on the objects.
SOFTWARE WRITTEN IN BASIC4ANDROID
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | Version=1.70 IconFile= FullScreen=False IncludeTitle=True NumberOfModules=0 Package=com.slava.brownian Label=Brownian Motion by Rostislav Persion VersionCode=1 VersionString= Orientation=portrait CanInstallToExternalStorage=False DoNotOverwriteManifest=False NumberOfFiles=0 NumberOfLibraries=2 Library1=core Library2=phone @EndOfDesignText@ Sub Process_Globals Dim Accelerometer As PhoneAccelerometer Dim AccX As Double Dim AccY As Double Dim Timer1 As Timer Dim xx(100) As Double Dim yy(100) As Double Dim vx(100) As Double Dim vy(100) As Double Dim ax(100) As Double Dim ay(100) As Double Dim r(100) As Double Dim dt As Double Dim w As Double Dim h As Double Dim diffx As Double Dim diffy As Double Dim dist1 As Double Dim dist2 As Double Dim xval As Double Dim yval As Double End Sub Sub Globals Dim Canvas1 As Canvas End Sub Sub Activity_Create(FirstTime As Boolean) canvas1.Initialize(Activity) Globe End Sub Sub Globe w = Canvas1.Bitmap.Width h = Canvas1.Bitmap.Height xx(0) = w/2 yy(0) = h/2 vx(0) = Rnd(-5,5) vy(0) = Rnd(-5,5) ax(0) = 0 ay(0) = 0 r(0) = 100 For i = 1 To 99 xx(i) = Rnd(0,w) yy(i) = Rnd(0,h) vx(i) = Rnd(-50,50) vy(i) = Rnd(-50,50) ax(0) = 0 ay(0) = 0 r(i) = Rnd(10,15) Next dt = .1 Accelerometer.StartListening("Accelerometer") Timer1.Initialize("MainEvent", 10) Timer1.Enabled = True End Sub Sub MainEvent_Tick For i = 0 To 99 For j = 0 To 99 ax(j) = 0.0; ay(j) = 0.0; Next For j = 0 To 99 If i <> j Then diffx = xx(i) - xx(j) diffy = yy(i) - yy(j) dist1 = Sqrt(Power(diffx,2)+Power(diffy,2)) dist2 = r(i) + r(j) If dist1 < dist2 Then deltaDistance = (dist2 - dist1) xval = (((deltaDistance * 10.0) / dist2) * diffx) yval = (((deltaDistance * 10.0) / dist2) * diffy) ax(i) = ax(i) + xval ay(i) = ay(i) + yval End If End If Next vx(i) = (vx(i) + (ax(i) * dt)) * .99 + AccX vy(i) = (vy(i) + (ay(i) * dt)) * .99 + AccY xx(i) = xx(i) + (vx(i) * dt) yy(i) = yy(i) + (vy(i) * dt) If xx(i)-r(i) < 0 Then vx(i) = -vx(i) xx(i) = 0 + r(i) End If If yy(i)-r(i) < 0 Then vy(i) = -vy(i) yy(i) = 0 + r(i) End If If xx(i)+r(i) > w Then vx(i) = -vx(i) xx(i) = w - r(i) End If If yy(i)+r(i) > h Then vy(i) = -vy(i) yy(i) = h - r(i) End If Next Canvas1.DrawColor(Colors.Black) Canvas1.DrawCircle(xx(0),yy(0),r(0),Colors.Red,True,5) For i = 1 To 99 Canvas1.DrawCircle(xx(i),yy(i),r(i),Colors.Green,True,5) Next Activity.Invalidate DoEvents End Sub Sub Activity_Touch (Action As Int, X As Float, Y As Float) xx(0) = x yy(0) = y vx(0) = 0 vy(0) = 0 End Sub Sub Activity_Resume Accelerometer.StartListening("Accelerometer") Timer1.Enabled = True End Sub Sub Activity_Pause (UserClosed As Boolean) Accelerometer.StopListening Timer1.Enabled = False End Sub Sub Accelerometer_AccelerometerChanged (X As Float, Y As Float, Z As Float) AccX = -(x/10) * 10 Accy = (y/10) * 10 End Sub |