Kometensimulation 2D
Übersicht

![]() |
KabelbinderSieger des WM-Contest 2006Betreff: Kometensimulation 2D |
![]() Antworten mit Zitat ![]() |
---|---|---|
Ein Programm zum simulieren von Kometenbahnen. Vielleicht noch nicht NASA - fähig aber eine nette kleine Spielerei
Screen: http://home.arcor.de/hack_page/komscr.jpg Code: Code: [AUSKLAPPEN] AppTitle "Kometen"
Graphics 1024,768,16,1 SetBuffer BackBuffer() SeedRnd MilliSecs() Const kmax = 200 Const pmax = 10 Const partmax = 800 Const effect = 40 Dim planet#(pmax,8) Dim komet#(kmax,9) Dim part#(partmax,8) Global set,mx#,my#,pnum,knum,jahr,jtimer,down,sx#,sy#,fineroll#,force#,mass#,partnum Global stat,gravmap,w#,fw# ;HELP Dim prefix$(20) Dim suffix$(20) Dim attrib$(20) Dim planetname$(pmax) Dim kometname$(kmax) gravmap = CreateImage(1024,768) For i = 1 To 20 Read prefix$(i) Next Data "clonc","omi","centi","meta","superi","anc","foli" Data "holi","dulc","wade","morph","blic","nova","nobo" Data "cumb","cilp","que","moleo","frang","pint" For i = 1 To 20 Read suffix$(i) Next Data "tron","cron","us","han","bron","mon","nal" Data "nan","ion","crom","trom","brom","mom","cahm" Data "cahn","os","ox","oz","gan","tan" For i = 1 To 20 Read attrib$(i) Next Data " alpha"," beta"," gamma"," delta"," 1"," zero"," omega" Data " 2"," 3"," 4"," 12"," psi","","" Data "","","","","","" Function draw() DrawBlock gravmap,0,0 For i = 0 To pmax If planet(i,3)=1 Then Color planet(i,4),planet(i,5),planet(i,6) Oval planet(i,1)-planet(i,7)/20,planet(i,2)-planet(i,7)/20,planet(i,7)/10,planet(i,7)/10 Text planet(i,1)+20,planet(i,2)-10,planetname$(i) If stat = 1 Then Color planet(i,4),planet(i,5),planet(i,6) Text 0,i*10+50,"Treffer, " + planetname(i) + ":" Text 200,i*10+50,Str$(Int(planet(i,8))) EndIf EndIf Next For i = 0 To partmax If part(i,3)=1 Then Color part(i,6),part(i,7),part(i,8) Plot part(i,1),part(i,2) EndIf Next For i = 0 To kmax If komet(i,3)=1 Then Color komet(i,6),komet(i,7),komet(i,8) Oval komet(i,1)-3,komet(i,2)-3,5,5 EndIf Next Color 0,255,255 Plot mx,my End Function Function sizen() If KeyDown(200) Then mass = mass + 1 If KeyDown(208) Then mass = mass - 1 If mass < 20 Then mass = 20 If mass > 400 Then mass = 400 End Function Function mouse_update() mx = MouseX() my = MouseY() End Function Function drag_line() If MouseDown(1)=1 And down = 0 Then down = 1 sx = mx sy = my EndIf If down = 1 Then Color 0,255,0 Line sx,sy,mx,my If MouseDown(1)=0 Then fineroll = ATan2(sy-my,sx-mx)+180 throwkom(sx,sy,fineroll,spat(mx,my,sx,sy)/10.0) down = 0 EndIf EndIf End Function Function distract() If MouseDown(2)=1 Then throwkom(mx,my,Rnd(1,360),Rnd(0.1,4.0)) EndIf End Function Function placeplan(x,y) planet(pnum,3)=1 planet(pnum,1)=x planet(pnum,2)=y Repeat planet(pnum,4)=Rand(255) planet(pnum,5)=Rand(255) planet(pnum,6)=Rand(255) Until planet(pnum,4)+planet(pnum,5)+planet(pnum,6)>100 planet(pnum,7)=mass planet(pnum,8)=0 astro_naming$(pnum) pnum = pnum + 1 End Function Function throwkom(x,y,r#,s#) komet(knum,3)=1 komet(knum,1)=x komet(knum,2)=y komet(knum,4)=Cos(r)*s komet(knum,5)=Sin(r)*s Repeat komet(knum,6)=Rand(255) komet(knum,7)=Rand(255) komet(knum,8)=Rand(255) Until komet(knum,6)+komet(knum,7)+komet(knum,8)>100 komet(knum,9)=3 If knum = kmax Then knum = 0 Else knum = knum + 1 EndIf End Function Function emit_part(x#,y#,r#,s#) part(partnum,3)=1 part(partnum,1)=x part(partnum,2)=y part(partnum,4)=Cos(r)*s part(partnum,5)=Sin(r)*s part(partnum,6)=255 part(partnum,7)=255 part(partnum,8)=0 If partnum = partmax Then partnum = 0 Else partnum = partnum + 1 EndIf End Function Function fly() For i = 0 To kmax If komet(i,3)=1 Then For j = 0 To pmax If planet(j,3)=1 Then fineroll = ATan2(komet(i,2)-planet(j,2),komet(i,1)-planet(j,1))+180 force = (komet(i,9)*planet(j,7))/(spat(planet(j,1),planet(j,2),komet(i,1),komet(i,2)))^2 komet(i,4)=komet(i,4)+Cos(fineroll)*force komet(i,5)=komet(i,5)+Sin(fineroll)*force EndIf Next fineroll = ATan2(komet(i,5),komet(i,4)) If RectsOverlap(0,0,1024,768,komet(i,1),komet(i,2),1,1) Then emit_part(komet(i,1),komet(i,2),fineroll+180+Rnd(-10.0,10.0),Rnd(0.0,2.0)) EndIf komet(i,1)=komet(i,1)+komet(i,4) komet(i,2)=komet(i,2)+komet(i,5) EndIf Next End Function Function drift() For i = 0 To partmax If part(i,3)=1 Then part(i,1)=part(i,1)+part(i,4) part(i,2)=part(i,2)+part(i,5) If part(i,7)>0 Then part(i,7)=part(i,7)-10 If part(i,7)<0 Then part(i,7)=0 Else part(i,6)=part(i,6)-10 If part(i,6)<0 Then part(i,6)=0 part(i,3)=0 EndIf EndIf If Not RectsOverlap(0,0,1024,768,part(i,1),part(i,2),1,1) Then part(i,3)=0 EndIf EndIf Next End Function Function collide() For i = 0 To kmax If komet(i,3)=1 Then For j = 0 To pmax If planet(j,3)=1 If spat(komet(i,1),komet(i,2),planet(j,1),planet(j,2))<2+planet(j,7)/20 Then For partanz = 0 To effect emit_part(komet(i,1),komet(i,2),Rnd(0,360),Rnd(0.5,2.0)) Next planet(j,8)=planet(j,8)+1 komet(i,3)=0 EndIf EndIf Next EndIf Next End Function Function blend() If KeyHit(57)=1 Then stat = Not stat EndIf End Function Function astro_naming$(nr) planetname$(nr)=prefix$(Rand(1,20))+suffix$(Rand(1,20))+attrib$(Rand(1,20)) End Function Function spat#(x1#,y1#,x2#,y2#) Return Sqr((x1-x2)^2+(y1-y2)^2) End Function ; PRE set = 0 Repeat mouse_update() sizen() If MouseHit(1)=1 Then placeplan(mx,my) EndIf draw() Color 255,255,255 Oval mx-mass/20,my-mass/20,mass/10,mass/10 Text 0,0,"Setze die Planeten" Text 0,10,"vergrößern/-kleiner mit den Pfeiltasten" Text 0,20,"Weiter mit Backspace" Text 0,30,mass If pnum = 10 Or KeyDown(14)=1 Or KeyDown(1)=1 Then set = 1 Flip Cls Until set = 1 Cls Flip z$ = Input("Gravitationsmap zeichnen? [j/n] :") If z = "j" Then SetBuffer ImageBuffer(gravmap) For y = 0 To 767 For x = 0 To 1023 w = 0 For i = 0 To pmax If planet(i,3)=1 Then w = w + spat(planet(i,1),planet(i,2),x,y)*planet(i,7) EndIf Next fw = 50000000.0/ w^1.05 If fw > 255 Then fw = 255 If fw < 0 Then fw = 0 WritePixel x,y,fw WritePixel x,y,fw,FrontBuffer() Next Next EndIf ; MAIN stat = 0 jahr = 2005 jtimer = MilliSecs() SetBuffer BackBuffer() Repeat mouse_update() If MilliSecs()-jtimer>1000 Then jahr = jahr + 1 jtimer = MilliSecs() EndIf fly() drift() collide() blend() DebugLog part(0,3) draw() Color 255,255,255 Text 0,0,jahr drag_line() distract() Flip Cls Until KeyHit(1) End |
||
<Wing Avenger Download> ◊◊◊ <Macrophage Download> |
![]() |
Cardonic |
![]() Antworten mit Zitat ![]() |
---|---|---|
Hi
Ist wirklich eine nette Spielerei. Macht Spass, die Asteroiden so loszulassen, dass sie möglichst lange nicht auf einem Planeten aufschlagen ![]() Die Physik finde ich echt beeindruckend. Ich denke, dass sie sehr realistisch ist. mfg Cardonic |
||
If you should go skating on the thin ice of modern life, dragging behind you the silent reproach of a million tear-stained eyes, don't be surprised when a crack in the ice appears under your feet. |
totonak5 |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
hey find ich echt cool!
habs geschafft dass ein komet immer nur im kreis um einen planeten fliegt ![]() ![]() |
||
Just for Fun!
Jesus loves U! |
![]() |
BladeRunnerModerator |
![]() Antworten mit Zitat ![]() |
---|---|---|
wow, ein verdammt schönes stück code. gefällt mir ausnehmend gut. | ||
Zu Diensten, Bürger.
Intel T2300, 2.5GB DDR 533, Mobility Radeon X1600 Win XP Home SP3 Intel T8400, 4GB DDR3, Nvidia GF9700M GTS Win 7/64 B3D BMax MaxGUI Stolzer Gewinner des BAC#48, #52 & #92 |
![]() |
Blitzard |
![]() Antworten mit Zitat ![]() |
---|---|---|
Jo echt super gmeacht REpekt coole Physik
@Bladerunner "Schönes Stück Code" des klingt so wie als wers en Stück fleisch ^^ |
||
User posted image |
Hawkins |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Hallo,
ich habe (weil ich dieses Programm hier gesehen habe) auch mal mein Programm reingestellt. Finde es cool, das auch andere auf die gleiche Idee kamen, oder zumindest auf eine ähnliche. https://www.blitzforum.de/foru...p?p=286366 Gruß Hawkins |
||
Matthias |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Hay. Das ist wirklich total geil.
Ich hatte auch mal so eine Idee. Ich stellte mir vor, zu simulieren wie unser Planetensystem etstanden ist. Also es gab kleine Kometen und diese haben sich gegenseitig angezogen dadurch sind dann Broggen etstanden, die dann noch mehr Anziehungskraft auf die restlichen Kometen ausgeübt haben. Leider habe ich nicht die nötigen Physikkentnisse. Du scheinst echt Ahnung von Physik zu haben. Könnte du das noch irgendwie mit rein bringen. Mfg. Matthias |
||
![]() |
maboxBetreff: Raspekt!!! |
![]() Antworten mit Zitat ![]() |
---|---|---|
He sowas gutes hab ich schon lang nichtmehr gesehen, habe fast ne halbe Stunde damit rumgespielt! macht echt Spaß und ist supergut simuliert. | ||
Fujitsu-Siemens Laptop, 2Ghz Intel Core2Duo Prozessor, 2GB Ram, 120GB Festplatte, ATI Mobility Radeon X1400, Windows Vista Ultimate
www.mausoft.de.tl Dönerfresser Homepage |
Hawkins |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Och, mit meinem Programm spielt kein er rum *heul*
nee, nur spass ^^ |
||
![]() |
FireballFlame |
![]() Antworten mit Zitat ![]() |
---|---|---|
Coooooool, schöne Sache ![]() |
||
PC: Intel Core i7 @ 4x2.93GHz | 6 GB RAM | Nvidia GeForce GT 440 | Desktop 2x1280x1024px | Windows 7 Professional 64bit
Laptop: Intel Core i7 @ 4x2.00GHz | 8 GB RAM | Nvidia GeForce GT 540M | Desktop 1366x768px | Windows 7 Home Premium 64bit |
#ReaperNewsposter |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Finde beide Codes toll ![]() (Also auch deins, Hawkins ![]() Nur der Kontrast bei der Gravitymap könnte um einiges größer sein, ist zumeinst mehr nur eine große Fläsche. |
||
AMD Athlon 64 3500+, ATI AX800 Pro/TD, 2048 MB DRR 400 von Infineon, ♥RIP♥ (2005 - Juli 2015 -> sic!)
Blitz3D, BlitzMax, MaxGUI, Monkey X; Win7 |
Hawkins |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Juchuhh, danke.
Ich habe nun BlitzPlus gekauft und bin dabei das zu verbessern. manche dinge sind nicht so einfach zu lösen (von wegen zeitkontinuität). |
||
![]() |
Der_Schläfer |
![]() Antworten mit Zitat ![]() |
---|---|---|
Tach allerseits!
Ich habe mir erlaubt, einige geringfügige Verbesserungen an Kabelbinders hüschen Programm vorzunehmen. Das Gravitaionsfeld wird nun etwa 25mal schneller gezeichnet und der Farbverlauf an die minimalen/maximalen Werte der variable fm angepasst. Ausserdem ist der Zusammenhang zwischen den Radien der Planeten und den Massen der Planeten neu m=pi*r^3 anstatt m=r... Macht echt spass mit dem Teil, danke! Code: [AUSKLAPPEN] AppTitle "Kometen" Graphics 1024,768,16,1 SetBuffer BackBuffer() SeedRnd MilliSecs() Const kmax = 200 Const pmax = 10 Const partmax = 800 Const effect = 40 Dim planet#(pmax,8) Dim komet#(kmax,9) Dim part#(partmax,8) Global set,mx#,my#,pnum,knum,jahr,jtimer,down,sx#,sy#,fineroll#,force#,mass#,partnum Global stat,gravmap,w#,fw# ;HELP Dim prefix$(20) Dim suffix$(20) Dim attrib$(20) Dim planetname$(pmax) Dim kometname$(kmax) gravmap = CreateImage(1024,768) For i = 1 To 20 Read prefix$(i) Next Data "clonc","omi","centi","meta","superi","anc","foli" Data "holi","dulc","wade","morph","blic","nova","nobo" Data "cumb","cilp","que","moleo","frang","pint" For i = 1 To 20 Read suffix$(i) Next Data "tron","cron","us","han","bron","mon","nal" Data "nan","ion","crom","trom","brom","mom","cahm" Data "cahn","os","ox","oz","gan","tan" For i = 1 To 20 Read attrib$(i) Next Data " alpha"," beta"," gamma"," delta"," 1"," zero"," omega" Data " 2"," 3"," 4"," 12"," psi","","" Data "","","","","","" Function draw() DrawBlock gravmap,0,0 For i = 0 To pmax If planet(i,3)=1 Then Color planet(i,4),planet(i,5),planet(i,6) Oval planet(i,1)-10*(planet(i,7)/(Pi))^(1/3.)/2,planet(i,2)-10*(planet(i,7)/(Pi))^(1/3.)/2,10*(planet(i,7)/(Pi))^(1/3.),10*(planet(i,7)/(Pi))^(1/3.) Text planet(i,1)+20,planet(i,2)-10,planetname$(i) If stat = 1 Then Color planet(i,4),planet(i,5),planet(i,6) Text 0,i*10+50,"Treffer, " + planetname(i) + ":" Text 200,i*10+50,Str$(Int(planet(i,8))) EndIf EndIf Next For i = 0 To partmax If part(i,3)=1 Then Color part(i,6),part(i,7),part(i,8) Plot part(i,1),part(i,2) EndIf Next For i = 0 To kmax If komet(i,3)=1 Then Color komet(i,6),komet(i,7),komet(i,8) Oval komet(i,1)-3,komet(i,2)-3,5,5 EndIf Next Color 0,255,255 Plot mx,my End Function Function sizen() If KeyDown(200) Then mass = mass + 1 If KeyDown(208) Then mass = mass - 1 mass=mass+MouseZSpeed()*10 If mass < 20 Then mass = 20 If mass > 400 Then mass = 400 End Function Function mouse_update() mx = MouseX() my = MouseY() End Function Function drag_line() If MouseDown(1)=1 And down = 0 Then down = 1 sx = mx sy = my EndIf If down = 1 Then Color 0,255,0 Line sx,sy,mx,my If MouseDown(1)=0 Then fineroll = ATan2(sy-my,sx-mx)+180 throwkom(sx,sy,fineroll,spat(mx,my,sx,sy)/10.0) down = 0 EndIf EndIf End Function Function distract() If MouseDown(2)=1 Then throwkom(mx,my,Rnd(1,360),Rnd(0.1,4.0)) EndIf End Function Function placeplan(x,y) planet(pnum,3)=1 planet(pnum,1)=x planet(pnum,2)=y Repeat planet(pnum,4)=Rand(255) planet(pnum,5)=Rand(255) planet(pnum,6)=Rand(255) Until planet(pnum,4)+planet(pnum,5)+planet(pnum,6)>100 planet(pnum,7)=mass planet(pnum,8)=0 astro_naming$(pnum) pnum = pnum + 1 End Function Function throwkom(x,y,r#,s#) komet(knum,3)=1 komet(knum,1)=x komet(knum,2)=y komet(knum,4)=Cos(r)*s komet(knum,5)=Sin(r)*s Repeat komet(knum,6)=Rand(255) komet(knum,7)=Rand(255) komet(knum,8)=Rand(255) Until komet(knum,6)+komet(knum,7)+komet(knum,8)>100 komet(knum,9)=3 If knum = kmax Then knum = 0 Else knum = knum + 1 EndIf End Function Function emit_part(x#,y#,r#,s#) part(partnum,3)=1 part(partnum,1)=x part(partnum,2)=y part(partnum,4)=Cos(r)*s part(partnum,5)=Sin(r)*s part(partnum,6)=255 part(partnum,7)=255 part(partnum,8)=0 If partnum = partmax Then partnum = 0 Else partnum = partnum + 1 EndIf End Function Function fly() For i = 0 To kmax If komet(i,3)=1 Then For j = 0 To pmax If planet(j,3)=1 Then fineroll = ATan2(komet(i,2)-planet(j,2),komet(i,1)-planet(j,1))+180 force = (komet(i,9)*planet(j,7))/(spat(planet(j,1),planet(j,2),komet(i,1),komet(i,2)))^2 komet(i,4)=komet(i,4)+Cos(fineroll)*force komet(i,5)=komet(i,5)+Sin(fineroll)*force EndIf Next fineroll = ATan2(komet(i,5),komet(i,4)) If RectsOverlap(0,0,1024,768,komet(i,1),komet(i,2),1,1) Then emit_part(komet(i,1),komet(i,2),fineroll+180+Rnd(-10.0,10.0),Rnd(0.0,2.0)) EndIf komet(i,1)=komet(i,1)+komet(i,4) komet(i,2)=komet(i,2)+komet(i,5) EndIf Next End Function Function drift() For i = 0 To partmax If part(i,3)=1 Then part(i,1)=part(i,1)+part(i,4) part(i,2)=part(i,2)+part(i,5) If part(i,7)>0 Then part(i,7)=part(i,7)-10 If part(i,7)<0 Then part(i,7)=0 Else part(i,6)=part(i,6)-10 If part(i,6)<0 Then part(i,6)=0 part(i,3)=0 EndIf EndIf If Not RectsOverlap(0,0,1024,768,part(i,1),part(i,2),1,1) Then part(i,3)=0 EndIf EndIf Next End Function Function collide() For i = 0 To kmax If komet(i,3)=1 Then For j = 0 To pmax If planet(j,3)=1 If spat(komet(i,1),komet(i,2),planet(j,1),planet(j,2))<5*(planet(j,7)/(Pi))^(1/3.) Then For partanz = 0 To effect emit_part(komet(i,1),komet(i,2),Rnd(0,360),Rnd(0.5,2.0)) Next planet(j,8)=planet(j,8)+1 komet(i,3)=0 EndIf EndIf Next EndIf Next End Function Function blend() If KeyHit(57)=1 Then stat = Not stat EndIf End Function Function astro_naming$(nr) planetname$(nr)=prefix$(Rand(1,20))+suffix$(Rand(1,20))+attrib$(Rand(1,20)) End Function Function spat#(x1#,y1#,x2#,y2#) Return Sqr((x1-x2)^2+(y1-y2)^2) End Function ; PRE set = 0 Repeat mouse_update() sizen() If MouseHit(1)=1 Then placeplan(mx,my) EndIf draw() Color 255,255,255 Oval mx-10*(mass/(Pi))^(1/3.)/2,my-10*(mass/(Pi))^(1/3.)/2,10*(mass/(Pi))^(1/3.),10*(mass/(Pi))^(1/3.) Text 0,0,"Setze die Planeten" Text 0,10,"vergrößern/-kleiner mit den Pfeiltasten/Mausrad" Text 0,20,"Weiter mit Backspace" Text 0,30,mass If pnum = 10 Or KeyDown(14)=1 Or KeyDown(1)=1 Or KeyDown(28) Then set = 1 Flip Cls Until set = 1 Cls Flip z$ = "j" If z = "j" Then SetBuffer ImageBuffer(gravmap) fwmax=0 fwmin=100000 xq=0 For y = 0 To 767 Step 5 For x = 0 To 1023 Step 5 w = 0 For i = 0 To pmax If planet(i,3)=1 Then w = w + spat(planet(i,1),planet(i,2),x,y)*planet(i,7) EndIf Next fw = 50000000.0/ w^1.05 If fw < 0 Then ;fw = 0 EndIf If fw>255 Then ;fw=255 EndIf If fw<fwmin Then fwmin=fw If fw>fwmax Then fwmax=fw Next Next For y = 0 To 767 Step 5 For x = 0 To 1023 Step 5 w = 0 For i = 0 To pmax If planet(i,3)=1 Then w = w + spat(planet(i,1),planet(i,2),x,y)*planet(i,7) EndIf Next fw = 50000000.0/ w^1.05 If fw < 0 Then ;fw = 0 EndIf If fw>255 Then ;fw=255 EndIf Color 0,0,(fw-fwmin)/fwmax*255. Rect x,y,5,5 Next Next EndIf ; MAIN stat = 0 jahr = 2005 jtimer = MilliSecs() SetBuffer BackBuffer() Repeat mouse_update() If MilliSecs()-jtimer>1000 Then jahr = jahr + 1 jtimer = MilliSecs() EndIf fly() drift() collide() blend() DebugLog part(0,3) draw() Color 255,255,255 Text 0,0,jahr Text 25,15,"fm="+fwmax Text 25,30,"fm="+fwmin Rect 10,15,10,10,0 Rect 10,30,10,10,0 Color 0,0,255 Rect 10,15,10,10,1 Color 0,0,0 Rect 10,30,10,10,1 drag_line() distract() Flip Cls Until KeyHit(1) End Ich habe mich dann gleich an einer 3d-Verion versucht, hatt aber nicht so recht geklappt... aber das kann ja noch kommen ![]() |
||
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group