2007-09-14 18:35

New library: ChipScene

This is the real outcome of my PyWeek failure: a neat library.

Take Chipmunk and Qt mash them up, and what do you get?

A OpenGL-accelerated, multiplatform, easy-to-use playground!

But watch the silly video that shows no interesting features instead:

You can't see it but there are 29 balloons, numbered, that bounce around happily.

Performance in the video sucks because I had to disable OpenGL in order to capture it correctly (and video recording kills my notebook,anyway). That demo normally runs in 3 seconds, not 57.

Here's the non-boilerplate code for that demo:

def fillWorld(scene):
  items=[]
  for x in range(1, 29):
      b=cs.CPBodyItem(bpos=[0+13*random.randint(0,25), -50-30*random.randint(0,10)],m=10)
      s=cs.CPCircleShapeItem(10, b, e=.5, offset=[0, 0])
      t=QtGui.QGraphicsSimpleTextItem(str(x), s)
      t.setPos(-5, -5)
      items.append(b)
  items.append(cs.CPSegmentShapeItem([0, 50], [500, 450], 1, None, e=.7))
  items.append(cs.CPSegmentShapeItem([0, 450], [500, 50], 1, None, e=.7))

  for i in items:
      scene.addItem(i)

Neat, isn't it?

You can get it at the ChipScene google code project including, of course, the source.

Comments

Comments powered by Disqus

Contents © 2000-2018 Roberto Alsina