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.

Комментарии • 120

  • @namdao2672
    @namdao2672 2 года назад +28

    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.

  • @darkknightanimation3493
    @darkknightanimation3493 3 года назад +73

    OMG, smooth, you actually explain, underatted!!! You deserve more, i did not even know pymunk existed!

  • @mathsplug6800
    @mathsplug6800 3 года назад +40

    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

  • @GuilhermeDiGiorgi
    @GuilhermeDiGiorgi 4 года назад +73

    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.

    • @ClearCode
      @ClearCode  4 года назад +11

      Check out the pymunk website, it has lots of examples of cool projects

    • @idontwanthackersanymore5224
      @idontwanthackersanymore5224 Год назад

      How could you do that on your own

    • @0rd3r
      @0rd3r Год назад

      u made me feel dumb

  • @apurvakumardani172
    @apurvakumardani172 3 года назад +22

    Full physics...... Physics+Python=Phython

  • @kefrov
    @kefrov 2 года назад +7

    This is amazing, never knew this library existed. I'm never making my own physics again, thanks.

  • @Purp0w
    @Purp0w Год назад +3

    Thanks for the good tutorials!

  • @scubing9486
    @scubing9486 3 года назад +2

    Man you did an excellent work your channel is no one in RUclips 👌👌👌🤘

  • @malterothkamm3579
    @malterothkamm3579 4 года назад +6

    Just found your channel, brilliant tutorials.
    I hope (and think) u channel grows fast :)
    Much love from Germany!!!

    • @ClearCode
      @ClearCode  4 года назад +1

      Vielen dank :)

    • @malterothkamm3579
      @malterothkamm3579 4 года назад +1

      @@ClearCode wait are you actually from Germany? :D

    • @ClearCode
      @ClearCode  4 года назад +3

      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

    • @Tila1
      @Tila1 4 года назад

      @@ClearCode facts, can you make a video about your atom settings, I love that font

    • @ClearCode
      @ClearCode  4 года назад +2

      @@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"
      }

  • @roocode618
    @roocode618 3 года назад

    You are the best tutor I have ever seen

  • @midnightdev73
    @midnightdev73 4 года назад +3

    I'm just starting out as a programmer and you should have a lot more subs then you have now :)

  • @jasonwalon5470
    @jasonwalon5470 3 года назад +1

    you are amazing!!! keep doing good stuff

  • @vilasd.chawan1769
    @vilasd.chawan1769 6 месяцев назад

    This video is really helpful thanks for sharing your knowledge with us 🙂

  • @umanglunia2194
    @umanglunia2194 3 года назад +8

    This is the only pygame tutorial that makes use of pymunk...
    I didn't even know it existed.
    Awesome tutorial, you deserve more subscribers.

  • @suyashmisra7406
    @suyashmisra7406 2 года назад +1

    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!

  • @muradpetrosyan5128
    @muradpetrosyan5128 4 года назад +4

    Bro how can you only 430 subs, You deserve moreee!!!

  • @farrasfauzan5613
    @farrasfauzan5613 3 года назад +1

    Great video!

  • @atharvapatil7474
    @atharvapatil7474 3 года назад +4

    I want more videos on Pymunk !!!

  • @davinaazizah609
    @davinaazizah609 Год назад

    Thank you it works sir! I'll use it for my presentation

  • @mengguojing6556
    @mengguojing6556 Год назад +1

    This is super helpful!! I just wonder if we can get the pixel array of the simulated animation?

  • @ChannelMovies
    @ChannelMovies 3 года назад +1

    This video very helpfull, I really like this video

  • @mitchellfolbe8729
    @mitchellfolbe8729 4 года назад +2

    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?

    • @sillicon8227
      @sillicon8227 3 года назад

      That's a problem with your png

  • @ademromdhane1271
    @ademromdhane1271 2 года назад

    thank's that video was very helpful

  • @kacperzawisza7040
    @kacperzawisza7040 4 года назад +2

    good video men!!!

  • @DontDoDrugsKidsItsBad
    @DontDoDrugsKidsItsBad 2 года назад +2

    Great video! But could you please publish a video explaining kynematic body type.

  • @piratesofphysics4100
    @piratesofphysics4100 2 года назад

    great video

  • @thatgamer_2397
    @thatgamer_2397 2 года назад +1

    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?

  • @Xinurval
    @Xinurval 3 года назад +1

    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

  • @StarkRaveness
    @StarkRaveness 3 года назад +4

    So good thanks! However after collisions I would expect some rotations on the apples, is this to do with friction?

    • @ilikeeatingcoconut
      @ilikeeatingcoconut 3 месяца назад

      i think you could add it yourself, idk how but check out pymunk's documentaries or keep searching, you might find one

    • @superkult
      @superkult 29 дней назад

      I have the same problem and i cant figure it out.. Im too stupid for the pymnunk dopcumerntaions

  • @brianm2572
    @brianm2572 3 года назад

    Great vid

  • @aminzar446
    @aminzar446 3 года назад +1

    Hy it's possible to do a Simulation of a Alternative Photographic Processes? Thanks

  • @jayengel9012
    @jayengel9012 3 года назад +2

    pls do a kinematic body tutorial!

  • @raviyadaw7715
    @raviyadaw7715 3 года назад

    Awesome

  • @Ishaan_Garud
    @Ishaan_Garud Год назад

    Hey , Is there any way to create a non-blocky, curvy terrain in pygame??????

  • @austineadah2843
    @austineadah2843 3 года назад +1

    Nice.. could one simulating a 3D floating object in water with python?

  • @basiccoder2166
    @basiccoder2166 3 года назад +1

    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)))

  • @techos3253
    @techos3253 3 года назад

    What text editor do you use?

  • @arandomboredindividual7855
    @arandomboredindividual7855 3 года назад +2

    Hey man, what is the IDE/Editor you're using in the video? Im really interested...

  • @josephwilliamcosta
    @josephwilliamcosta Год назад

    do you have a copy of this code posted anywhere? Thank you!

  • @sjacobson42
    @sjacobson42 2 года назад

    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

  • @mehmetberkayozbay2531
    @mehmetberkayozbay2531 3 года назад +1

    how can i create rectangle body for sprite

  • @apurvakumardani172
    @apurvakumardani172 3 года назад +2

    But now, the apple.body.position attribute returns integer.... Maybe due to updates

  • @zihasoo
    @zihasoo 3 года назад

    thank you

  • @senthilkumar-co4vr
    @senthilkumar-co4vr Год назад +1

    gravity and step function is not working
    is that because of any new update

  • @somebody6837
    @somebody6837 3 года назад

    Hello! I just have a simple question that I want the answer of. How do you add anti-aliasing to the circles?

    • @ClearCode
      @ClearCode  3 года назад

      check out the gfxdraw library of python, it can do that. www.pygame.org/docs/ref/gfxdraw.html

    • @somebody6837
      @somebody6837 3 года назад

      @@ClearCode will you ever make another video like this but this time with classes?

  • @v-dev4800
    @v-dev4800 3 года назад

    hey,is pymunk uses lot of cpu and is pygame fps decrese

  • @miguelcolladogomez
    @miguelcolladogomez 2 года назад +1

    Kick to PEP8, as always.

  • @scottli9012
    @scottli9012 3 года назад +1

    Can we get the source somewhere?

  • @slowmomoose8546
    @slowmomoose8546 2 года назад

    Can I add movement to this? Or can I just watch

  • @biophotography903
    @biophotography903 2 года назад

    How can I make the image smaller?

  • @CPlusPy
    @CPlusPy 5 месяцев назад +2

    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?

    • @ClearCode
      @ClearCode  5 месяцев назад +2

      you messed up the indentation for the game loop!

    • @CPlusPy
      @CPlusPy 5 месяцев назад

      @@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

  • @shikshya2594
    @shikshya2594 2 года назад

    Holy Fuck I'm never writing collision functions in pygame ever again
    Thank you so muchhhhhhhhhhhh

  • @ecniiv
    @ecniiv Год назад

    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

  • @capybara8581
    @capybara8581 3 года назад

    sir ! how can i run the code that i created in pymunk in my website?\

  • @marcoshaw1
    @marcoshaw1 2 года назад

    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.

    • @StarFury2
      @StarFury2 Год назад +1

      He made a mistake, it must be ==

  • @Pixel_Magic
    @Pixel_Magic 3 года назад

    Dont work... Color of background isn't changing. And i dont see ball, i tryed to make it white. But its not work...

  • @ohtych1004
    @ohtych1004 3 года назад +2

    Would it be possible to use pymunk with ursina?

    • @ClearCode
      @ClearCode  3 года назад +3

      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.

    • @ohtych1004
      @ohtych1004 3 года назад

      @@ClearCode thank you

  • @qidirbinu5640
    @qidirbinu5640 2 года назад

    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? 😅

  • @avstechindian8807
    @avstechindian8807 2 года назад +1

    I am your 1100th liker

  • @dnyaneshwarikadam7207
    @dnyaneshwarikadam7207 Год назад +1

    I get this error:
    AttributeError: module 'pymunk.body' has no attribute 'STATIC'
    What should i do?

    • @StarFury2
      @StarFury2 Год назад +1

      Check for capital "B" in body. You actually want to instance of a Body() class, like:
      body = pymunk.Body(body_type=pymunk.Body.STATIC)

  • @YOy50
    @YOy50 3 года назад

    When I put the apple it won't show

  • @lyrics4047
    @lyrics4047 3 года назад

    What text editor you use ? :D

  • @cmop0693
    @cmop0693 2 года назад

    i dont know why I cant see any response on the screen
    It has correct background color, but neither ball nor apple are visible.

    • @cmop0693
      @cmop0693 2 года назад

      code is exactly same and I am using pycharm professional, not sure why it is not working.

    • @cmop0693
      @cmop0693 2 года назад

      So i have made some changes and now it is working. Awesome explanation.

    • @cmop0693
      @cmop0693 2 года назад

      @Arpan Rai i got it, just switch the position of screen fill to the top of the while loop.

  • @videogamegenerator5106
    @videogamegenerator5106 2 года назад

    Please upload about poly too. instead of circles.

  • @praizdev
    @praizdev 2 года назад

    Can games created using pygame be deployed?

  • @anis6674
    @anis6674 Год назад

    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

  • @passion002
    @passion002 2 года назад +1

    Do the same thing by using Ursina please

  • @josephinealmas3692
    @josephinealmas3692 3 года назад +1

    My screen in PyGame is black. No errors showing up. Someone please help me!

    • @thebosssss9634
      @thebosssss9634 Год назад

      not sure if it matters to you anymore, but move the code at the end under the while loop

  • @ScumBagHarley
    @ScumBagHarley Год назад

    If the dynamic ball does not move use "space.step(0.02)" instead of 1/50 like in the video.

  • @blaukampfflieger
    @blaukampfflieger 3 года назад

    Um clear code? i got a problem
    The object of type "int" has no len().
    SOMEONE HELP PLS

    • @ClearCode
      @ClearCode  3 года назад

      you created an integer when you were supposed to make a list

    • @blaukampfflieger
      @blaukampfflieger 3 года назад

      i did what you said what's wrong

    • @jachymdolezal5103
      @jachymdolezal5103 3 года назад

      @@blaukampfflieger check your code u might make a type somewhere it happened to me many times.

  • @anilkumarsharma8901
    @anilkumarsharma8901 2 года назад +1

    please give code file link

  • @0rd3r
    @0rd3r Год назад

    why...
    why u dont follow the rules of pep 8
    rly good tutorial btw

  • @rahotep4927
    @rahotep4927 3 года назад

    You should have a source code

  • @tushar_mahajan
    @tushar_mahajan 2 года назад

    Kyu Abhishek ne maya ko apne bhai ke paas bheja?

  • @xseis.
    @xseis. Год назад

    pymunk. 1sst off im not gay, 2nd off im a monké but not monk alr

  • @sucram314
    @sucram314 2 года назад

    It is very laggy for me

  • @SamosaShorts2013
    @SamosaShorts2013 2 года назад +1

    Give the code!!!!!!!!!!!!!!!!!

  • @gamertronky8648
    @gamertronky8648 Год назад

    you have so big screen

  • @oyunlarveparodiler3221
    @oyunlarveparodiler3221 3 года назад +2

    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*