PDA

View Full Version : Conway's life visualization



qutron
30th December 2010, 13:12
I'm writing simple Conway's life using qt and MVC design pattern.

My program consists of 3 classes: lifeModel, Controller and Window. Window class visualizes every generation of cells (it's 2d matrix, as it's generally known). So I'm looking for the best way to implement this class.

For example, I picked QSpinBox to set matrix size, QPushButton to start generation, QGraphicsView to display matrix and QLayout to place elements on main QWidget.

Is QGraphicsView optimal for this case? Are there any better solutions?

high_flyer
30th December 2010, 13:51
Is QGraphicsView optimal for this case?
Well, it depends what is 'optimal' in your case...
QGraphicsView is not pixel based, which allows you to work on logical coordinates, and resize the view to any size you like, with out worrying about sizes and pixels - and their real position during paint time.
So in that sense you probably are better off with QGraphicsView.
But there might be other considerations that might counter that, which I don't see at the moment.

SixDegrees
30th December 2010, 16:13
It will depend on how you intend to display your matrix. If you use thousands of individual QGraphicsItems, you will run into trouble pretty quickly, as the view calls each individual paint() method; you'll probably start noticing slowdowns with several hundred items on display.

On the other hand, if you have a single QGraphicsItem that paints all of the matrix cells, painting will be much more efficient. You could similarly paint the view's background to achieve the same effect.

Side note: I read the original Mathematical Games column where Life was introduced to the public at large back in the early 70s. I spent a shameful amount of time working simple configurations by hand, with a pencil and graph paper. Much later, my first foray into assembly language was a Life program written for the Commodore 64; this was followed a few years later with a progarm on the Amiga that made use of the specialized graphics hardware to turn the blitter chip into a half-adder for a pretty astonishing (at the time) speedup.

I would imagine that today's machines would handle high resolution at very high speeds, even when wrapped in several abstraction layers. Have fun.