This is an attempt to merge Blenders Dynamic Paint feature with cellular automata. It started as a python script but then became even more of an educational experience when I realized python wasn’t going to be fast enough to run conway’s life on a 64x grid, let alone a 4Kx one, which was my initial goal. These ended up being 512x grids. I could have gone bigger but I’m using a little netbook for all this so I didn’t go nuts.
After figuring out that python wasn’t going to be fast enough I set out to make a c++ version, not in Blender, just in c++. Long story short it’s an atrocity of loops inside a main function. I didn’t even bother to pass any arguments, just recompiled every time I changed paths. Anyway it ended up being lots faster than the py scripts and I finally had an excuse to write a function I knew very well in a language I’ve been intimidated by for some time (and still very much am).
The c++ code uses the ImageMagick++ library, which made things much easier, but you’ll have to get this lib if you want to compile and use this. Hopefully this whole process has prepared me to get on porting the lighting generator to c++, which really needs to happen if if it’s ever going to be more than a gimmick.
So anyway, here’s the c++ code and here’s the Blender python script that I abandoned in favor of doing it in c++. For the record- this is bad, bad code. Very bad. Also here’s the command line to compile with g++ and imageMagick++, since that took awhile to get past.
user@pc:~$ g++ `Magick++-config –cxxflags –cppflags` conway.cpp -o conway `Magick++-config –ldflags –libs`
Here’s the process for using this to dynamic paint with conways life.
1) dynamically paint a canvas with a brush. This will paint ‘live’ cells onto the canvas
Turn on ‘dissolve’ and set to dissolve in 1-3 frames. Otherwise these become ‘immortal’ cells, which makes for a weird simulation.
I used red channel only for these demos.
2) compile and run the c++ code.
This will run the simulation on the dynamic paint cache images. It runs the simulation from the initial frame, but always includes the red cells from the next dynamic paint frame so they will be used in the next simulation step.
3) use this simulation output as a map in place of the dynamic paint output.
Sounds easy, and it kind of is, and kind of isn’t.
So if you want to do this yourself- if you know c++ it should be easy. If you don’t it will be very hard. If you’re just learning c++ it may be worthwile to try.
Not sure where I’m going with all this, as usual it was just something to do. Hope you dig it.
[…] Setup and more information here. // Be Sociable, Share! Tweet […]
the link for download conway_cpp_py.zip doesn’t works, it calls this page again 🙁
Fixed, sorry about that.
Hey Patrick, the sound isnt working in the game for me after the cube dies, I have no idea why. Here is my sciprts:ObstacleScript.py:import bgedef main(): cont = bge.logic.getCurrentController() obstacle = cont.owner keyboard = bge.logic.keyboard scene = bge.logic.getCurrentScene() if hp’ not in obstacle: start(obstacle) ######## obstacle.color = (1, obstacle[‘hp’], obstacle[‘hp’], 1) if obstacle[‘hp’] <= 0: die(obstacle, scene)def start(obstacle): obstacle['hp'] = 1.0def die(obstacle, scene): explosion = scene.addObject("ExplosionSound", obstacle.name, 60) explosion.actuators["Sound"].startSound() obstacle.endObject()main()BulletScript.py:import bgedef main(): cont = bge.logic.getCurrentController() bullet = cont.owner keyboard = bge.logic.keyboard scene = bge.logic.getCurrentScene() touch = cont.sensors["Touch"] hit = touch.positive damage = 0.1 if 'active' not in bullet: start(bullet) if hit and bullet['active'] == True: bullet['active'] = False bullet.color = (1,1,1,1) touch.hitObject['hp'] -= damagedef start(bullet): bullet['active'] = Truemain()PlayerScript.py:import bgedef main(): cont = bge.logic.getCurrentController() player = cont.owner keyboard = bge.logic.keyboard scene = bge.logic.getCurrentScene() movSpeed = 0.15 rotSpeed = 0.1 BulletSpeed = 1000 if bge.logic.KX_INPUT_ACTIVE == keyboard.events[bge.events.UPARROWKEY]: player.applyMovement((0, movSpeed, 0), True) if bge.logic.KX_INPUT_ACTIVE == keyboard.events[bge.events.DOWNARROWKEY]: player.applyMovement((0, -movSpeed, 0), True) if bge.logic.KX_INPUT_ACTIVE == keyboard.events[bge.events.RIGHTARROWKEY]: player.applyRotation((0, 0, rotSpeed), True) if bge.logic.KX_INPUT_ACTIVE == keyboard.events[bge.events.LEFTARROWKEY]: player.applyRotation((0, 0, -rotSpeed), True) if bge.logic.KX_INPUT_JUST_ACTIVATED == keyboard.events[bge.events.LEFTCTRLKEY]: bullet = scene.addObject("Bullet", "BulletSpawn", 150) bullet.applyForce((0, BulletSpeed, 250), True) bullet.color = (1, 0, 0, 1) player.color = (2, 1, 0, 0)main()
Really found your tutorial hepufll, far more than others that i have seen so far.You use simple models which can be made quickly and easily and are ideal placeholders for more advanced models which could be made later, i love that you show sources of information, how to find things, use of console / terminal, showing mistakes and working through them, this is what i need more than anything is to be shown how to actually make a gamePersonally i am trying to make an rts which i realise is a alot to take on for a total newb but cant get into things that im not interested in, i tried some tutorials for writing script but they were mostly hello world or writing script for boring websites or calculators etc, yawn, this is the sort of style i can really get into, just need more depth Looking forward to more of your tuts regardless of content as i very much like your style but if you could do a walkthrough for the most common features of rts style game that would make my life alot easier and give me a good basis to work on / practice with on my own.Thanks for your time and knowledge, much appreciatedGeoff