Hi, ok , here's another version of the program ( a bit better, I think).
But has anyone an idea how to hold the particles on the screen?
Please help me to improve it! *g*
thx
But has anyone an idea how to hold the particles on the screen?
Graphics 1024,768 speed# = 1 startspeed# = 1 zuf# = 0 abstandsfaktor =1 anzahl = 100 barriere = 0.5 Global partx#[anzahl] ' Declaration of positions of the particles Global party#[anzahl] Global partxs#[anzahl] Global partys#[anzahl] Global rot[anzahl] ' Declaration of color of the particles Global gruen[anzahl] Global blau[anzahl] For x = 0 To (anzahl-1) ' Set particles position and color partx[x] = Rnd(0,1024) party[x] = Rnd(0,768) rot[x] = Rnd (1,255) gruen[x] = Rnd (1,100) blau[x] = Rnd (1,255) partxs[x] = Rnd(-startspeed,startspeed) partys[x] = Rnd(-startspeed,startspeed) Next Repeat dxsv# = 0 dysv#= 0 For x = 0 To (anzahl-1) partx[x] =partx[x] + partxs[x] ' Move particles party[x] = party[x] + partys[x] SetColor rot[x],gruen[x],blau[x] DrawRect (partx[x]-(dxs#-350)),(party[x]-(dys#-250)),2,2 ' Draw them(dxs and dys shal hold them in the middle of the screen, but it doesn't work) dxsv = dxsv + partx[x] dysv = dysv + party[x] SetColor 255,255,255 Next dxs# = (dxsv/anzahl) dys# = (dysv/anzahl) For x = 0 To (anzahl-1) For y = 0 To (anzahl-1) abstand# = abstandsfaktor*(((partx[x]-partx[y])^2+(party[x]-party[y])^2)^.5) ' Get the distance between particle[x] and particle[y] If partx[x] < partx[y] Then ' change it's acceleration because of gravity partxs[x] = partxs[x] +(.speed * (1/abstand)*Rnd(1-zuf,1+zuf)) End If If partx[x] > partx[y] Then partxs[x] = partxs[x] -(.speed * (1/abstand)*Rnd(1-zuf,1+zuf)) End If If party[x] < party[y] Then partys[x] = partys[x] +(.speed * (1/abstand)*Rnd(1-zuf,1+zuf)) End If If party[x] > party[y] Then partys[x] = partys[x] -(.speed * (1/abstand)*Rnd(1-zuf,1+zuf)) End If If y <> x Then If Abs(partx[x]-partx[y]) < 2 And Abs (party[x]-party[y]) < 2 Then 'particle-collision durchx = (partxs[x]+partxs[y]) /2 durchy = (partys[x]+partys[y]) /2 If Abs(partxs[x]-partxs[y])>(speed*5) Or Abs (partys[x] - partys[y]) >(speed*5) Then ' change it's color when they collide If rot[x] + 5< 255 Then rot[x] = rot[x] + 5 End If If gruen[x] + 2 < 210 Then gruen[x] = gruen[x] + 2 End If If blau[x] - 2 > 0 Then blau[x] = blau[x] - 2 End If End If partxs[x] = partxs[y] partys[x] = partys[y] End If End If Next Next If MouseDown (1) Then ' show the gravity(x,y) on a certain point (I think it doesn't work *g*) For x = 0 To (anzahl-1) For y = 0 To (anzahl-1) abstand# = abstandsfaktor*(((MouseX()-partx[y])^2+(MouseY()-party[y])^2)^.5) If MouseX() < partx[y] Then xspeed# = xspeed +(.speed * (1/abstand)*Rnd(1-zuf,1+zuf)) End If If partx[x] > partx[y] Then xspeed = xspeed -(.speed * (1/abstand)*Rnd(1-zuf,1+zuf)) End If If party[x] < party[y] Then yspeed# = yspeed +(.speed * (1/abstand)*Rnd(1-zuf,1+zuf)) End If If party[x] > party[y] Then yspeed = yspeed -(.speed * (1/abstand)*Rnd(1-zuf,1+zuf)) End If Next Next DrawText xspeed,MouseX(),MouseY()+15 ' Draw this gravity DrawText yspeed,MouseX(),MouseY()+25 xspeed = 0 yspeed = 0 End If Flip If Not KeyDown(key_space) Cls End If Until KeyHit (key_escape) End ' end *g*
Please help me to improve it! *g*
thx