0

I tried using the code so I can run a simulation of an object hitting on the ground but it just says draw_polygon ([Vec2d(55.0, -4779353554820.233), Vec2d(55.0, -4779353554810.233), Vec2d(45.0, -4779353554810.233), Vec2d(45.0, -4779353554820.233)], 0.0, SpaceDebugColor(r=44.0, g=62.0, b=80.0, a=255.0), SpaceDebugColor(r=52.0, g=152.0, b=219.0, a=255.0))

import pymunk
#This comands sets the scene for our prosomition
space=pymunk.Space()
space.gravity = 0,-9.80665
body = pymunk.Body()
body.position= 50,100

#This comands create a box that attaches to the body and creates its settings
poly = pymunk.Poly.create_box(body) 
poly.mass = 10              
space.add(body, poly)

#Creates and prints the scene
print_options = pymunk.SpaceDebugDrawOptions()
speed=int(input("Speed:"))
while True:
    space.step(speed)
    space.debug_draw(print_options)

Im trying to run this on my visual studio but it's just saying: draw_polygon ([Vec2d(55.0, -4779353554820.233), Vec2d(55.0, -4779353554810.233), Vec2d(45.0, -4779353554810.233), Vec2d(45.0, -4779353554820.233)], 0.0, SpaceDebugColor(r=44.0, g=62.0, b=80.0, a=255.0), SpaceDebugColor(r=52.0, g=152.0, b=219.0, a=255.0))

Is there any package for an graphical enviroment ?

Jishan Shaikh
  • 1,572
  • 2
  • 13
  • 31
Malex
  • 1

1 Answers1

0

Yes, by default the debug drawing will just print out the result (its made in this way so that you can use it without installing anything else and even run it from the terminal). However, it also comes with a module for the two libraries pygame and pyglet that are documented here: http://www.pymunk.org/en/latest/pymunk.pygame_util.html and here http://www.pymunk.org/en/latest/pymunk.pyglet_util.html Both work in more or less the same way, just use their implementation of the SpaceDebugDrawOptions class instead of the default one.

An example of your code converted to pygame is below. Note that in your example you have speed (the input to space.step) set to an integer. However, when displaying its too big step size to see anything. I have adjusted it to speed/50 so if you enter 1 as speed, then it will progress in the speed matching pygame clock (clock.tick(50)). Without this the box moves too quickly out of the window:

import pygame
import pymunk
import pymunk.pygame_util

speed=int(input("Speed:"))

pygame.init()
screen = pygame.display.set_mode((600, 600))
clock = pygame.time.Clock()
running = True

### Physics stuff
space = pymunk.Space()
space.gravity = 0,-9.80665
body = pymunk.Body()
body.position= 50,100

#This comands create a box that attaches to the body and creates its settings
poly = pymunk.Poly.create_box(body) 
poly.mass = 10              
space.add(body, poly)

#Creates and prints the scene
print_options = pymunk.pygame_util.DrawOptions(screen)

while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        elif event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
            running = False

    ### Draw stuff
    screen.fill(pygame.Color("white"))
    space.step(float(speed) / 50)
    space.debug_draw(print_options)

    ### Flip screen
    pygame.display.flip()
    clock.tick(50)
    pygame.display.set_caption("fps: " + str(clock.get_fps()))
viblo
  • 4,159
  • 4
  • 20
  • 28
  • It still shows nothing – Malex Dec 06 '22 at 22:44
  • I updated my answer with a full example. I would also recommend you take a look at the pymunk tutorial at http://www.pymunk.org/en/latest/tutorials/SlideAndPinJoint.html if you feel the need. – viblo Dec 07 '22 at 09:49