I want to simplify #pymunk + #py5 use for my students but I struggle with finding good strategies… Pymunk has two types of (linked) objects for each simulated object: body and shape. For complex objects (like concave shapes) you can use more than one convex shape linked to the same body. In these cases I usually want to have an extra shape to draw and hide the triangulation.
I don't want to keep extra data structures to track the simulation objects to draw. I tried both extending and monkey patching either body or shape objects to be "drawable" so I can just iterate the native pymunk structures and ask stuff to draw themselves (would be nice, huh?), but there is always some snag. If I extend shape classes, I stumble on the complex objects with many shapes drawn with divisions. If I extend the Body class, the problem is static objects have shapes but share a virtual constant body, more of a flag, so I can't add anything to it, so back to keeping track of a separate list of static shapes… Then performance & serialization issues, I want to be able to easily pickle simulations, but if I add Py5Shape objects to the extended/modified classes they become unpickable...
I have bigger fishes to fry right now (the paralyzing PhD) but this is something I would like to pair with someone more experienced to work on.

so... maybe I should try a new fresh approach. I gave up avoiding adding a new data structure and created a drawing_dict to iterate and draw. At this point it contains a reference to a drawing function and the attributes to use... it should give me enough flexibility. I'm using shapes as keys,
I have to think about the case of the complex body... the body should be the key in that case. But then, removing stuff will be harder.

https://github.com/villares/sketch-a-day/blob/main/2025/sketch_2025_04_27/sketch_2025_04_27.py

sketch-a-day/2025/sketch_2025_04_27/sketch_2025_04_27.py at main · villares/sketch-a-day

One visual idea a day. Contribute to villares/sketch-a-day development by creating an account on GitHub.

GitHub
Alexandre B A Villares (@[email protected])

Attached: 1 image Code at: https://github.com/villares/sketch-a-day/tree/main/2025/sketch_2025_04_27 More sketch-a-day: https://abav.lugaralgum.com/sketch-a-day If you like this, support my work: https://www.paypal.com/donate/?hosted_button_id=5B4MZ78C9J724 https://liberapay.com/Villares https://wise.com/pay/me/alexandrev562 #pymunk #Processing #Python #py5 #CreativeCoding

Python News