Planet Simulation In Python - Tutorial
Skills:
AI Workflow Automation70%
Key Takeaways
Creates a planet simulation using Python with astronomical values and gravity
Full Transcript
[Music] hello everybody and welcome to another YouTube video in this video I'm going to be showing you how to make a planet simulation using python now the goal of this is going to be to simulate the orbits of different planets around the Sun we're going to use real astronomical values so the real mass of the Sun the real distance from Earth to the sun all of that type of stuff and we're going to apply the force of gravity between all of the different planets so we actually get an accurate elliptical orbit now here it does look like the orbit is circular it is not you can see I'm actually writing the distance of the uh planet to the Sun on each planet so it's changing as we go around the orbit well this is really cool we're kind of mixing a bit of physics with python and looking at a cool simulation now I will mention that this tutorial is not designed for complete beginners you should have some knowledge of python however if you don't know anything about physics don't worry I will teach you the different physics we need to know to actually I guess perform this simulation it's not very complicated I myself am not a physics major or a physics guy and I was able to figure it out pretty quickly anyways with that said let's go ahead and get into the code after a quick word from our sponsor thanks to back trace for sponsoring this video back Trace provides application monitoring as well as error and crash reporting for games we've all been there excited to launch a brand new video game just to be tormented by crashes bugs and an overall bad user experience experience back trce wants to help limit that by providing a platform that gives game developers the best error and crash reporting with the most complete and helpful information back Trace works with any platform any engine and at any scale and provides 247 monitoring so you can retain more players and get better ratings back Trace helps you fix issues fast by providing accurate call Stacks regression detection querying and analytics and integration with Microsoft teams Discord slack and more you can get started with back Trace today and manage up to 25,000 monthly errors with one month retention and 10 GB of storage completely for free check it out from the link in the description and thanks again to back trace for sponsoring this video all right so let's go ahead and get started now I will mention that right here I'm not simulating every single planet you can easily adjust the simulation to add as many planets as you would like you can even put something like stars or satellites whatever you can put any of that here because of the way we're going to set this up however the planets I'm simulating right now are just the four closest to the Sun so we have Earth Mars Venus and Mercury we're just doing that so that we get a nice visual and we can see everything nice and large if you were to simulate the planets that are much further away from the Sun then you're going to see all of these planets kind of smooshed really close to the Sun and then the huge orbits around the Sun from the larger planets if that makes sense and the planets that are much further away so this is just a nice visualization again you can adjust this however you like and I'll show you how to do that so with that said let's dive into this I'm going to close this and just open up a new window here and we'll start writing some code now the first thing we do actually need to do is install py game so if you don't already have uh P game installed then just open up your terminal or command prompt depending on your operating system and type in the following command pip install py game that doesn't work for you try pip 3 install py game if that doesn't work for you try python hyphen M and then pip install py game if that doesn't work try Python 3 hyphen M pip install py game and if none of those commands work I have two videos that I'll put on the screen that show you how to fix your pip command anyways I'm going to assume that you have pame installed this is just a 2d Graphics library that we're going to use for the simulation if you don't know P game don't worry we're going to use very limited features from it and I'll talk about how all of them work so the first thing I'm going to do here is just import pame and then I'm going to say pame uh.it just to initialize the module I'm also going to import the math module because we're going to have to use that in this code okay so continuing since I'm using p game the first thing I want to do is set up my P game window now to do this we need to pick a width and height in pixels for our window so I'm going to say the width comma the height in all capitals because this is a constant is going to be 800800 you can make this whatever width and height you want but I recommend you make it square and then we're going to set up a window so I'm going to say wi is equal to pame do display setor mode now this is just going to take in the coordinates for the sign of our window so we're going to pass as a tupple here the width and the height this is going to give us what's known as a p game surface we're going to call it the window because it's the main window that we're going to draw onto and we need to have access to this surface to be able to put something on the screen and actually see something moving around now what I'm also going to do is just set a caption for this window so py game display setor caption now the caption is just going to be kind of the title of the window I'll show you what it looks like in one second and for this we'll just do Planet s simulation okay perfect so now that we have this what I want to do is create something known as the pame event Loop now this is essentially an infinite Loop that's going to run the entire time that the simulation is going whenever you're working with some type of game you need some type of loop that's constantly running they can keep track of the different events that are occurring in this case the only event is going to be moving the different planets but we need to have some type of loop so the window doesn't just open and instantly close we need something keeping the program running so I'm going to make a function here and I'm going to call this Main and inside of here I'm going to make a variable I'm going to say run is equal to true then we're going to say while run like this and this Loop will run while this variable run is true now inside of here I'm going to get the different events that are occurring in pi game so I'm going to say for event in pi game event get now this is going to give us a list of all of the different events that occur so key presses Mouse movements whatever now when you're coding a more complex game you're going to handle those different events however the only event that we want to handle is when the user presses the x button to close the window now that event is the following we're going to say if event type is equal to pame do quit in all capitals then all we're going to do is say run is equal to false and then outside of our wall loop we're going to say pame do quit so this is literally all we need for the event loop at least for right now what's going to happen is we're going to continually run we're going to get all of the events if one of the events that occurred was we hit the x button in the window then we are going to close the window by making run equal to false since that's going to exit our loop we're going to quit pame and then we'll be done perfect so all we need to do here is just call this main function and now that we do this we should see a pame window pop up and then we can close it and get out of the program safely so let's try this and there we go we get Planet simulation this is the caption I was talking about you can see it kind of right here beside the Little P game logo then if I click the x button we're going to close and we are all good okay we have set up our event Loop nice so now that we have done that I just want to show you how we can draw something onto the screen and kind of update the screen uh so let's do that so at the top of this Loop here I'm actually going to set up something called a clock now a clock is essentially going to make it so that the frame rate of our game won't go past a certain value I'll talk about why we need this but the idea here is that if we don't Implement some type of clock so some way to synchronize our game essentially you're going going to run the simulation at the speed of your computer now some people want that to happen they want it to run super fast if you're on a super super fast computer and then super slow if you're on a super slow one but ideally for me I don't care about what type of processor you have I just want you to run the simulation at the same speed so it looks normal uh hopefully that makes a bit of sense but we can kind of regulate the frame rate and how many times our game is refreshing so the way we do that is we say clock is equal to py game time clock and then we go here and we say clock tick and then we put in the number of times that we want this to update per second now this does not mean you're always going to update at in this case 60 frames per second however this is the maximum that you will be able to update at so we're saying clock tick 60 that means we're going to update this Loop or run this Loop a maximum of 60 times per second to ensure our game's not going too fast okay so now we have our clock and as I was saying we want to draw something on the screen so to draw something I'm going to use my window right here and I'm going to say win fill and then I need to pass an RGB color here that's going to be the color that I want to fill the entire window with on the screen so I'm just going to define a color let's just go with white for now and white will be equal to 255 255 255 okay so that's our RGB value for White and then I'm going to pass white inside of here and we should see in a second that we're going to get the screen actually updating and now it's going to have a white background rather than a black however I will show you if I currently run the code we actually don't get any white on the screen and the reason we don't get any white on the screen is because we're not updating the display so what I need to do is say p game do display update not clear and what this does is actually take all of the drawing actions that we've done since the last update and then kind of paste them and draws them onto the screen so what I'm doing is every Loop I'm going to fill the background with white and then I'm going to update the display okay so now if I run this you're going to see that we get a white background now we don't actually want a white background I want a black one so I'm going to get rid of this I just wanted to show you how we fill the screen okay so let's comment these out for right now perfect so now that we've done this let's start implementing a planet because obviously we want to put some planets on the screen and to do this I'm going to make a class so I'm going to say class planet and inside of here I'm going to Define an initialization I'm going to say Define a nit I'm going to say self we need an X and A Y now the X and the Y is going to be the position that we want this planet to be on the screen uh we also are going to need a radius we're going to need a color and then let me just check if we want to take anything else we're also going to need a Mass for the planets okay so these are kind of the initialization values that we have so I'm going to say self.x is equal to X self.y is equal to Y self radius is equal to radius obviously we're going to have circular planets self color is equal to color we might want to make our planets more detailed and have multiple colors but for now we're just going to go with a single color and then the mass is going to be the mass in kilograms of this planet we're going to have to use that Mass to calculate the attraction between the different planets then generate the actual circuit orbit uh which we'll get to when we start talking about the physics now there's a few other things that we want our planets to have they're going to have to have an x velocity as well as a y velocity so I'm going to say self doore XV is equal to zero and self yvel is equal to zero now I'll explain how all of these Concepts work in a second but the idea is we're going to be moving our planet in a circle and in order to move in a circle we have a velocity in multiple directions so we're going to have it in the X Direction which is the horizontal Direction and then in the y direction and by moving in two directions at the same time we're able to generate a circle and have kind of I don't want to call it uh centrifical force or centrifical motion but something along those lines right we're actually moving in a circle around an object at a constant speed okay uh hopefully this is making sense so far another thing that I want to do here is I want to have something that says self sun is equal to false now this is going to tell us if the planet is the sun the reason we want that is because we're going to draw the orbit of the planet moving around and I don't want to draw the orbit for the Sun so I need to know if it's a sun to either draw it or to not draw it and then I'm going to have the self distance to Sun I'm just going to make this equal to zero right now and we're going to update this value for every single planet that we have so that we know what its distance is and we can then draw that on the screen and then the last thing that I want is self orbit is equal to an empty list we're going to use this to keep track of all all of the points that this planet has traveled along so we can draw a circular orbit representing well the orbit of the planet okay again all this will start to make sense as we get into more of these Concepts I'm just kind of setting up all the initialization values now a few other things that I want to do here uh is just write out a few constants that we're going to use for our simulation now the first constant we're going to do as a class variable in the planet class and this is going to be Au now Au is astronomical units and this is approxim equal to the distance of the Earth to the sun now I want to use Au because it's going to simplify the math that we need to do to calculate the distance between the current planet and the Sun and allow us to initialize our planets at the correct AU from the Sun so they're kind of the correct distance away hopefully that makes a bit of sense but 1 Au is equal to and I just have to copy this from my other screen 1.49 do 6 to the exponent 6 which is what this E6 stands for and then multiplied by 1,000 and I don't actually need these in parentheses so I don't know why I had it there okay so what this is saying is we are 149,000 uh I guess this is sorry 149 million and then 600,000 kilom that's what this stands for right here but we want this to be in meters so I'm going to multiply by a th000 to get the distance from the Sun in meters uh 1 Au that that's what this is hopefully that makes sense again want to use the distance from the Earth to the sun approximately and here we're converting this from kilom to met by multiplying it by a th000 okay now we also want the gravitational constant now this is not 9.8 that's the uh acceleration of gravity I actually yeah I think it's the acceleration of gravity I might be messing that up but it's something to with gravity but the gravitational constant is used in finding the force of attraction between objects which is what we want to do and G is different than the regular gravity one is uh 6.67 and actually is 4.28 e to the 11 okay that's great my auto complete is working very well there nice now the last two things we want here is a scale since we're actually going to be simulating the real values here for the orbits we can't draw them at the position that we have them at I know that's probably a confusing line but the idea is if our planet is moving at you know something kilometers per second 7 km/ second 29 km/ second I can't draw my Planet at a million kilom in my P game window I need to draw it in a kind of appropriate scale right so I'm going to have to figure out what one meter represents in terms of pixels in my Pi game scale here because I'm only working with 800 pixels high and 800 pixels wide hopefully this is making a little bit of sense what I'm going to do here is say 250 / Au is the scale now this scale essentially says that one astronomical unit is going to be about 100 pixels in my Pi game program you can look at the math to figure out how that works but for now I'll leave a comment we're going to say 1 Au is equal to 100 pixels okay that's kind of the scale that we're going with here so we can draw things to scale in the window and then the last thing I want is the time step and this is going to represent how much uh of time I want to represent in my simulation or that I want to simulate is being elapsed so the idea here is every time I update the frame I'm going to pass a certain time step and say okay I want to look at 1 hour of this plan movement at a time or one day of this planet's movement at a time because I don't want to look at one second it's going to take a really really long time to simulate instead I want to look at a larger time step so what I'm going to do is say 3600 which is the number of seconds in a uh what is this in an hour yeah I think this number of seconds in an hour and then I'm going to multiply this by 24 and that's going to give me one day okay so this is representing one day I think that's correct yeah okay I'm pretty certain that is correct this would be the number of seconds in an hour right if you go 60 * 60 I think that gives you 3600 and then multiply that by 24 and that is the time step that we're going to be doing the simulation on so kind of one day at a time we'll be updating the planet all right hopefully I'm not confusing you guys too much I do understand this is a lot we got to go through a bunch of physics and stuff here to make this work but there you go that is a planet now the next thing I want to do is Implement a draw method now this draw method just going to draw the planet on the screen so what I'm going to do is say self and then I'm going to take a window that I need to draw this planet on so the X and Y for my Planet as well as the x velocity and the Y velocity for my planet is going to be in meters so the number of meters that I am away from the Sun that's what X and Y is going to represent so I need to take those values and then draw them to scale right because I again I can't draw like something million kilometers or million meters away I need to draw it in an accurate scale in pame so this is where the scale is going to come in I'm going to say that my X is equal to and then this is going to be the self do X multiplied by my scale okay so it's going to be self scale and self scale is going to be a really really tiny number that will now take this number and bring it to scale and I'm going to say Y is equal to self.y and I'm going to multiply that by self scale okay nice now one other thing I need to do is make sure that I'm drawing all of this in the center of my screen because I haven't mentioned yet when we're talking about Pi game 0 0 is actually the top leftand corner so let me just quickly open the window here right here where my mouse is so top leftand Corner this is 0 0 if I go all the way to the right this would be 800 Z if I go all the way to the bottom right hand corner this would be 800 800 so rather than having 0 0 in the middle which you might be used to it's the top left so I don't want to draw my stuff in the top left I want to draw it in the center so that means I need to take every single value I have I need to offset it by the center of the screen so that we draw stuff in the middle hopefully that makes a tiny bit of sense uh but the way we do this is we say plus and then this is going to be width over two and then this is going to be plus and then this is going to be height over two and those values are right here okay so the width and the height we could just write 400 but I'm going to do width and height so that if we change the width and the height this is going to update automatically okay so now we have our X and Y and now I can actually draw this onto the screen so I'm going to say uh P game do draw do Circle and I'm going to pass the window which is where we want to draw this circle I'm going to pass the color that I want to draw the circle in so this is going to be self color I'm going to pass the position that I want to draw it in which is going to be XY that's the center of the circle and then lastly I'm going to pass the radius so self rius okay so now we're actually going to draw the circle on the screen when we call this draw method okay hopefully this is all making a bit of sense let's now go and actually draw a few planets and initialize some of their constants so the first planet we probably want to draw is the sun uh could you call the sun a planet I guess it's a star again not a big physics guy but the first thing we want to draw is the sun okay so I'm going to say sun is equal to planet and we're going to pass 0 0 for its XY okay so 0 0 right here for the radius of the sun we can kind of pick whatever value we want here we're just going to be kind of randomly picking the radiuses based on the relative mass of the planets so we want the sun to be the biggest and what I have in my other program here is 30 for the radius so we'll go with that and for the color I want this to be yellow so so just to make this a bit easier to read I'm going to Define yellow up here and yellow actually how do you even make yellow let's look at this yellow is going to be 255 255 and zero okay so that's the RGB value for yellow obviously that's the color we want the Sun so let's now put the color as yellow and then the last thing we need to pass is the mass and the mass I need to look at my cheat sheet here because unfortunately I don't have this memorized is going to be the following let me paste this in 1.98 1892 * 10 the exponent 30 and in case you're wondering this is in kilog again we're going to use the accurate masses and astronomical units and stuff for all of these planets okay so that is the sun uh and for the sun we're just going to say sun sun is equal to true because remember we have this property here that says sun and we're going to make this true so that we don't draw the distance to the Sun from the Sun and we don't draw the orbit for the sun which we don't need okay so now that we have this let's just see if we can draw this on the screen so let's go planets is equal to and let's make a list of all the planets cuz we're going to add a few more and then inside of our Loop here we're going to say four planet in planets and we're going to say planet do draw and we're going to pass the window that we want to draw it on which is win in all capitals okay nice now we also need to make sure that we're updating this place so let's steal this here and let's put it down there okay nice so we're saying four plan and Planet planet draw py game display update let's see if this works fingers crossed let's run the code okay there we go we get a sun in the middle of the screen very nice that is exactly what we want all right now the next thing we want to do is draw a few more planets right so let's create Earth Mercury all of those okay so we're going to start with Earth we're going to say Earth is equal to planet now the Earth is actually going to be -1 multiplied by planet with an all capital au this is going to be the distance from the Sun so we're going to put that as the x coordinate and for the y-coordinate we're just going to make it zero for right now the color of the Earth is going to be blue we'll write that RGB uh variable in a second and then the mass of the Earth uh actually sorry we need the radius as well uh let's put the radius first what was the radius of the Earth I had 60 in here as the radius and then the mass of the earth is this number let me copy it in 5.9 9742 * 10 the expon 24 okay that's the mass of the earth now I will actually mention here before I continue that there is a great article I'm going to open it up so I can show it to you guys uh let me get it on my Google Chrome here uh that I'm actually inspired by making this program that has all of these values already so this is the article I'll leave it in the description but it essentially implements the same thing we're going to implement here in Turtle now I didn't want to do it in Turtle cuz Pi game is a lot better and it's a lot faster uh but if you look here all the the values that I'm using are just coming from here right so like the Earth Mass uh the Earth distance-1 * Au the sun Mass just want to give credit to this article I'll leave it in the description anyways enough of that uh we have the distance to the sun which is this we have zero 160 in blue this is the mass and I think that's all we need for the Earth right now let's now put Earth inside of here and see if when we draw it we get it in an accurate position okay so let's run this and and we get blue is not defined okay I forgot to do that let's define the color blue blue is going to be equal to and then I want kind of a nice light blue so I just picked one of these before it's going to be 100 149 237 this is the RGB value for kind of a lighter blue if you just wanted it to be regular blue then you could go zero Zer and then 255 that give you a nice dark blue okay so let's run this now and see if this works and there we go we get the uh the Earth which is you know 1 Au away from the sun hopefully uh that makes sense but this is how the scale is working we put it attive - 1 Au which means we're going to the left if we put it at 1 Au we would have gone to the right doesn't really matter where we start it and there we go okay so now we have the Earth the next planet that I want to do let's look here is going to be Mars so let's say Mars is equal to a planet now the distance uh for Mars is going to be this so let me just copy it in it's going to be - 1.5 524 * planet au again we're going to put its y-coordinate at zero the radius of Mars it's much smaller than Earth we're going to go with 12 it's going to be red which I'll Define in a second and then the mass of Mars is a little bit less than Earth as well so that's going to be 6.39 * 10 to the exponent 23 now for red we need to Define this now again I wanted kind of a nice looking red so I picked a custom RGB value here and this value is going to be 18 8 39 and 50 okay and now we have Mars so now that we have Mars we're going to put Mars inside of here and we should now draw Mars at the appropriate scale so let's look at this and we see the Mars over here so notice that Mars is kind of right by the border I'm fine with that but if you wanted to move everything in closer then what you would do is reduce this number right here so rather of doing 250 you would do something like 200 and you're going to notice that this going to move us in a little bit closer so that's kind of how you can mess with things uh just make the number here smaller if you want everything to get closer to the Sun okay so we'll go with 250 Au for now all right so now we have Mars let's do our other planets so the other planets we have is mercury this is going to be equal to Planet uh this distance this is the closest one to the sun uh my understanding is at least this is going to be zero we're going to have to make this smaller so we're going to go zero the color is going to be dark gray which will will Implement in a second and then the mass let me just copy this in is going to be 0.330 * 10 to the exponent 24 if we wanted to be consistent we go 3.30 * 10 to the exponent 23 that give us the same thing okay so let's Implement dark gray now so let's go up to Colors dark gray is equal to and then what did I have dark gray at let me just look here this is going to be 807 71 no 78 and 81 again mess with these colors if you want I'm just picking some custom ones so they look a little bit nicer okay so now we have mercury so let's put mercury in here and we can just go right on to Venus which I believe is the next planet so we're going to say Venus is equal to Planet uh its distance is going to be 0.723 time planet au in case you're wondering planet au is referencing this right here just cuz it's inside of the the planet class okay so planet au we're going to have zero uh this is a little bit larger so we're going to have 14 the color of this will just be a regular white and then the mass is going to be this let me copy it in 4.86 A5 * 10 to the exponent 24 okay let me zoom in so you guys can read that a little bit better let's now put Venus in the list and let me go ahead and run this and see if we're getting all of our plants okay nice so there we go and I've just put the plants on different sides again you can kind of put put them wherever you want doesn't really matter we could put them all on the same side and have them move at the same time I'm just staggering them a bit maybe some of you will have issue with that based on your physics knowledge but this is what we're going to do for right now okay there we go we have all of our plants so now that we have all of our planets the next thing we need to do is start moving them now moving them is complicated but again as I mentioned we're going to be moving them by their x velocity and their y velocity but we need to determine what those velocities are and those velocities are determined by the force of attraction so essentially the force of gravity between the different planets all right so I'm going to start explaining the math that's going to go on here to actually move the planets around the Sun and before I can do that I just want to give you a general understanding of gravity and how planets actually orbit around the Sun in case you're unfamiliar so the reason why when we jump up we fall down or when we throw a ball up it comes down is because of gravity now we all know gravity but gravity is relative to different objects okay so all object objects are actually attracting one another and the force of attraction that they have on one another is based on the mass of those objects now this only really becomes relevant when you have very very massive objects like planets so when we're talking about something like Earth this a massive body right is something like you know 6 to 6 multiplied by 10 to the exponent 24 kilg or whatever the number is it's a very very massive body so relative to our Mass which is maybe 60 kg 70 kg 80 kg whatever it is it's way way larger so it actually exerts a massive force on us that pulls us downwards towards the earth now what actually determines the strength of this force is the distance from us to the Center of the Earth hence why when you go up in space you have zero gravity because you're much further away from the earth now all objects again exert forces on each other and those forces depend on the two masses of the objects as well as the distance of the objects but if you're just naively looking at this equation here which is actually the force of attraction you'll see that the between the center of the two objects is the most important when it comes to what type of the force what type of force you're going to get because it's R squ so the further away you go uh exponentially the less gravity you're going to have the closer you get exponentially the more gravity you're going to get now again I'm not a physics major so take everything with a grain of salt here that's the basic understanding of gravity now when we're talking about planets we're talking about multiple massive objects that are moving around each other so when we talk about an object like Earth here right the Earth is moving at a constant velocity well not necessarily constant but it's moving at a relatively constant velocity around the Sun now what forces it to move around the Sun is gravity so the Earth is already on a trajectory moving in the X Direction okay so it has some speed going in the X Direction and then there is a force pulling it towards the Sun that force is gravity or the attraction between the Earth and the Sun now the reason why there's an attraction is because the sun is much much much larger than the earth if the Earth was larger than the sun then the sun would be orbiting around it great example if you think of the moon right the Moon is much smaller than the earth it's very close to the Earth and so it orbits around the uh the Earth okay hopefully this is making a little bit of sense but the idea is that you have some force and uh that Force essentially is causing the Earth to move around the Sun and the reason why the Earth doesn't just shoot directly towards the sun like we shoot directly down on earth when we jump up is cuz it already has momentum moving in Direction and so there's multiple forces affecting it causing it to go in an orbit again very simplified explanation of what's going on but hopefully that makes a bit of sense now the reason I'm saying this is because we have multiple planets that are orbiting around the earth right maybe we have another planet I know I probably shouldn't have drawn it in blue but the point is there's a distance between these two planets and they also have a force of attraction on each other and that's why you're going to have different orbits and different speeds based on the location of other planets and kind of their orbital trajectory so if you have two planets here as well as a planet here well this guy's still orbiting around the sun because the sun is much larger than him but he's going to be orbiting slower than the earth is because he's not as close however the Earth is going to be attracting or having some force of attraction on this planet and this planet is going to have some force of attraction on the earth and so you need to uh take that into account when you're actually calculating the different orbits of the planets all right I know this is a lot very very math and physics heavy here but the idea is every single object exhibit some force on each other and we need to calculate what all of those forces are when we are actually determining the orbit so that we are going to be orbiting appropriate to where the other planets are so we can't just calculate the force to the sun we need to also calculate the force to the other planets and that's going to give us a somewhat elliptical orbit as well okay hopefully this makes a little bit of sense now let's talk about how we actually do this so as I kind of already hinted at if you look to the left of my screen you can see that I have the equation here for the force of attraction between two objects now this force is the straight line force between two objects so let me just move the earth a bit here uh so I can explain kind of what I mean by that and why we need to do a little bit of trigonometry so let's say we have the Earth over here this will say is the force of gravity or the force of attraction between the two objects now to calculate this is fairly simple we just need to First calculate the distance between the two objects which we can do uh we then need to know the masses which we already know and gravitational constant which we know as well so let's say we know the force well if we know the force the issue is it's giving us the straight line Force we want to break this Force into two components so that we are able to move the Earth in an X direction as well as a y direction so we need to kind of understand this that it's giving us the straight line Force we need to break that Force into X and Y components so we can actually move the Earth around the Sun in both the X and the y direction now this is the same way that we're going to calculate the distance it's very easy for us to actually find the distance because we're looking for let me just redraw all of this this right here so this is going to be R we don't know what R is but we know what the Y distance is and the X distan is between these two points because for both these points we have an X and A Y right so we have like X2 and Y2 so if we know both of those points we can calculate the difference in X and the difference in y and then to figure out what R is relative to our right triangle here what equation do we use well pythagore theorem I know I completely butchered that that name but it's going to be x^2 + y squ take the root of that and that's going to give us R okay so we are able to calculate R then obviously we can take the square so once we do that we calculate the distance then we're going to calculate the force and then we need to go in the opposite direction from the force back to the X and Y components okay so let's redraw this so now let's say we know the force okay and again we need to split this into X and Y so we need to have I guess FX and FY now the way that we do this is we need to calculate the angle here Theta because if we have any two aspects of a triangle so if we have one side length and an angle and it's a right angled triangle we can calculate any other angle or any other side length right that's just a property of a right triangle so we know F and we should know this angle and the reason we know this angle is because we know X and we know y so the way we calculate this angle is we take the arc Tang tent so the tan inverse of y/x now to derive why this is going to give us the angle Theta let's look at the equation of tan of theta is equal to and then this is going to be the opposite over the adjacent now I like to remember this as TOA okay but uh this is the equation you know this is a property of a right triangle so if I have tan Theta is equal to the opposite over the adjacent and we're talking about this right here the opposite side length is y the adjacent side length is X and so we can kind of sub those values in right and we get Y and X if we want to isolate for Theta we need to take the inverse tangent so that's what we do we take tan inverse of YX that gives us Theta okay so now that we know Theta we can now use Theta to calculate what the f Force component is or the X Force component is as well as the Y Force component so to do that we need to use some other properties so we have a property it is so uh oops let me write this property so C TOA this is the way that I always remember these but we can say that the S of theta is equal to the opposite over the hypotenuse and since we're looking for the opposite which is FY we can say s of the angle Theta which we know is equal to the F of Y over H H is f we know F and we're able to find what F of Y is by just isolating for f of Y so multiplying F by sin Theta and then same thing if we want to find what FX is we can say FX is equal to this is going to be the co of theta multiplied by F that will give us the FX component and then once we know the X and Y velocity we can very easily move this around the Sun all right math lesson is now over hopefully I didn't confuse you too badly again I'm trying to squeeze in what is probably taught in an entire year of grade 12 physics in about 10 minutes uh but that is the math that we need to understand to be able to move these objects around can't really make it much simpler than that if you don't understand basic trigonometry then I'm sure this was a lot uh but you can kind of just trust the properties that I showed you here and I will show you how to implement them in code if you don't understand totally fine you can still follow along and you will have a working simulation with that said let's go back to the code all right so I'm back in the code and it is time to do some math inside of code now I know we just did a lot of math but now we're doing it in code hopefully that gave you an explanation of what I'm about to write here so I'm on my planet class and I'm going to write a method that will calculate the force of attraction between another object and the current object okay so I'm going to say Define attraction like that I'm going to take in self and I'm going to take in an other object now the other is going to be another planet okay so the first thing I'm going to do is say that my other underscore X other uncore Y is equal to other dox and other doy okay now the first thing we need to do here is we need to calculate the distance between the current object and the other object so let's do that we're going to say the distance in X is equal to and this is going to be the other x minus the self.x okay and then the distance in y is going to be equal to the other y minus the self don't y now it doesn't matter if you take the self.x and subtract it from other dox it doesn't matter what way you do it it's going to give us the uh the magnitude which is what we which is what we want sorry because once we take the square of both these values we're going to get a positive value no matter what so I have the distance X and the distance y now I'm going to say distance is equal to and this is going to be the math.sqrt of the distance x to the exponent 2 plus the distance y to the exponent to okay let me just check and make sure I haven't messed this up yet looks good we have found the distance okay now the first thing I'm going to do is I'm going to say if the other do sun then I'm going to say the self dot distance to Sun is equal to distance now the reason I'm doing this is because if the other object that were calculating the force of attraction with is the sun I just calculate the distance to the Sun and I just want to update the distance to Sun property here so that I can use that when I actually want to draw the distance of the Sun on top of the planet again we're just checking is the other object this Sun if it is okay we know the distance so let's just plug that in and save that value inside of the class that way we're not recalculating it later on we already have the value okay so now that we've done that we need to calculate the force of attraction so we're going to say the force uh yeah I think it's force is going to be equal to self g we're going to multiply this by our self mass multiplied by the other mass and then we're going to divide this by the distance to the exponent two uh and why did I write like that it's going to be distance to the exponent 2 and I think that's good okay now we don't need to do any parentheses because these have the same order of operations and exponent to the exponent two is going to um happen first anyways okay so this is how we calculate the force now remember this is the straight line Force we need to break this Force down into the X into the Y component which is why we had to do all of that trigonometry so now we need to uh calculate the angle Theta so we're going to say Theta is equal to and then this is going to be the math ar tangent of and it's actually going to be here the distance y over the distance X now the reason I'm doing a tan2 is because this is a special function in Python that's going to take the Y over the X and then give us the angle associated with it so make sure you use a tan 2 from the math Library if you just use a tan that's not going to work you need a tan 2 okay so math a tan distance X distance y now we know the angle Theta now that we know the angle Theta we can calculate the x velocity and the Y velocity so we're going to say or sorry not the x velocity we're going to calculate the X force and the Y Force so we're going to say the force x is equal to this is going to be math cosine of theta multiplied by the force okay and then the forcecore Y is going to be equal to the math s of the Theta multiplied by the force okay and then we're going to return from here the force x and the Force y okay let's break down what we did here understand this is probably a little bit confusing still we first calculate the distance between the two objects there we go we have the distance great then what we're going to do is determine if the other object is the sun if it is we're just going to store that distance in a property here because we want to know what that value is now after that we want to calculate the force of attraction so this is the force of attraction here it's FAL M lowercase M uh over R 2 multiplied by the gravitational constant G okay so that's what we're doing so self g * mass multip by other Mass over distance squared okay then we want to break this distance down into the two components so the sorry the force into the X force and the Y Force so we first need to calculate the angle so we say the math arc tangent 2 of the distance y over distance X gives us the angle that we want then we're going to say the force x is equal to the math do cosine of theta multiplied by force and the force Y is equal to the math sin Theta multiplied by the force now remember here that all of these distances and all of these forces are real distances and forces these are actually the distances and the forces that you would see I mean it's an approximation in the real solar system so I'm not using really small pixel values in pi game I'm using massive you know meter per squared uh kilogram squared values whatever the units are of these forces I'm actually using the correct numbers like the large two scale numbers I just want to make that clear here because like if we were to print out what x were and print out with the force where you would see really really massive numbers because that's actually what they are in the real world cuz we're trying to do a simulation here okay anyway so we have attraction now that we have the force of attraction what we need to do is actually update the position of each planet based on the force of attraction between every single other planet because we can't just do it from the sun we need to look at all the other planets as I was discussing kind of in the Whiteboard section so what I'm going to do is make a uh method here I'm going to say update position and this is going to take in self and planets okay so what we're going to do is Loop through all of the planets we're going to calculate the force of attraction between the current planet and all of the other planets we're then going to calculate what the velocity needs to be uh for these planets then we're going to move them by that velocity so we're going to say the total force in the X direction is equal to the total force in the y direction which is currently equal to zero and we're going to sum all of the forces together from all of the plan planets so we're going to say for planet in planets we're going to pass a list of planets here that's what we're taking in we're going to say if self is equal to Planet then continue because we don't want to calculate the force with ourself in fact that would just give us a zero division error because the distance between oursel and oursel is zero right so we can't uh do this division with the arc tangent or sorry with the distance squar that would give us an issue anyways continuing now what we're going to do is say that the force x Force y is equal to and this is going to be the self attraction to this planet okay so again for every single planet we're going to calculate the force x and the force y that it's exerting on this planet we're going to say self attraction is equal to Planet that's what's doing the calculation here that gives us the FX and FY then we're just going to uh sum these two variables or add to these two variables so self x FX plus equal FX and total FY plus equal FY okay so now that we know what the total force is that being exerted on us in the X and the y direction we need to use these forces to actually calculate what the velocity of the planet is going to be all right so the way we calculate the velocity here is we're going to say that the self xor V is equal to the total FX divided by the self dot Mass multiplied by the self Dot and then this is going to be time step now I'm going to explain how this works but this is using kind of the famous equation fals ma okay so we have this equation f equal ma a and this stands for the total force is equal to the mass ID the acceleration now you can use this to solve for the acceleration which is what we're doing here so we're saying the acceleration is equal to F over M so I'm taking my total FX and my total mass right I'm dividing those to get the acceleration now the thing is I'm going to be adding to this so I'm saying self xl plus equals so the way this works is I'm increasing my velocity by my acceleration multiplied by the time step there was another equation that has to do with time and acceleration to equal velocity and all those kinds of things anyways the point is though since we're simulating this over a period of time we're going to take the time step which is right here which is one day we're going to multiply that by whatever the acceleration is and then we're going to take that value and add that to the current velocity now why this is going to give us a perfect elliptical is because as soon as we start going to the left or to the right of the planet and the distances and the angles change our force is going to be either negative or positive uh saying that we're going kind of right or we're going left or we're going up or we're going down so by doing a total summation of all of these forces what ends up happening is we go in a complete circle Because by the time we get to a certain point in the orbit the velocity is going to be changing and either getting more positive or more negative moving us to the left or to the right hopefully that makes a tiny bit of sense but the point is we're going to constantly add this and you'll notice that we're not going to go faster we're just going to change in directions because what's going to happen is x velocity is going to be decreasing while the Y velocity is increasing when we're at a certain point in the circle and then that's going to continually change and change directions as we move around so you you'll see when we start running this but uh that's how this works now we do the exact same thing with the Y so plus equals the total FY over the self mass okay and then multiplied by the self time step okay so now that we have that what we need to do is just increment the X and the Y because this is just the velocity so from acceleration you get velocity from velocity you get displacement or distance which is what we're now going to do so we're going to say self.x uh and then this is going to be plus equals self.x uncore Vel and then we need to multiply this by the time step as well and then we're going to say self y plus equals this needs to be self yvl multiplied by self ep and then let's fix this to be self xell okay and then lastly here uh we can actually say the self orbit and then append and I'm going to append uh just a tupple here which is going to be self.x self.y and yeah I think that's actually good for the orbit okay so let me uh break this down one more time what we're doing is we're getting the total forces exerted on this planet from all other planets that are not itself we are then going to figure out what the the X and the Y velocity is using the equations I described then we are going to update the X and Y position by using the velocity we need to multiply by the time step to make sure we're moving in the accurate amount of time here okay and then we have self orbit uh do append and we're appending the X and Y position that we're currently at so that now we can draw the orbit for this planet which I'm going to do in a second okay so there we go we actually have all of the hard stuff done now we just need to call the update position uh method here on all of our planets and you'll see that they'll start moving around the screen so I'm going to go to right before planet draw and I'm going to say Planet Dot and then this is going to be update position and I'm just going to pass to it planets okay uh and that's actually all we need to start moving the planet and let's just run this now and see if it works okay so let's see and we can see that our planets are moving but we're getting a bit of an issue and I'm going to explain why that happens so first of all the reason why we were seeing our planets like thousands of times on the screen is because we need to refresh the screen by kind of redrawing a background on top of it before we draw everything again so what's happening right now is we're continually drawing the planets but we're not drawing anything on top of the old planets and so we keep seeing the old planets so all I need to do here is say wind fill and I'm just going to put inside of here uh 0000 which is just the color black and now if I run this you're going to see that the planets just zoom towards the sun now now the reason they're zooming towards the sun is because they don't have a velocity in the y or sorry in the x is the X no it's in the y direction So currently right again if I run this you see that they just zoom right towards the Sun and then keep going the reason they're doing that is because we don't have another velocity and that's what would happen if they weren't already moving in another Direction so we need to apply an existing velocity in the y direction to these planets so that they will be moving around the Sun so that the force attracting them to the Sun causes this kind of centrifical motion or the circular motion around the planet I know this is I like this a lot of physics I wasn't actually uh considering how many physics I would need to explain here but the idea is for all of these planets they need some starting velocity in the y direction otherwise the only Force being applied is directly x uh because of kind of where the planets are placed and the fact that we're just going straight down towards the sun that's the only Force being applied currently because we don't have another velocity so let's app the other velocities uh I'm just going to copy them in from my other screen so this is the earth velocity I'll pause so we can read them all in a second this is the Mars velocity this is the Mercury velocity and then this is the Venus velocity okay so the Earth y velocity is 29.78 3 this is kilomet per second multiplied by a th000 which gives us meters per second because that's what we're using excuse me uh the Mars velocity 24 0 uh 77 multipli by 1,000 again this is me/ second so kilom then we convert to meters 47.4 for mercury and then - 35.027185 be negative to make sure that it's going to be moving in the correct direction so if you have one that's positive the other one needs to be negative so that they're all moving in the same direction vice versa hopefully that makes sense but you'll see here uh when this starts running okay so let me actually just run this now and we should see that they orbit so let's have a look okay so there we go now we have an orbit obviously it doesn't look as cool we're not drawing the orbits but notice that they're all moving in the same direction and obviously the ones that are closer to the Sun are moving faster perfect so the same ation seems to be working okay so let's now draw the orbits around and the way that we're going to do that is we're going to use all of the points that we're storing in this orbit list because every time that we call this we're going to add a point to the orbit list uh and we're going to draw them so what I'm going to do is add something here and say h for point in self orbit and I actually want to draw this yeah I'll draw this before I draw the circle I'm going to say XY equals Point uh and then I'm going to say x is equal to X multiplied by self scale and then this is going to be plus width over two and then I'm going to say Y is equal to Y multiplied by self scale plus height over two and then we are going to actually store these in in updated points list we're going to say updated points equal to this updated points append point and then we're going to draw all these points as a line so we're going to say py game draw doline and is it lines let me just have a look here to see actually exactly what we need to do to do so this is actually going to be lines sorry we're going to pass win we're going to pass self docolor we're going to pass pass false which means this is not an enclosed line so we're not going to draw an ending line essentially and then we're going to pass the updated points and we'll pass a thickness of two okay let me explain what I did I understand I kind of just went through this without any explanation so what I'm doing is I'm getting a list of updated points which are going to be all of the XY coordinates to scale right because I need to get them to scale otherwise I can't draw these properly so I take them I do what I need to do to get them to scale exactly what I did right here and then I update uh I make a new list here updated points and append sorry not the point the new XY that I uh made right here okay then I'm going to draw lines now what this does is it takes a list of points which is right here and it essentially just draws a bunch of uh a bunch of lines between the different points and it doesn't enclose them because I passed false now this is the uh thickness that I want to draw the lines which is going to be two pixels now one thing I do need to do is just put an if statement here and say if the lens of self points is less than two actually less than or equal to two because I believe we need at least three points then I don't want to do any of this so we're going to say actually the opposite we're going to say if yeah if L of points is greater than two so meaning that it is at least three then we'll do this just confusing myself there we need at least three points so if the Lend of points greater than two do all of this otherwise don't do it that should give us the orbit so let's see now if we're going to get kind of the orbital ringer around let's run this and Planet object has no attribute points ah sorry it's not points it is orbit and I think I did this right self that orbit yes okay self- orbit nice all right let's see there we go now we get the orbits being drawn as the planets are moving around very nice so I mean you can run the simulation as long as you like and see everything working now what I want to do is implement the distance to the Sun just to show you that this is not a perfect circle Circle it is actually elliptical I know it looks like a perfect circle but since the uh scale is so I guess small here that we're drawing this on you can't really see the elliptical of the orbits okay so now what I want to do is also draw that distance on top so to do that I need to initialize a font in pame so I'm just going to say font is equal to py game font sy font like that and I'm going to pass inside of here comic Sands as my font and for the font size we'll just go with something like 16 so this is the font you want and this is the size okay that's how you initialize the font and then what I need to do if I want to draw the distance is I need to say first of all if not self sun and forgot we're working in Python so let's use the actual not because I don't want to draw the distance between the Sun and the sun which is always going to be zero so I'm going to say if not self sun then we'll say distance unor text is equal to font do render this is how you actually create a text object that you can draw going to say font render we're going to do an F string and this is simply going to be the self distance to the Sun and then this is going to be in meters so what I can do is I can divide this value by th if I want to get kilometers to make it a little bit smaller so let's do that divide by th000 in kilom I'm also just going to round this just so that we don't get a massive number here so let's just round this to one decimal point put that in kilometers and then we want anti-aliasing one which is the next argument and then the last argument I believe is the cut that I want to draw this in which we can just make I guess it shouldn't be self color we'll do white okay perfect so that is now the text object created again you have to use a font object to create a text object which then you can render on the screen now I want you draw it on the screen so I'm going to say win blit I'm going to pass the distance text and then the position that I want to draw this at is a little bit complicated uh and also guys sorry I just realized I made a little bit of a mistake here actually no maybe this is okay the way it is when I Define XY inside the for Loop this might be interfering with this although it didn't seem like it was um so I guess we can just proceed but I don't like having these names Shadow each other okay we'll just proceed for now but uh that's kind of what I was realizing and why I paused there anyways what I'm going to do is draw this at XY and we're referencing this XY here which is going to be the center of the circle now the issue is if I draw this at the center of the circle since I start drawing the text from the top left hand corner you'll see actually let me just run the code and you'll see what happens here when I do this so you'll notice that the actual uh the text is kind of at the bottom right of the center now that looks really ugly I obviously don't want that to be there so what I'm going to do instead is I'm going to make it so it's drawn directly in the center now to do that I need to take the X I need to subtract this from the distance undor text getor width divided by two so if I take the width of the text and divide that by two and then subtract that from the X that shifts me to the left so I'm exactly in the middle and then same thing with the Y so Y is distance text gcore height over two okay nice hopefully that is all clear now I'm just going to take all of this and we're going to put this below when we're drawing the circle so that it gets drawn on top and we don't have any overlap or we don't have the circle kind of overlapping the text okay so let's close that uh you guys can pause the video if you want to have a look at this let's run the code though and let's see what we get now nice okay so now we actually have the uh text being drawn on top and for some of the planets given it is a bit hard to see but that is all working nice so with that said I think I'm going to end this tutorial here this was a lot of stuff to go through I hope you guys appreciated this in all of the math and explanations if you did please make sure you leave a like obviously you can extend this as much as you would like you can mess around with the scale you can mess around with the speed you can change the time step this is a really really flexible program and all of the hard physics and math is done so if you want to add more planets you can really easily do that this is a realistic simulation something I haven't done on the channel before and that I hope you guys appreciate all right with that said I am going to end the video again please like the video subscribe to the channel and I will see you in another one [Music] oh
Original Description
Welcome back to another tutorial video! In this video I am going to be showing you how to make a planet simulation using Python! The goal of this tutorial is to simulate the orbits of different planets around the sun using real astronomical values! We're also going to apply the force of gravity on each of the planets so we get an accurate elliptical orbit! I hope you enjoy!
💻 Thanks to BackTrace for sponsoring this video! Build better games with less bugs today for FREE by signing up for a developer account: https://hubs.la/Q012hTT00
💻 ProgrammingExpert is the best platform to learn how to code and become a software engineer as fast as possible! Check it out here: https://programmingexpert.io/tim and use code "tim" for a discount!
📄 Resources 📄
Inspiration For This Video: https://fiftyexamples.readthedocs.io/en/latest/gravity.html
Code In This Video: https://github.com/techwithtim/Python-Planet-Simulation
Fix Pip (Windows): https://www.youtube.com/watch?v=AdUZArA-kZw&t=204s
Fix Pip (Mac): https://www .youtube.com/watch?v=E-WhAS6qzsU
⭐️ Timestamps ⭐️
00:00 | Planet Simulation
01:15 | Sponsor
02:12 | Setup & Installation
03:46 | Pygame Window Setup
09:28 | Creating Planets
18:50 | Initializing Planets (Using Real Values)
27:33 | Moving Planets Explanation (Math & Physics)
36:45 | Implementing Movement Physics
51:58 | Drawing Orbits
55:38 | Drawing Distance To Sun
59:18 | Conclusion
◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️
👕 Merchandise: https://teespring.com/stores/tech-with-tim-merch-shop
📸 Instagram: https://www.instagram.com/tech_with_tim
📱 Twitter: https://twitter.com/TechWithTimm
⭐ Discord: https://discord.gg/twt
📝 LinkedIn: https://www.linkedin.com/in/tim-ruscica-82631b179/
🌎 Website: https://techwithtim.net
📂 GitHub: https://github.com/techwithtim
🔊 Podcast: https://anchor.fm/tech-with-tim
🎬 My YouTube Gear: https://www.techwithtim.net/gear/
💵 One-Time Donations: https://www.paypal.com/donate?hosted_button_id=CU9FV329ADNT8
💰 Patreon: https://
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Tech With Tim · Tech With Tim · 0 of 60
← Previous
Next →
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
A* Path Finding Algorithm(Visualization)
Tech With Tim
Python Programming Tutorial #1 - Variables and Data Types
Tech With Tim
Python Programming Tutorial #2 - Basic Operators and Input
Tech With Tim
Python Programming Tutorial #3 - Conditions
Tech With Tim
Python Programming Tutorial #4 - IF/ELIF/ELSE
Tech With Tim
Python Programming Tutorial #5 - Chained Conditionals and Nested Statements
Tech With Tim
Python Programming Tutorial #6 - For Loops
Tech With Tim
Python Programming Tutorial #7 - While Loops
Tech With Tim
Python Programming Tutorial #8 - Lists and Tuples
Tech With Tim
Python Programming Tutorial #9 - Iteration by Item (For Loops Continued...)
Tech With Tim
Python Programming Tutorial #10 - String Methods
Tech With Tim
How to Overclock a NVIDIA GPU
Tech With Tim
Python Programming Tutorial #11 - Slice Operator
Tech With Tim
Python Programming Tutorial #12 - Functions
Tech With Tim
Python Programming Tutorial #13 - How to Read a Text File
Tech With Tim
Python Programming Tutorial #14 - Writing to a Text File
Tech With Tim
Python Programming Tutorial #15 - Using .count() and .find()
Tech With Tim
Python Programming Tutorial #16 - Introduction to Modular Programming
Tech With Tim
Python Programming Tutorial #17 - Optional Parameters
Tech With Tim
Python Programming Tutorial #18 - Try and Except (Python Error Handling)
Tech With Tim
Python Programming Tutorial #19 - Global vs Local Variables
Tech With Tim
Python Programming Tutorial #20 - Classes and Objects
Tech With Tim
Cool VBS Script to Prank Your Friends!
Tech With Tim
How to Overclock an AMD GPU
Tech With Tim
Best GPU'S For Mining Ethereum (2018)
Tech With Tim
Recursion and Memoization Tutorial Python
Tech With Tim
Ethereum Mining Rig - Hardware Guide
Tech With Tim
Pygame Tutorial #1 - Basic Movement and Key Presses
Tech With Tim
How to Install Pygame (Windows 8/10)
Tech With Tim
How to Trade Your Cryptocurrency (Bitcoin, Ethereum etc.) For Cash!
Tech With Tim
How to Mine Ethereum 2018 - WORKING (Super-Easy)
Tech With Tim
Microphone Comparison - $10 Mic vs $150 Mic (Blue Yeti USB)
Tech With Tim
Pygame Tutorial #2 - Jumping and Boundaries
Tech With Tim
Pygame Tutorial #3 - Character Animation & Sprites
Tech With Tim
Pygame Tutorial #4 - Optimization & OOP
Tech With Tim
OBS Studio Tutorial - Best OBS Settings
Tech With Tim
Linear Search Algorithm - Python Example and Code
Tech With Tim
Make Any Mic Sound AMAZING! (WITH OBS)
Tech With Tim
Binary Search Algorithm - Python Example & Code
Tech With Tim
Pygame Tutorial #5 - Projectiles
Tech With Tim
Pygame Game - Mini Golf
Tech With Tim
Pygame Tutorial - Projectile Motion (Part 1)
Tech With Tim
Pygame Tutorial - Projectile Motion (Part 2)
Tech With Tim
Pygame Tutorial #6 - Enemies
Tech With Tim
Pygame Tutorial #7 - Collision and Hit Boxes
Tech With Tim
Pygame Tutorial #8 - Scoring and Health Bars
Tech With Tim
Cloud Mining vs. Hardware Mining - 2018
Tech With Tim
How to Install Pygame on Mac OSX (Fast-Simple)
Tech With Tim
Pygame Tutorial #9 - Sound Effects, Music & More Collision
Tech With Tim
Pygame Tutorial #10 - Finishing Touches & Next Steps
Tech With Tim
How to Fade Your Screen in Pygame [CODE IN DESCRIPTION]
Tech With Tim
How to Create a Button in Pygame [CODE IN DESCRIPTION]
Tech With Tim
Pygame Side-Scroller Tutorial #1 - Scrolling Background/Character Movement
Tech With Tim
Pygame Side-Scroller Tutorial #2 - Random Object Generation
Tech With Tim
Pygame Side-Scroller Tutorial #3 - Collision
Tech With Tim
Pygame Side-Scroller Tutorial #4 - Scoring and End Screen
Tech With Tim
How to Create A Message Box in Python - Tkinter
Tech With Tim
Is Ethereum Mining Still Profitable - Is It Worth It (April 2018)
Tech With Tim
How to Run MAC OSX on a WINDOWS PC (Clover Boot-loader)
Tech With Tim
Programming Problem #1 - Alphabet Soup (Beginner/Novice)
Tech With Tim
More on: AI Workflow Automation
View skill →Related Reads
📰
📰
📰
📰
My AI Bill Dropped 95% When I Switched to Chinese Models
Dev.to AI
AI Dubbing for Short Drama: The 2026 Playbook That Actually Scales
Dev.to AI
Why AI App Backends Are Becoming Accounting Systems
Dev.to · StructureIntelligence
I Let AI Build My WordPress Forms for a Week. Here’s What Actually Worked.
Medium · AI
Chapters (11)
| Planet Simulation
1:15
| Sponsor
2:12
| Setup & Installation
3:46
| Pygame Window Setup
9:28
| Creating Planets
18:50
| Initializing Planets (Using Real Values)
27:33
| Moving Planets Explanation (Math & Physics)
36:45
| Implementing Movement Physics
51:58
| Drawing Orbits
55:38
| Drawing Distance To Sun
59:18
| Conclusion
🎓
Tutor Explanation
DeepCamp AI