It'd be easier to tell what it actually does if there were trails attached to the planets. I also recommend using either "sphere3" or "icosphere3" over "sphere", as the model is much smoother in both cases.
This expression can simulate up to six planets orbiting in space without hitting the tick quota. It uses Newton's formula for the gravity and some vector math for the rest. It can be pretty fun to put in random values to see if any interesting orbits come out of it. If you find any interesting orbit patterns, be sure to post them here. This is my first expression using loops and arrays, so be sure to post if you see any way I could improve or optimize this.
Pictures!Code:@name Orbiter @persist Ent:entity GravConstant Masses:array Positions:array @persist Velocities:array Forces:array Colors:array Planets if(first()|duped()){ runOnTick(1) #All values between this line GravConstant = 1 Planets = 6 #Planet 1 Masses[1,number] = 1000 Positions[1,vector] = vec(0,0,100) Velocities[1,vector] = vec(0,0,1) Colors[1,vector] = vec(255,0,0) #Planet 2 Masses[2,number] = 100 Positions[2,vector] = vec(100,0,100) Velocities[2,vector] = vec(2,2,0) Colors[2,vector] = vec(0,255,0) #Planet 3 Masses[3,number] = 100 Positions[3,vector] = vec(-100,0,100) Velocities[3,vector] = vec(-2,-2,0) Colors[3,vector] = vec(0,0,255) #Planet 4 Masses[4,number] = 100 Positions[4,vector] = vec(-200,0,100) Velocities[4,vector] = vec(-2,-2,0) Colors[4,vector] = vec(255,255,0) #Planet 5 Masses[5,number] = 100 Positions[5,vector] = vec(200,0,100) Velocities[5,vector] = vec(-2,-2,0) Colors[5,vector] = vec(255,0,255) # Planet 6 Masses[6,number] = 100 Positions[6,vector] = vec(300,0,100) Velocities[6,vector] = vec(-2,-2,0) Colors[6,vector] = vec(0,255,255) #and this line can be changed Ent = entity() Count = 1 while(Count<=Planets){ holoCreate(Count) holoModel(Count,"icosphere3") holoColor(Count,Colors[Count,vector]) holoScale(Count,log10(Masses[Count,number])*vec(1,1,1)) holoEntity(Count):setTrails(40,0,25,"trails/laser",Colors[Count,vector],100) Count=Count+1 } }else{ Count = 1 while(Count<=Planets){ Count2 = 1 Forces[Count,vector] = vec() while(Count2<=Planets){ if(Count!=Count2){ Force = (GravConstant*Masses[Count2,number])/ (Positions[Count,vector]:distance(Positions[Count2,vector])^2) Forces[Count,vector] = Forces[Count,vector]+(Positions[Count2,vector]-Positions[Count,vector]):normalized()*Force } Count2=Count2+1 } Count=Count+1 } Count=1 while(Count<=Planets){ Oldpos = Positions[Count,vector] Positions[Count,vector] = Velocities[Count,vector]+Positions[Count,vector]+Forces[Count,vector] Velocities[Count,vector] = Positions[Count,vector]-Oldpos holoPos(Count,Ent:pos()+Positions[Count,vector]) Count=Count+1 } }
![]()
Last edited by SamPerson12345; 09-06-2009 at 06:15 PM.
I code best at 3 A.M.
It'd be easier to tell what it actually does if there were trails attached to the planets. I also recommend using either "sphere3" or "icosphere3" over "sphere", as the model is much smoother in both cases.
It doesn't look so visually appealing. You should get creative with trails and model attachments/parent's.
Tutorials: Wire GPU | 3D Projections
Black Phoenix: drun KIE
Black Phoenix: PLEASE CONFIRM THIS MESSAGE DRUN KIE
Drunkie: confirmed
Black Phoenix: THE INTERGALACTIC CONTINIUM WANTS DRUN KIE TO GO ON A SPECIAL MISSION
Black Phoenix: this will be AN EASY mission TO THE UNKNOWN AND beyonD<HP> ... I can't believe I'm talking to a fucking script at 4 am
I added trails, and used a better model. It does look pretty nice.
I'll update the code in the first post.
I code best at 3 A.M.
I'd hate to be living on those colliding planets.
Is it possible to make the colliding planets explode or merge to a bigger one?
I would imagine that it would be possible to do that simply by checking the distances between the two planets in question, then making use of holoDelete and holoCreate. It wouldn't be too difficult.
The Olympus Technologies drones, totally not SkyNet in Gmod form.
Cronus: The Ultimate Drone, definitely SkyNet in Gmod form.
The gBrain Project, the drone controls system that thinks it's better than you
Need to learn how to make your own drones? Check out Drones with a Mad Scientist for my tutorials on how to do it.
Bookmarks