Hi,
here is a small new BlitzMax-program.
It simulates gravity between many "planets"!
Because the code is very messy, I don't explain the details in this text, but if you have questions I'd like to answer them.
Now information you gonna need.At the top of the code are a few variables which you can change in the code:
- anzahl = change "anzahl" to set the number of planets
- ausgleich = "ausgleich" is a factor which influences the speed of the planets
-weite = "weite" sets how big the area is in which the planets can move
-zufweite = sets how big the area is in which the planets are created
-gu = sets how big the planets can be when they are created
These factors are in the program code as it is now very high. You can chose them however you like. Please try out!
The control also is quite easy:
- SPACE: Shows the direction of every planet
- "g": Shows the biggest gravity-connections
- "a": Zoom out
- "s": Zoom in
- "Cursor-Keys: Move camera"
I hope you'll enjoy the program:
PS: With this setting you have to zoom in a lot at the beginning!!
Feedback is welcome,
Lukas
here is a small new BlitzMax-program.
It simulates gravity between many "planets"!
Because the code is very messy, I don't explain the details in this text, but if you have questions I'd like to answer them.
Now information you gonna need.At the top of the code are a few variables which you can change in the code:
- anzahl = change "anzahl" to set the number of planets
- ausgleich = "ausgleich" is a factor which influences the speed of the planets
-weite = "weite" sets how big the area is in which the planets can move
-zufweite = sets how big the area is in which the planets are created
-gu = sets how big the planets can be when they are created
These factors are in the program code as it is now very high. You can chose them however you like. Please try out!
The control also is quite easy:
- SPACE: Shows the direction of every planet
- "g": Shows the biggest gravity-connections
- "a": Zoom out
- "s": Zoom in
- "Cursor-Keys: Move camera"
I hope you'll enjoy the program:
Graphics 800,600 Global ausgleich:Double Global weite:Double Global gu:Double Global ABSP:Int Global GRP:Int Global reg:Double absp = 2 grp = 2 anzahl = 50 ausgleich= 40000000 weite = 10000000000 zufweite = 500000 gu = 500000000 reg = 1 Global planets:Double[anzahl] Global planetg:Double[anzahl] Global planetx:Double[anzahl] Global planety:Double[anzahl] Global planetxs:Double[anzahl] Global planetys:Double[anzahl] Global greatest:Double[anzahl] Global greatestp:Double[anzahl] Global color:Double[anzahl] Global zoom:Double Global gesamtgroesse:Double = .1 Global verhx:Double Global verhy:Double Global xp:Double Global yp:Double xp = weite yp = weite zoom = (1/(weite/200)) Global abstandx:Double Global abstandy:Double Global abstand:Double Global richtungx:Double Global richtungy:Double Global ausgleich2:Double Global aenderungsr:Double For x = 0 To (anzahl-1) planetx[x] =Rnd (-zufweite,zufweite) planety[x] = Rnd(-zufweite,zufweite) planetg[x] = Rand(1,gu) Next Repeat For xx = 0 To (anzahl-1) SetColor 150+color[xx],150+color[xx],100 DrawOval (planetx[xx]+xp)*zoom,(planety[xx]+yp)*zoom,(planetg[xx]^0.5)*zoom+1,(planetg[xx]^0.5)*zoom+1 planetx[xx] = planetx[xx] + planetxs[xx] planety[xx] = planety[xx] + planetys[xx] color [xx] = 0 Next gesamtgroesse = 0.1 For xx3 = 0 To (anzahl-1) greatest[xx3] = 0 For yy3 = 0 To (anzahl-1) abstandx = (Abs((planetx[xx3]+(planetg[xx3]^0.5/2))-(planetx[yy3]+planetg[yy3]^0.5/2)))^2 abstandy = (Abs((planety[xx3]+(planetg[xx3]^0.5/2))-(planety[yy3]+planetg[yy3]^0.5/2)))^2 abstandx2 = (Abs(planetx[xx3]-planetx[yy3])) abstandy2 = (Abs(planety[xx3]-planety[yy3])) abstand = ((abstandx)+(abstandy))^0.5 If abstand < ((planetg[xx3]^0.5/2)+(planetg[yy3]^0.5/2)) And xx3 <>yy3 Then If planetg[xx3] >= planetg[yy3] Then planetx[xx3] = planetx[xx3] planety[xx3] = planety[xx3] Else planetx[xx3] = planetx[yy3] planety[xx3] = planety[yy3] End If planetg[xx3] = planetg[xx3]+planetg[yy3] planetg[yy3] = Rnd (1,gu*reg) planetxs[xx3] = (planetxs[xx3]+((planetg[yy3]/planetg[xx3])*planetxs[yy3]))/(1+(planetg[yy3]/planetg[xx3])) planetys[xx3] = (planetys[xx3]+((planetg[yy3]/planetg[xx3])*planetys[yy3]))/(1+(planetg[yy3]/planetg[xx3])) planetxs[yy3] = 0 planetys[yy3] = 0 planetx[yy3] = Rnd (-zufweite,zufweite) planety[yy3] = Rnd (-zufweite,zufweite) End If If xx3<>yy3 And abstandy2 <> 0 And abstandx2 <> 0 Then End If If xx3<>yy3 Then ausgleich2= (100/abstand) Else ausgleich2 = .01 End If If xx3 <> yy3 Then aenderungsr = ( (planetg[yy3]/planetg[xx3])^grp*ausgleich*(1/abstand^absp)) Else aenderungsr = 0 End If richtungx = Sin((abstandx^0.5)/(abstandy^0.5)) richtungy = Cos((abstandy^0.5)/(abstandx^0.5)) richtungx = 1 richtungy = 1 If (planetx[xx3]+planetg[xx3]^0.5/2) < (planetx[yy3]+planetg[yy3]^0.5/2) And xx3<>yy3 Then planetxs[xx3] = (planetxs[xx3] + (aenderungsr*richtungx) ) Else planetxs[xx3] = (planetxs[xx3] - (aenderungsr*richtungx)) End If If (planety[xx3]+planetg[xx3]^0.5/2) < (planety[yy3]+planetg[yy3]^0.5/2) Then planetys[xx3] = (planetys[xx3] + (aenderungsr*richtungy)) Else planetys[xx3] = (planetys[xx3] - (aenderungsr*richtungy)) End If If aenderungsr > greatest[xx3] Then greatest[xx3] = aenderungsr greatestp[xx3] = yy3 color[yy3] = color [yy3] + (100/anzahl) EndIf If KeyDown (key_space) Then SetColor 255,0,0 verhx = (planetxs[xx3]/planetys[xx3]) verhy =(planetys[xx3]/planetxs[xx3]) DrawLine (planetx[xx3]+xp)*zoom,(planety[xx3]+yp)*zoom,(planetx[xx3]+planetxs[xx3]+xp)*zoom,(planety[xx3]+planetys[xx3]+yp)*zoom End If gesamtgroesse = gesamtgroesse + planetg[yy3] If planetx[xx3] > weite Then planetxs[xx3] = -1 planetx[xx3] = weite End If If planetx[xx3] < -weite Then planetxs[xx3] = 1 planetx[xx3] = -weite End If If planety[xx3] > weite Then planetys[xx3] = -1 planety[xx3] = weite End If If planety[xx3] < -weite Then planetys[xx3] = 1 planety[xx3] = -weite End If Next Next If KeyDown (key_g) Then For xx4 = 0 To (anzahl-1) For yy4 = 0 To (anzahl-1) SetColor 0,255,0 DrawLine (planetx[xx4]+(planetg[xx4]^0.5/2)+xp)*zoom,(planety[xx4]+(planetg[xx4]^0.5/2)+yp)*zoom,(planetx[greatestp[xx4]]+(planetg[greatestp[xx4]]^0.5/2)+xp)*zoom,(planety[greatestp[xx4]]+(planetg[greatestp[xx4]]^0.5/2)+yp)*zoom Next Next End If SetColor 255,0,0 DrawLine (xp-weite)*zoom,(yp-weite)*zoom,(weite+xp)*zoom,(yp-weite)*zoom DrawLine (xp+weite)*zoom,(yp-weite)*zoom,(weite+xp)*zoom,(yp+weite)*zoom DrawLine (xp+weite)*zoom,(yp+weite)*zoom,(xp-weite)*zoom,(yp+weite)*zoom DrawLine (xp-weite)*zoom,(yp+weite)*zoom,(xp-weite)*zoom,(yp-weite)*zoom Flip Cls If KeyDown (Key_up) Then yp = yp + (5*1/zoom) End If If KeyDown (Key_down) Then yp = yp - (5*1/zoom) End If If KeyDown (Key_right) Then xp = xp - (5*1/zoom) End If If KeyDown (Key_left) Then xp = xp + (5*1/zoom) End If If KeyDown(key_a) Then zoom = zoom*.99 xp = xp + (4*1/zoom) yp = yp + (3*1/zoom) End If If KeyDown(key_s) Then zoom = zoom*1.01 xp = xp - (4*1/zoom) yp = yp - (3*1/zoom) End If DrawRect 400,296,1,9 DrawRect 396,300,9,1 Until KeyHit (key_escape) End
PS: With this setting you have to zoom in a lot at the beginning!!
Feedback is welcome,
Lukas