{"id":303073,"date":"2020-05-05T21:00:21","date_gmt":"2020-05-05T21:00:21","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=303073"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=303073","title":{"rendered":"\u041f\u0440\u043e\u0441\u0442\u0430\u044f \u043a\u043e\u0441\u043c\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Python \u0438 Box2D"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/500568\/\">\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440.<\/p>\n<p>  \u041d\u0430 \u0434\u0430\u043d\u043d\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e \u043c\u0435\u043d\u044f \u0432\u0434\u043e\u0445\u043d\u043e\u0432\u0438\u043b\u0430 \u043d\u0435\u0434\u0430\u0432\u043d\u044f\u044f \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u044f <a href=\"https:\/\/habr.com\/ru\/post\/494546\/\">\u041c\u043e\u0434\u0435\u043b\u0438\u0440\u0443\u0435\u043c \u0412\u0441\u0435\u043b\u0435\u043d\u043d\u0443\u044e<\/a>, \u0433\u0434\u0435 \u0430\u0432\u0442\u043e\u0440 \u043f\u043e\u043a\u0430\u0437\u0430\u043b \u0432\u0435\u0441\u044c\u043c\u0430 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435 \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0440\u0430\u0437\u043d\u044b\u0445 \u043a\u043e\u0441\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u044f\u0432\u043b\u0435\u043d\u0438\u0439. \u041e\u0434\u043d\u0430\u043a\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0442\u0430\u043c \u043a\u043e\u0434 \u043d\u0435\u043f\u0440\u043e\u0441\u0442 \u0434\u043b\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445. \u042f \u043f\u043e\u043a\u0430\u0436\u0443 \u043a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u0432\u0438\u0436\u043a\u0430 <a href=\"https:\/\/box2d.org\/about\/\" rel=\"nofollow\">Box2D<\/a>, \u043d\u0430\u043f\u0438\u0441\u0430\u0432 \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u043a \u043a\u043e\u0434\u0430. <\/p>\n<p>  \u0420\u0438\u0441\u043a\u043d\u0443 \u043e\u0448\u0438\u0431\u0438\u0442\u044c\u0441\u044f, \u043d\u043e \u044d\u0442\u043e \u043f\u0435\u0440\u0432\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 Box2D \u0434\u043b\u044f Python \u043d\u0430 \u0425\u0430\u0431\u0440\u0435, \u0432\u043e\u0441\u043f\u043e\u043b\u043d\u0438\u043c \u044d\u0442\u043e\u0442 \u043f\u0440\u043e\u0431\u0435\u043b.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ja\/b7\/zy\/jab7zymczq9q1pvs5eea2xuzy7k.gif\"><\/p>\n<p>  \u0414\u043b\u044f \u0442\u0435\u0445 \u043a\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u043a\u0430\u043a \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u0434 \u043a\u0430\u0442\u043e\u043c.<br \/>  <a name=\"habracut\"><\/a><br \/>  Box2D \u044d\u0442\u043e \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u0430\u044f \u043a\u0440\u043e\u0441\u0441\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u0430\u044f \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u043e\u043c Blizzard Erin Catto. \u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0431\u044b\u043b\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u0432 2007 \u0433\u043e\u0434\u0443, \u0438 \u043d\u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f\u0448\u043d\u0438\u0439 \u0434\u0435\u043d\u044c \u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0441\u0435 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b. \u0415\u0441\u0442\u044c \u043f\u043e\u0440\u0442 \u0438 \u0434\u043b\u044f Python, \u0435\u0433\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0437\u0430\u043f\u0443\u0442\u0430\u043d\u043d\u043e\u0435, \u043d\u043e \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u0432\u0441\u0435 \u0441\u0442\u0430\u043d\u0435\u0442 \u043f\u043e\u043d\u044f\u0442\u043d\u0435\u0435. <\/p>\n<h2>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h2>\n<p>  \u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 <a href=\"https:\/\/github.com\/pybox2d\/pybox2d\" rel=\"nofollow\">pybox2d<\/a> \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0434\u0432\u0443\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u2014 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e Box2D, \u043a\u0440\u043e\u0441\u0441\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0434\u043b\u044f \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0438 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0438, \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u043e\u0433\u043e Framework. \u041e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0430 \u043d\u0443\u0436\u043d\u0430, \u0435\u0441\u043b\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0432\u0438\u0434\u0435\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435, \u0447\u0442\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0439 \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u0438. \u041a\u043b\u0430\u0441\u0441 Framework \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0432\u044b\u0432\u043e\u0434\u0430 (\u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 <a href=\"https:\/\/github.com\/pybox2d\/pybox2d\/tree\/master\/library\/Box2D\/examples\/backends\" rel=\"nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>), \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c pygame. \u0415\u0441\u043b\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 pygame \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0430, \u043e\u043d\u0430 \u00ab\u043f\u043e\u0434\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f\u00bb \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438, \u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e. \u0414\u043b\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u0432\u0435\u0441\u0442\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 <b>pip install Box2D pygame<\/b>. <\/p>\n<p>  \u041c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0430\u044f Box2D, \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u0430 \u043d\u0438\u0436\u0435. \u041a\u043e\u0434 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0440\u043e\u0441\u0441\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u044b\u043c, \u0438 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432\u0435\u0437\u0434\u0435, \u0438 \u0432 Linux \u0438 \u0432 Windows.<\/p>\n<pre><code class=\"python\">from Box2D.examples.framework import Framework from Box2D import *  class Simulation(Framework):     def __init__(self):         super(Simulation, self).__init__()          # Ground body         self.world.CreateBody(shapes=b2LoopShape(vertices=[(20, 0), (20, 40), (-20, 40), (-20, 0)]))         # Dynamic body         circle = b2FixtureDef(shape=b2CircleShape(radius=2), density=1, friction=1.0, restitution=0.5)         self.world.CreateBody(type=b2_dynamicBody, position=b2Vec2(0,30), fixtures=circle, linearVelocity=(5, 0))      def Step(self, settings):         super(Simulation, self).Step(settings)  if __name__ == &quot;__main__&quot;:     Simulation().run()<\/code><\/pre>\n<p>  \u041a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0432\u0438\u0434\u0435\u0442\u044c, \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043a\u043b\u0430\u0441\u0441 Simulation, \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c\u044b\u0439 \u043e\u0442 \u0443\u0436\u0435 \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u043e\u0433\u043e Framework. \u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0432\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u044b\u0437\u043e\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 <b>CreateBody<\/b>. \u041f\u0435\u0440\u0432\u044b\u0439 \u044d\u0442\u043e \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043e\u0431\u044a\u0435\u043a\u0442, \u0437\u0430\u0434\u0430\u044e\u0449\u0438\u0439 \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u043d\u0430\u0448\u0435\u0433\u043e \u043c\u0438\u0440\u0430. \u0412\u0442\u043e\u0440\u043e\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0438\u043c\u0435\u0435\u0442 \u0442\u0438\u043f b2_dynamicBody, \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b (\u0444\u043e\u0440\u043c\u0430, \u0440\u0430\u0437\u043c\u0435\u0440, \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u044c, \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u0442\u0440\u0435\u043d\u0438\u044f, \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c) \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b \u0438\u0437 \u043a\u043e\u0434\u0430. \u0424\u0443\u043d\u043a\u0446\u0438\u044f <b>Step<\/b> \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u0438, \u043c\u044b \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u044d\u0442\u0438\u043c \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c. \u0415\u0441\u043b\u0438 UI \u043d\u0435 \u043d\u0443\u0436\u0435\u043d, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043c\u044b \u0434\u0435\u043b\u0430\u0435\u043c backend \u0434\u043b\u044f \u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u0442\u043e \u0440\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f, \u043a\u043b\u0430\u0441\u0441 Framework \u043c\u043e\u0436\u043d\u043e \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u043d\u043e \u0434\u043b\u044f \u043d\u0430\u0441 \u044d\u0442\u043e \u0432\u043f\u043e\u043b\u043d\u0435 \u0443\u0434\u043e\u0431\u043d\u043e. <\/p>\n<p>  \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438 \u0432\u0441\u0435, \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0438 \u0432\u0438\u0434\u0438\u043c \u0433\u043e\u0442\u043e\u0432\u0443\u044e \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u044e:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/2j\/rm\/d4\/2jrmd4cnndjtzik3hatcujqrchy.gif\"><\/p>\n<p>  \u041a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0432\u0438\u0434\u0435\u0442\u044c, \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0434\u0432\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0438 \u0443\u043a\u0430\u0437\u0430\u043b\u0438 \u0438\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b. \u0412\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u00ab\u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438\u00bb \u2014 \u0441\u0438\u043b\u0430 \u0442\u044f\u0436\u0435\u0441\u0442\u0438, \u0442\u0440\u0435\u043d\u0438\u0435, \u0443\u043f\u0440\u0443\u0433\u043e\u0441\u0442\u044c, \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0442\u0435\u043b \u0438 \u043f\u0440. \u041d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0430\u0442\u044c \u043a \u043d\u0430\u0448\u0435\u0439 \u00ab\u043a\u043e\u0441\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439\u00bb \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u0438.<\/p>\n<h2>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u00ab\u0441\u043f\u0443\u0442\u043d\u0438\u043a\u00bb<\/h2>\n<p>  \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0439 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u041d\u044c\u044e\u0442\u043e\u043d\u043e\u0432\u0441\u043a\u043e\u0439 \u0433\u0440\u0430\u0432\u0438\u0442\u0430\u0446\u0438\u0438 \u0432 Box2D \u043d\u0435\u0442, \u0435\u0451 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e, \u0434\u043e\u043f\u0438\u0441\u0430\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e Step. \u0414\u043b\u044f \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0434\u0432\u0430 \u0442\u0435\u043b\u0430 \u2014 \u043f\u043b\u0430\u043d\u0435\u0442\u0443, \u0438 \u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0438\u0439\u0441\u044f \u0432\u043e\u043a\u0440\u0443\u0433 \u043d\u0435\u0451 \u0441\u043f\u0443\u0442\u043d\u0438\u043a.<\/p>\n<p>  \u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u0446\u0435\u043b\u0438\u043a\u043e\u043c:<\/p>\n<pre><code class=\"python\">from Box2D import * from Box2D.examples.framework import Framework   class Simulation(Framework):     def __init__(self):         super(Simulation, self).__init__()          # Default gravity disable         self.world.gravity = (0.0, 0.0)         # Gravity constant         self.G = 100          # Planet         circle = b2FixtureDef(shape=b2CircleShape(radius=5), density=1, friction=0.5, restitution=0.5)         self.world.CreateBody(type=b2_dynamicBody, position=b2Vec2(0,0), fixtures=circle)          # Satellite         circle_small = b2FixtureDef(shape=b2CircleShape(radius=0.2), density=1, friction=0.5, restitution=0.2)         self.world.CreateBody(type=b2_dynamicBody, position=b2Vec2(0, 10), fixtures=circle_small, linearVelocity=(20, 0))      def Step(self, settings):         super(Simulation, self).Step(settings)          # Simulate the Newton's gravity         for bi in self.world.bodies:             for bk in self.world.bodies:                 if bi == bk:                     continue                  pi, pk = bi.worldCenter, bk.worldCenter                 mi, mk = bi.mass, bk.mass                 delta = pk - pi                 r = delta.length                 if abs(r) &lt; 1.0:                     r = 1.0                  force = self.G * mi * mk \/ (r * r)                 delta.Normalize()                 bi.ApplyForce(force * delta, pi, True)  if __name__ == &quot;__main__&quot;:     Simulation().run()<\/code><\/pre>\n<p>  \u041a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0432\u0438\u0434\u0435\u0442\u044c, \u043c\u044b \u00ab\u043e\u0442\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u00bb \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0443\u044e \u0433\u0440\u0430\u0432\u0438\u0442\u0430\u0446\u0438\u044e, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 self.world.gravity \u0432 0. \u0422\u0430\u043a\u0436\u0435 \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 G, \u044d\u0442\u043e \u00ab\u0433\u0440\u0430\u0432\u0438\u0442\u0430\u0446\u0438\u043e\u043d\u043d\u0430\u044f \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u0430\u044f\u00bb \u043d\u0430\u0448\u0435\u0433\u043e \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043c\u0438\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u0440\u0430\u0441\u0447\u0435\u0442\u0435 \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 Step. \u0422\u0430\u043a\u0436\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0434\u0432\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u2014 \u0441\u043f\u0443\u0442\u043d\u0438\u043a \u0438 \u043f\u043b\u0430\u043d\u0435\u0442\u0443. \u0417\u0434\u0435\u0441\u044c \u0432\u0430\u0436\u043d\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b density (\u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u044c) \u0438 radius. \u041f\u043e \u044d\u0442\u0438\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 Box2D \u0441\u0430\u043c\u0430 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 \u043c\u0430\u0441\u0441\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u0440\u0430\u0441\u0447\u0435\u0442\u0435. \u0414\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0441\u0438\u043b\u044b \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043e\u0431\u044b\u0447\u043d\u0430\u044f \u00ab\u0448\u043a\u043e\u043b\u044c\u043d\u0430\u044f\u00bb \u0444\u043e\u0440\u043c\u0443\u043b\u0430 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%9A%D0%BB%D0%B0%D1%81%D1%81%D0%B8%D1%87%D0%B5%D1%81%D0%BA%D0%B0%D1%8F_%D1%82%D0%B5%D0%BE%D1%80%D0%B8%D1%8F_%D1%82%D1%8F%D0%B3%D0%BE%D1%82%D0%B5%D0%BD%D0%B8%D1%8F_%D0%9D%D1%8C%D1%8E%D1%82%D0%BE%D0%BD%D0%B0\" rel=\"nofollow\">\u0437\u0430\u043a\u043e\u043d\u0430 \u0442\u044f\u0433\u043e\u0442\u0435\u043d\u0438\u044f \u041d\u044c\u044e\u0442\u043e\u043d\u0430<\/a>:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/2c\/e8\/uh\/2ce8uhhbxbflqmwpslxvsryji3m.png\"><\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u044e. \u041f\u0435\u0440\u0432\u043e\u0439 \u043a\u043e\u0441\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u043c\u044b \u043d\u0435 \u0434\u043e\u0441\u0442\u0438\u0433\u043b\u0438, \u0438 \u0445\u043e\u0442\u044f \u0441\u043f\u0443\u0442\u043d\u0438\u043a \u0432\u0441\u0435-\u0442\u0430\u043a\u0438 \u043e\u0431\u043e\u0433\u043d\u0443\u043b \u0432\u0441\u044e \u043f\u043b\u0430\u043d\u0435\u0442\u0443, \u00ab\u043f\u043e\u043b\u0435\u0442\u043e\u043c\u00bb \u044d\u0442\u043e \u043d\u0430\u0437\u0432\u0430\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u043e:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/-i\/54\/bn\/-i54bnhv60xzrd0r7tzscobuq04.gif\"><\/p>\n<p>  \u0423\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u043c \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c, \u0438\u0437\u043c\u0435\u043d\u0438\u0432 \u0441\u0442\u0440\u043e\u0447\u043a\u0443 \u043a\u043e\u0434\u0430 \u043d\u0430 linearVelocity=(28, 0):<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/s9\/ek\/5l\/s9ek5l5qqaertw1obapwrx7jvzy.gif\"><\/p>\n<p>  \u041d\u0430\u0448 \u00ab\u0441\u043f\u0443\u0442\u043d\u0438\u043a\u00bb \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0432\u044b\u0448\u0435\u043b \u043d\u0430 \u043e\u0440\u0431\u0438\u0442\u0443 \u0432\u043e\u043a\u0440\u0443\u0433 \u00ab\u043f\u043b\u0430\u043d\u0435\u0442\u044b\u00bb! \u0415\u0441\u043b\u0438 \u0435\u0449\u0435 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c, \u043e\u0440\u0431\u0438\u0442\u0430 \u0441\u0442\u0430\u043d\u0435\u0442 \u044d\u043b\u043b\u0438\u043f\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439: <\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/py\/ei\/nf\/pyeinf7mofrwej3oxa2nrh_3gwo.gif\"><\/p>\n<p>  \u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u0438\u0437\u043e\u0431\u0440\u0430\u0437\u0438\u043c \u043d\u0435\u0447\u0442\u043e, \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0445\u043e\u0436\u0435\u0435 \u043d\u0430 \u043d\u0430\u0448\u0443 \u00ab\u0441\u043e\u043b\u043d\u0435\u0447\u043d\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443\u00bb, \u0434\u043e\u0431\u0430\u0432\u0438\u0432 \u0442\u0440\u0438 \u043f\u043b\u0430\u043d\u0435\u0442\u044b \u0440\u0430\u0437\u043d\u044b\u0445 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u0432 \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u043e\u0440\u0431\u0438\u0442\u0430\u0445:<\/p>\n<pre><code class=\"python\">circle_small = b2FixtureDef(shape=b2CircleShape(radius=0.2), density=1, friction=0.5, restitution=0.2) circle_medium = b2FixtureDef(shape=b2CircleShape(radius=0.3), density=1, friction=1.0, restitution=0.5) self.world.CreateBody(type=b2_dynamicBody, position=b2Vec2(0, 6), fixtures=circle_small, linearVelocity=(37, 0)) self.world.CreateBody(type=b2_dynamicBody, position=b2Vec2(0, 10), fixtures=circle_small, linearVelocity=(28, 0)) self.world.CreateBody(type=b2_dynamicBody, position=b2Vec2(0, 15), fixtures=circle_medium, linearVelocity=(22, 0))<\/code><\/pre>\n<p>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/we\/9l\/tj\/we9ltjtbzrydvigbta1nczj_2zm.gif\"><\/p>\n<p>  \u041c\u044b \u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u0447\u0435\u043c \u0434\u0430\u043b\u044c\u0448\u0435 \u043f\u043b\u0430\u043d\u0435\u0442\u0430 \u043e\u0442 \u00ab\u0441\u043e\u043b\u043d\u0446\u0430\u00bb, \u0442\u0435\u043c \u043c\u0435\u043d\u044c\u0448\u0435 \u0435\u0451 \u043f\u0435\u0440\u0438\u043e\u0434 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f (3\u0439 \u0437\u0430\u043a\u043e\u043d \u041a\u0435\u043f\u043b\u0435\u0440\u0430). \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0434\u0432\u0438\u0436\u043e\u043a Box2D \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0438\u0441\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435 \u0442\u0440\u0435\u043a\u0438 \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u044f, \u0442\u0430\u043a \u0447\u0442\u043e 1\u0439 \u0438 2\u0439 \u0437\u0430\u043a\u043e\u043d\u044b \u041a\u0435\u043f\u043f\u043b\u0435\u0440\u0430 \u00ab\u0443\u0432\u0438\u0434\u0435\u0442\u044c\u00bb \u0441\u043b\u043e\u0436\u043d\u043e, \u043d\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0443\u0432\u0435\u0440\u0435\u043d\u043d\u044b\u043c\u0438, \u0447\u0442\u043e \u043e\u043d\u0438 \u0442\u0430\u043a\u0436\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f.<\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>  \u041a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0432\u0438\u0434\u0435\u0442\u044c, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Box2D \u043d\u0435\u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0443\u0441\u0438\u043b\u0438\u044f\u043c\u0438. \u0420\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f, \u0434\u0432\u0438\u0436\u043e\u043a \u044d\u0442\u043e\u0442 \u0432\u0441\u0435 \u0436\u0435 \u0438\u0433\u0440\u043e\u0432\u043e\u0439, \u0430 \u043d\u0435 \u043d\u0430\u0443\u0447\u043d\u044b\u0439, \u0442\u0430\u043a \u0447\u0442\u043e \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u043e\u0436\u0438\u0434\u0430\u0442\u044c \u043e\u0442 \u043d\u0435\u0433\u043e \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0439 \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u0438 \u0441\u0442\u043e\u043b\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u044f \u0433\u0430\u043b\u0430\u043a\u0442\u0438\u043a \u0438\u043b\u0438 \u0440\u0430\u0437\u043b\u0435\u0442\u0430 \u0432\u0435\u0449\u0435\u0441\u0442\u0432\u0430 \u043f\u0440\u0438 \u0411\u043e\u043b\u044c\u0448\u043e\u043c \u0432\u0437\u0440\u044b\u0432\u0435. \u041d\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0437\u0430\u043a\u043e\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432\u043f\u043e\u043b\u043d\u0435 \u043b\u044e\u0431\u043e\u043f\u044b\u0442\u043d\u043e.<\/p>\n<p>  \u0412\u0441\u0435 \u0437\u0430\u0434\u0443\u043c\u0430\u043d\u043d\u043e\u0435 \u0432 \u043e\u0434\u043d\u0443 \u0447\u0430\u0441\u0442\u044c \u043d\u0435 \u0432\u043b\u0435\u0437\u043b\u043e. \u0415\u0441\u043b\u0438 \u043e\u0446\u0435\u043d\u043a\u0438 \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b, \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043c\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u043d\u0435\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b.<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/500568\/\"> https:\/\/habr.com\/ru\/post\/500568\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/500568\/\">\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440.<\/p>\n<p>  \u041d\u0430 \u0434\u0430\u043d\u043d\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e \u043c\u0435\u043d\u044f \u0432\u0434\u043e\u0445\u043d\u043e\u0432\u0438\u043b\u0430 \u043d\u0435\u0434\u0430\u0432\u043d\u044f\u044f \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u044f <a href=\"https:\/\/habr.com\/ru\/post\/494546\/\">\u041c\u043e\u0434\u0435\u043b\u0438\u0440\u0443\u0435\u043c \u0412\u0441\u0435\u043b\u0435\u043d\u043d\u0443\u044e<\/a>, \u0433\u0434\u0435 \u0430\u0432\u0442\u043e\u0440 \u043f\u043e\u043a\u0430\u0437\u0430\u043b \u0432\u0435\u0441\u044c\u043c\u0430 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435 \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0440\u0430\u0437\u043d\u044b\u0445 \u043a\u043e\u0441\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u044f\u0432\u043b\u0435\u043d\u0438\u0439. \u041e\u0434\u043d\u0430\u043a\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0442\u0430\u043c \u043a\u043e\u0434 \u043d\u0435\u043f\u0440\u043e\u0441\u0442 \u0434\u043b\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445. \u042f \u043f\u043e\u043a\u0430\u0436\u0443 \u043a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u0432\u0438\u0436\u043a\u0430 <a href=\"https:\/\/box2d.org\/about\/\" rel=\"nofollow\">Box2D<\/a>, \u043d\u0430\u043f\u0438\u0441\u0430\u0432 \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u043a \u043a\u043e\u0434\u0430. <\/p>\n<p>  \u0420\u0438\u0441\u043a\u043d\u0443 \u043e\u0448\u0438\u0431\u0438\u0442\u044c\u0441\u044f, \u043d\u043e \u044d\u0442\u043e \u043f\u0435\u0440\u0432\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 Box2D \u0434\u043b\u044f Python \u043d\u0430 \u0425\u0430\u0431\u0440\u0435, \u0432\u043e\u0441\u043f\u043e\u043b\u043d\u0438\u043c \u044d\u0442\u043e\u0442 \u043f\u0440\u043e\u0431\u0435\u043b.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ja\/b7\/zy\/jab7zymczq9q1pvs5eea2xuzy7k.gif\"><\/p>\n<p>  \u0414\u043b\u044f \u0442\u0435\u0445 \u043a\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u043a\u0430\u043a \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u0434 \u043a\u0430\u0442\u043e\u043c.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-303073","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/303073","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=303073"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/303073\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=303073"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=303073"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=303073"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}