My blog has been moved to ariya.ofilabs.com.
Showing posts with label s60. Show all posts
Showing posts with label s60. Show all posts

Saturday, March 20, 2010

morphing clock

As I promised before, here is a fresh X2 example. Those who attended Bossa Conference 10 and followed my talk are lucky to have seen it for the first time there. In fact, this example is ridiculously simple that I am not surprised at all if somebody has done this ages ago.

Let's start with a screen capture, or two:

Basically the above shows an analog and digital clock running on my Nokia N900, hardly a shock. However, the fun part is when you switch the clock from analog to digital and vice versa. Check out this video, or watch directly on YouTube, courtesy of Signor Portale from Nokia/Qt, showing the morphing on Nokia 5800:

The trick is simple. Actually it's not even generic enough, meaning that you can't morph from an arbitrary path to another arbitrary path. However, for this clock use-case, the gross approximation is good enough. First, we need to convert the path into a polygon, which is done easily via QPainterPath::toFillPolygon() function. Then any line segment in the polygon longer than a certain tolerance is further split into smaller segments. As I claimed above, the result is not perfect, i.e. it does not approximate the original path into line segments with equal length. But hey, it is good enough for this animation purpose (unless your user has ueberhuman eyes).

The target path needs to be sliced into segments as well. Since we have only two types, circle (for the analog clock frame) and solid block (for the hour and minute hands), it is easier to special-case both. The secret is to have the same number of segments as the source path. The following figure shows the digit '7' and a circle, each splitted to 28 line segments. Small dots indicate the start and end points of those segments. The animation is now a matter of doing tweening, or linear interpolation, between each segment.

The flaw of this trick is when the source path contains holes inside it, e.g. for digits like 0, 4, 6, 8, and 9. Again, we are cheating here for the sake of keeping the code simple, so I leave the code as it is. Doing a more advanced, better handling for those cases is left as a motivational exercise for the perfectionist readers. Another bonus puzzle: find out why 503 ms is the morphing time (hint: find the same number in Qt source tree).

The code is in the X2 repository, check the sub-directory widget/morphingclock. You need Qt 4.5 or later. It is not long at all (surprise!), sloccount reports 191 lines of code. A morphing-clock plasmoid is also underway, just be patient.

For the sake of completeness, let me mentioned Dali Clock (even in Canvas and JavaScript version) from the famous Jamie Zawinski (jwz). It is similar, however Dali Clock just morphs the digits of the digital clock.

Also, if you just prefer a normal (but old-fashioned!) digital clock with the flipping effect, check the digiflip example I did back then. You already have it if you install Qt 4.6 for Symbian.

Last but not least, I'd like to mention my "special thanks to Delta Airlines for such a long (but safe) flight to Brazil so I had the chance to write this example while I was bored", but then I was told by the Trolls that this kind of intro line can't be funny anymore.

Wednesday, September 23, 2009

frozen in the headlights (have I made the final sacrifice?)

This slick stuff is mostly educational (for the lazy, see the 30-second YouTube video courtesy of Alessandro). With all the accelerated graphics (with those alphabet soups) these days, who on earth uses ray casting for real-world apps? Nevertheless, since I still keep the piece of code (read: a function, literally) I wrote ages ago, why not giving it a try again?

Testing it on Nokia E71 (powered by ARM 369 MHz processor), I am content to get a consistent 25 fps at QVGA resolution (and the code is still portable!). I reckon I need to resort to platform-specific, e.g. Anti Tearing API for S60, if I want to push the frame rate further.

For the code and the explanation, head to the S60 ray casting demo. You would need the Qt 4.5 Tower release to build it for your favorite phone. Also, you need a four-way controller as I haven't bothered to let it run on a touch device.

Final (friendly) reminder: use sloccount and check yourself how long this example is. Why? Because usually people think I try to trick them when I reveal the size of the source code :)

Tuesday, August 11, 2009

(again) the map of my world gets smaller as I sit here

I always wanted to help Marble, but I am guilty because until now I can't afford any time to play with it. All these years, I used to compile bleeding-edge Marble from time and time, use it, and basically that is it. Although since a long time ago I promised Torsten that I was willing to help Marble, actually only right after Gran Canaria Desktop Summit finally I devoted some time to study its code. The three of us, Torsten, Andrew and I also had a short but fascinating discussion during the summit.

Now, I still don't manage to contribute anything to Marble yet, but I already have something in my pipeline. You will likely hear from me in the coming weeks, so stay tuned.

Since I reckon I enter the wonderful territory of mapping world, I thought, well, let's familiarize myself a bit with the technology. I took a look at the interesting experimental Google Maps API v3 (which BTW does not require an API key). Using QtWebKit, I wrote a simple 300-lines example that shows a magnifying glass over the map (see the screencast). Of course, the area under is the zoomed version of the map.

Since I am flirting with Qt for S60 these days, I thought about bringing that example to the phone. However, instead of relying on Google Maps, I decided to leave the dark side and jumped to use OpenStreetMap instead. The result is effectively an example of how to render the tiles from OpenStreetMap using Qt, which also runs on S60. It does even have the night-mode feature.

Video, you asked? Thanks to Alessandro, here is the 52-second videocast that demonstrates it (or watch on YouTube), running on Nokia 5800:

Tuesday, July 28, 2009

like a startling sign that fate had finally found me

What follows is a list of three Qt examples, designed with Qt/S60 in mind, but works fine on the desktop as well. Hopefully this will attract^Wprovoke more people to create, write, port apps to S60, especially since the Tower release makes our life much easier already.

For each example, the picture shows how it does look like both on an actual phone and on the desktop. The code is available from the usual Graphics Dojo repository. All of them runs on the desktop, too (of course). Afterall, they are just normal Qt/C++ programs. Thanks to my fellow Troll, dboddie, some of them are already available (or being converted as we speak) to PyQt, for all the Python fans out there. Also, screenshots are so prehistoric and we are the YouTube generation, so another fellow Troll, aportale, agreed to spend few minutes of his precious lifetime to play the Producer, Cameraman, Propman, Editor roles (all at the same time) and publish the Director's Cut versions of all videocasts mentioned here. Long live the Trolls!

Without further ado, here they are.

The first is the easiest one: flipping digital clock, where the digits flip as they change. There are probably tons of implementations out there (do we have one for KDE 4?), but if you are ever so curious to find out how useful QTransform could be, the check it out. For the lazy, watch the 23-second YouTube video.

Next is yet-another-weather tool. This time I relied on the unoffical Google Weather API. Nothing too fancy here, just a bit of SVG and Graphics View here and there, along with a bit of animation. The lazy side of you can go straight to stare at the 34-second demonstration videocast.

The last one is (just the next logical step to the second one): flight tracking tool. Based on flightview.com, the video can be checked on YouTube, too. It looks a bit ugly and it's also pretty limited, but hey, dogfooding your own app on your phone is also not bad.

Now, who's next?

Monday, June 29, 2009

ivory tower? I'd pick one of the anomalies of water

The Qt/S60 team continues to make some progresses. After Pyramid, Temple, and Garden, finally Tower came out of its cage. For a quick intro of what is inside Tower, check out the video. In particular, QtWebKit is included in this prerelease (yay!), thanks to the hard work of Simon, Norbert, Laszlo, Janne, Kristian, and other great hackers. My little contribution improves from only the basic engine behind the infamous Fluid Launcher (remember PictureFlow?) to a tech-demo QtWebKit-based web browser (created quickly in 1.5 days, cause I needed to rush to LinuxTag) dubbed Anomaly (Mobile). Once I am free again (now we're busy preparing for Akademy), I will put some more efforts to add more polishes to Anomaly Mobile. Imagine having visual bookmarks, flick support, Google suggest, optimized disk cache, double-tap-to-zoom, of course also smooth zooming in and out, snap scrolling, perhaps even night mode for your Nokia 5800, Nokia N97, and other Nokia touch devices, all implemented with Qt? /me just drools :-)