Time for another fresh example for the Graphics Dojo. This time I present a small tool that does nothing but showing the famous HSV cylinder. To give some realism, subtle blurred reflection is also added but can be easily disabled. Manual full-scene anti-aliasing is provided by the usual multisampling approach. Everything is done using pure QImage per-pixel manipulation along with some tricks, no OpenGL (or even its GLSL) is involved.
For the code, check it out using:
svn checkout svn://labs.trolltech.com/svn/graphics/dojo/hsvpie
Note that the tool is not optimized for speed (evidenced by lots of setPixel() calls) so there is definitely room for improvement. Some possible further enhancements left as exercises for the readers are interactivity (mouse dragging to change e.g. the depth of the pie) and threaded rendering (so that the application remains responsive, just adapt the Mandelbrot example).
Have some dojo-fun!
5 Responses to “Let there be color”
You may be interested in this one. Fabian Jakobs has ported the whole thing to JavaScript using the Canvas element.
@Sebastian Werner: the HTML Canvas version looks really cool!
Thanks
Take a look at the JavaScript code. You will be surprised how similar it is to your C++ version.
Hm, I wonder why in line 211 of hsvpie.cpp we have:
class QImage createHsvPie(int radius, int depth, qreal ratio, qreal limit, qreal init)
{
…
}
instead of
QImage createHsvPie(int radius, int depth, qreal ratio, qreal limit, qreal init)
{
…
}
what is the keyword class is doing there and why does it compile without any errors?
The “class”-keyword in this context is used for in-place forward-declarations, but doesn’t quite make sense because we’re not using pointers here.
You can return previously unknown classes in two ways. The first is the usual forward-declaration:
class Return;
Return *returnSomething();
The other way is the in-place forward-declaration:
class Return *returnSomething();
By prefixing the “class”, Return does not need to be declared in this scope. It only needs to be declared when dereferencing the resulting pointer later.
When not using pointers or references, you can still use the “class”-prefix on return types and parameter types, but the class needs to be fully declared at this point.
