Simulating physics in Python
HTML-код
- Опубликовано: 1 июн 2020
- This tutorial is about simulating physics in python with the pymunk module; and to visualise the results pygame will be used. The specific project we will make is going to be a simple 2D simulation of apples falling down.
Clear Code is a underrated channel that only lucky people can find, and he's really know how to teach and make people understanding problem step bt step.
Totally Agree
OMG, smooth, you actually explain, underatted!!! You deserve more, i did not even know pymunk existed!
This is fantastic.
Physics simulation made easy on python.
I spent ages doing this on Matlab and one afternoon on this.
Thanks for the lesson
Pymunk? Holy... I always create the whole energy, speed, momentum, gravity logic into pygame to make my balls run. Im glad theres a library for it. I havent done it before, but doing balls colliding with rects and calculating the rotational and regular speeds and reactions would be hell.
Check out the pymunk website, it has lots of examples of cool projects
How could you do that on your own
u made me feel dumb
Full physics...... Physics+Python=Phython
Nope
This is amazing, never knew this library existed. I'm never making my own physics again, thanks.
Thanks for the good tutorials!
Man you did an excellent work your channel is no one in RUclips 👌👌👌🤘
Just found your channel, brilliant tutorials.
I hope (and think) u channel grows fast :)
Much love from Germany!!!
Vielen dank :)
@@ClearCode wait are you actually from Germany? :D
I grew up in Germany, but things got weird and I ended up living in lots of different countries. It's a bit weird... I do miss some good Döner though :D
@@ClearCode facts, can you make a video about your atom settings, I love that font
@@Tila1 hey, I am actually using the sublime code editor, here are the settings: {
"caret_extra_bottom": 1,
"caret_extra_top": 1,
"caret_extra_width": 0.5,
"caret_style": "solid",
"color_scheme": "Packages/Base16 Color Schemes/Themes/base16-one-light.tmTheme",
"font_size": 28,
"gutter": true,
"highlight_line": true,
"ignored_packages":
[
"Vintage"
],
"line_numbers": false,
"line_padding_bottom": 4,
"line_padding_top": 4,
"mini_diff": false,
"overlay_scroll_bars": "enabled",
"theme": "ayu-light.sublime-theme"
}
You are the best tutor I have ever seen
I'm just starting out as a programmer and you should have a lot more subs then you have now :)
you are amazing!!! keep doing good stuff
This video is really helpful thanks for sharing your knowledge with us 🙂
This is the only pygame tutorial that makes use of pymunk...
I didn't even know it existed.
Awesome tutorial, you deserve more subscribers.
pos_x = int(ball.body.position.x)
ValueError: cannot convert float NaN to integer
>>>
if you faced this error , a quick fix is to pass two integers as arguments to
body = pymunk.Body(1,1,pymunk.Body.STATIC)
in the function definition for static_ball().
great tutorial, thanks a lot!
Bro how can you only 430 subs, You deserve moreee!!!
dont worry he got 2k now!
Now about 10k
Great video!
I want more videos on Pymunk !!!
Thank you it works sir! I'll use it for my presentation
This is super helpful!! I just wonder if we can get the pixel array of the simulated animation?
This video very helpfull, I really like this video
really enjoyed that. looking forward to more projects. the apple i found has a boarder around it so it looks awkward. do you have a git link for yours?
That's a problem with your png
thank's that video was very helpful
good video men!!!
Great video! But could you please publish a video explaining kynematic body type.
great video
what should I do if the image of the apple is too big? what is the code to change its size? and where is the proper placement in the script?
Hi! do you have a download link for the images or code by any chance... im getting some problems and idk how to fix, perhaps it could be because ive loaded the wrong images or incorrect code
So good thanks! However after collisions I would expect some rotations on the apples, is this to do with friction?
i think you could add it yourself, idk how but check out pymunk's documentaries or keep searching, you might find one
I have the same problem and i cant figure it out.. Im too stupid for the pymnunk dopcumerntaions
Great vid
Hy it's possible to do a Simulation of a Alternative Photographic Processes? Thanks
pls do a kinematic body tutorial!
Awesome
Hey , Is there any way to create a non-blocky, curvy terrain in pygame??????
Nice.. could one simulating a 3D floating object in water with python?
That was a very cool tutorial
Thanks Clear Code btw you can get a satisfactory result if you use below co-ordinates
balls.append(static_ball(space,(200,100)))
balls.append(static_ball(space,(310,175)))
balls.append(static_ball(space,(200,250)))
balls.append(static_ball(space,(310,325)))
i will try and tell you
What text editor do you use?
Hey man, what is the IDE/Editor you're using in the video? Im really interested...
Sublime text
@@ClearCode What theme is that?
do you have a copy of this code posted anywhere? Thank you!
My kingdom for a portable version of Python with GUI editor and Pygame all connected. I’d use it with all 100+ of my game design students
how can i create rectangle body for sprite
But now, the apple.body.position attribute returns integer.... Maybe due to updates
thank you
gravity and step function is not working
is that because of any new update
Hello! I just have a simple question that I want the answer of. How do you add anti-aliasing to the circles?
check out the gfxdraw library of python, it can do that. www.pygame.org/docs/ref/gfxdraw.html
@@ClearCode will you ever make another video like this but this time with classes?
hey,is pymunk uses lot of cpu and is pygame fps decrese
Kick to PEP8, as always.
Can we get the source somewhere?
Can I add movement to this? Or can I just watch
How can I make the image smaller?
Great video! Though my code won't run with me constantly moving my mouse, otherwise it will pause until I move it again, what's going on here?
you messed up the indentation for the game loop!
@@ClearCode Thanks so much, im sorry i hadnt seen this earlier thanks for the help with this and the entire project, it was a fun one and Im hoping to code it more
Holy Fuck I'm never writing collision functions in pygame ever again
Thank you so muchhhhhhhhhhhh
13:03 I somehow didn't get an error but I just copy paste what you do, I assume it's because of an update since this video is from 2 years ago
sir ! how can i run the code that i created in pymunk in my website?\
At 20:25 I don't know if it's newer versions of the modules, but I had to use a == or it was failing.
He made a mistake, it must be ==
Dont work... Color of background isn't changing. And i dont see ball, i tryed to make it white. But its not work...
Would it be possible to use pymunk with ursina?
Pymunk does nothing but physics calculations and returns numbers, although only for 2d spaces. So yeah, you could connect it, all you need are the ursina screen dimensions.
@@ClearCode thank you
I have a problem:
if event.type = pygame.MOUSEBUTTONDOWN:
^
SyntaxError: invalid syntax
when I change to:
if event.type == pygame.MOUSEBUTTONDOWN:
the syntax does not error anymore but:
TypeError: create_apple() missing 1 required positional argument: 'pos'
can someone help me? 😅
I am your 1100th liker
I get this error:
AttributeError: module 'pymunk.body' has no attribute 'STATIC'
What should i do?
Check for capital "B" in body. You actually want to instance of a Body() class, like:
body = pymunk.Body(body_type=pymunk.Body.STATIC)
When I put the apple it won't show
What text editor you use ? :D
The original python ide
i dont know why I cant see any response on the screen
It has correct background color, but neither ball nor apple are visible.
code is exactly same and I am using pycharm professional, not sure why it is not working.
So i have made some changes and now it is working. Awesome explanation.
@Arpan Rai i got it, just switch the position of screen fill to the top of the while loop.
Please upload about poly too. instead of circles.
Can games created using pygame be deployed?
bruh i used to litteraly create physics manualy by giving the balls an x velociy and a y velocty and adding the force of grvity to theem and add the velocity to the balls position thoose days are over now
Do the same thing by using Ursina please
My screen in PyGame is black. No errors showing up. Someone please help me!
not sure if it matters to you anymore, but move the code at the end under the while loop
If the dynamic ball does not move use "space.step(0.02)" instead of 1/50 like in the video.
Um clear code? i got a problem
The object of type "int" has no len().
SOMEONE HELP PLS
you created an integer when you were supposed to make a list
i did what you said what's wrong
@@blaukampfflieger check your code u might make a type somewhere it happened to me many times.
please give code file link
why...
why u dont follow the rules of pep 8
rly good tutorial btw
You should have a source code
Kyu Abhishek ne maya ko apne bhai ke paas bheja?
Kyu?
what is this, I have not commented this
Lol, it's you.
pymunk. 1sst off im not gay, 2nd off im a monké but not monk alr
It is very laggy for me
Give the code!!!!!!!!!!!!!!!!!
you have so big screen
Phython users:A really basic physic simulator in 23 minutes and with a lot of code
Unity users:Rigidbody 2D/3D Collider 2D/3D a complicated physics simulator in 2 seconds and with zero code *GO BRRR*