Archive

Archive for August, 2009

Recent Reading

August 21st, 2009 Comments off

My fortnightly occasional summary of what I’ve been reading and listening to.

The Grail Quest Trilogy

The Grail Quest by Bernard Cornwell

Audiobook on my iPhone

Amazon link

This is a trilogy of historical novels, set during the Hundred Years War between England and France (mid 1300s), and centered on the exploits of Thomas of Hookton, an English archer. In those days, the English longbow, en masse, had the devastating impact on opposing armies that the machine gun did during World War I. Arrows from such bows, plied by men trained from youth to have the strength to draw them, could pierce even plate armor.

Cornwell has an excellent sense of period, and has clearly done his historical research thoroughly. There are several battles in the book which – if they were fiction – would seem to strain credibility: the Battle of Crécy, in which the English army in France under the command of Edward III, hugely outnumbered, desperate, out of supplies, and exhausted, nevertheless managed to wipe out a vast proportion of the French nobility and escape; the Battle of Durham, where again a greatly outnumbered English contingent destroyed the flower of Scottish arms and captured the King of Scotland; the Battle of La Roche-Darien where Duke Charles of Brittany thought he had a cunning plan to destroy the English archers, but was in fact defeated and captured. All of these are true stories, but Cornwell brings them vividly (and bloodily) to life; and it’s perfectly credible that his protagonist would be at each of these events, which happened within the span of a few years in the 1340s.

The character development of Thomas, his loves and friends, is all excellently handled, particularly the conflicts between Thomas and his one-time friend, the Scot Robbie Douglas in the last book.

And then there’s the plot device of the search for the Holy Grail. No Arthurian (or even Monty Pythonesque) romance here, but a belief that the relic exists among the powers of the Church, and a connection through Thomas’ family which holds out the tantalising thought that the Grail might really exist and be located. It’s this hope which drives the characters.

Really entertaining reading. And very well narrated by Sean Barrett.

Almost Perfect by W.E. Pete Peterson

E-book on my iPhone

Interesting history of the word processing software which for a time was the best-selling product in the field.

The book could have been subtitled “The Rise and Fall of Word Perfect”, I guess, for the product is now long gone, swept away by the ubiquitous Microsoft Word.

This e-book is a fascinating look at the early history of computing and word processing in particular. Since I am someone who cut their teeth on a dedicated Wang word processing system, and who has seen the introduction and rise of Microsoft’s products, it was particularly interesting to me. But it would be equally interesting, I think, to students of business dynamics and interpersonal relationships in business, as the company grows and grows and relationships get stressed. Peterson eventually gets shafted by his long-time partners, and a fair bit of his resentment and self-justification comes out in the book.

This is only available as an e-book these days as the original is long out of print (if it ever was in print, not sure).

Current Reading

I’m currently part-way through:

  • Team of Rivals by Doris Kearns Goodwin (Hardcover, my own library) – yes, I’m still reading this – it’s a long book, and I find it hard to find time to sit down with a physical volume these days.
  • Ruled Brittania by Harry Turtledove (Ebook)

iPhone, you Phone, we Phone

August 14th, 2009 Comments off

iPhone 3GS
Well, I finally did it.

After six months of loving my iPod Touch but carrying a separate mobile phone, I gave in and signed up for a fully-fledged iPhone when the 3GS model came out.

My justification was that I would only have to carry one device with me on my morning walks, or when I was driving. That’s my excuse, but what I was really drooling over were some of the exciting new capabilities that the iPhone has which are still missing from the iPod Touch.

Here we have an elegant, powerful, multi-functional pocket computer with some astonishing capabilities. It’s truly a ‘Swiss Army Knife’ of electronic devices.

Rehashing my earlier list of functions of the iPod Touch, now expanded by the addition of iPhone 3GS features:

I can (and do!) use it to:

* Store my contacts, calendar, notes, photos
* Get my email from several accounts
* Calculate
* Act as an an alarm clock and stop watch
* Keep track of my working time on various projects
* Listen to music – I have some 160 albums on it
* Listen to audiobooks as I walk or drive
* Play games
* Watch videos
* Read e-books
* Take photographs
* Find my way with maps, compass and GPS
* Store all of my passwords
* Check the weather
* Check the stock market
* Record sound
* Browse the Internet
* Look up train, tram and bus timetables (with real-time advice on arrival of trams)
* Find the nearest ATM
* Look up postcodes
* Identify planets, stars and constellations in the night sky
* “Fax” documents
* Remotely control my computers
* Improve my musical ear

Oh yes, nearly forgot:
* Make and receive phone calls
* Write and receive text messages

Others, with a different selection of ‘apps’ will have a different list. But I submit that such a list of capabilities is truly astonishing. It’s the kind of ‘magical machine’ that I could barely have dreamed of when I was young. Heck, I spent a long while saving up for a simple four-function calculator when I was in my first year at college!

If you are wondering how I do some of the things in the list above, here’s a short list of my favorite iPhone apps at the moment:

MotionX GPS
MotionX GPS
This is currently my very favorite app. It really leverages the power of the GPS, compass and accelerometer. I set off for my morning walk, start my audiobook playing, fire up this app and start walking. When I get back home, I stop and save the ‘track’. Now I know exactly how long I’ve walked for, how far, what my average speed was, what my maximum speed was, and the highest and lowest altitudes I’ve visited. My exact path is shown on the map, and I can even email it to myself or friends, complete with a Google Earth KMZ file. Brilliant and worth every cent (AU$3.99).

JotNot
JotNot
This is a clever application for those out on the road – essentially it turns your iPhone into a mobile scanner/fax. Take a photo of a document with your camera – even at an angle – and then an overlay appears with movable corners. Position the corners to match the corners of your document, and voilà ! JotNot processes the image, reshapes it to make it into a perfect rectangle, adjusts the sharpness and contrast, and you have something which looks like a pretty good scan. JotNot then lets you email the result as an image or as a PDF. Terrific for receipts, newspaper clippings, white-board workings, business cards…. I love it. (AU$5.99)

Pocket Universe
Pocket Universe
This really leverages all the features of the iPhone 3GS. It knows what time it is because of the clock; it knows where in the world you are because of the GPS chip; it knows which way you are facing because of the compass; it knows how much you are tilting it because of the accelerometer. Thus, you can hold it up to the night sky and it will show you essentially the same view – but with the constellation lines shown, and labels next to the brightest objects. Instant recognition of ‘what’s that star or planet’? It tracks the phase of the moon and all of the planets, and has a summary of ‘Tonight’s Sky’, with rising and setting times. Very clever stuff. (AU $3.99).

MetLink and Tram Tracker
TramTracker
These are specific to the Australian city where I live (Melbourne), but offer a really handy way to discover when the next public transport vehicle is leaving for your destination. Metlink has all the latest timetables (updating live) for train, tram and bus. You can set up your favorite stations/stops. Tram Tracker is even neater: it shows the actual time – not just the scheduled time – before the next tram arrives at your stop, working off the very same live electronic information available to the company running the trams. Both of these are free!

Adventures in WPF

August 5th, 2009 Comments off

I’m very new to Microsoft’s Windows Presentation Foundation (WPF), even though the technology has been out for a few years now (since .NET Framework and Visual Studio 2008). As with many new programming paradigms, I tend not to put in the hard yards in learning them until (1) they appear bedded down and stable and (2) I see a real use for them. The latter is usually the big decider – I can’t learn everything, particularly as my aging brain finds it harder and harder to cram in new stuff.

Anyway, I did do some work in WPF earlier this year, in building a digital signage system for the National Sports Museum. Basically a display of current world records, it needed to be attractive, have interesting transitions, and be very easy to update.

In years gone by I would certainly have built this kind of thing in Flash, possibly under the control of a C# shell program. But it seemed like a good opportunity to get my feet wet with WPF, and so I gave it a go. It was a struggle, but with the aid of a good textbook (Programming WPF by Chris Sells and Ian Griffiths) I managed to achieve a pretty good result, I think. By the way, I do find that when learning something new it’s far more helpful to have a good, hardcopy, text book by my side than any amount of electronic help.

So over the weekend I got the impulse to do some more with WPF, the trigger being some astronomy articles I was reading.

A long time ago I wrote a program called Gravitorium, still available as shareware (though hardly anyone ever buys it now). The purpose was to act as a simple simulator of gravitational interactions between arbitrary stars, planets, asterioids, etc. Build your own solar system and see what happens. Throw a black hole through the middle of our own solar system. That sort of thing.

The old version of Gravitorium

Now here’s the thing: Gravitorium was written nearly 10 years ago, in Visual Basic 6. Calculating all the interactions in such a system is very slow, and updating the display is even slower. Running on the kind of computers and graphics cards we had 10 years ago, it’s surprising that I was able to get any kind of reasonable result at all. Watching a simulation the motion of the Moon around the Earth, for example, was a bit like watching grass grow, unless you cranked down the accuracy of the simulation a fair bit.

So for some time I’ve been toying with revisiting the program, using modern programming techniques and a much faster computer platform. And I figured that WPF, which gives direct access to the graphics processor, would be just the shot to give a much speedier result.

Well, so far it hasn’t worked out like that. Now do bear in mind that in what follows I’m just going to be exposing my experimentation and learning processes to you. If you already thoroughly understand WPF, this article is not for you!

I can see that there are going to be major benefits from a WPF approach. For example, in the old Gravitorium I was doing some pretty dumb things to draw planets and orbits. Everything happened on a PictureBox control. To create the illusion of a moving object I first drew a colored circle and then on the next phase, ‘erased’ it by drawing a black rectangle over it. All the objects and all of orbital trails were just bitmapped onto a single layer. The orbit trails were just literally painted dots, and each time the display is rescaled, I had to keep track of the dots and repaint them.

In my new version, I’m playing with using a WPF Canvas object, and associating Ellipse, Label and Polyline objects with each body in the system. These get moved around as the calculation proceeds, and WPF takes care of redrawing the display. The Polyline object redraws the orbital trails (admittedly as a series of straight lines rather than curves, but the segments are so small they look smooth).

It’s kind of working, but I’m not there yet! Refreshing the display regularly is a bit of a struggle, which I don’t yet understand. In the old Windows Forms days, I would just repaint things in a loop, invalidating the picture box or doing an Application.DoEvents() call. You can’t do that in WPF, which seems odd. I found a couple of ways around this limitation. The one that works best so far is a ‘fake’ DoEvents() procedure which I found here. I modified it by adding the null object check, which avoids an exception on closing the application.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
using System.Threading;
using System.Windows.Threading;
//....
 
/// <summary>
/// Processes all messages currently in the message queue.
/// </summary>
/// <remarks>
/// This method can potentially cause code re-entrancy problem, so use it with great care.
/// </remarks>  
public static void DoEvents()
{
     if (Application.Current !=null)
    {
       Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, new ThreadStart(delegate { }));
     }
}

I do suspect that having to use a crutch like the above means that I don’t have my head around WPF as yet.

Anyway, the revisited application (which at present is only a proof of concept) is coming along:

Gravitorium WPF POC

This is working fast enough to be able to animate the labels along with the objects (the VB6 version has to pause to show labels) and still get a pretty swift animation. At an equivalent level of accuracy the VB6 version takes 95 seconds to complete an orbit of the Moon. The WPF one, even with the overhead of redrawing labels, only takes 25 seconds. That’s about a four-fold increase in speed, and the results look much nicer.

Anyway, this is a WPF Work in Progress, so I’ll return to it as I continue my learning process.

Categories: Programming Tags: ,
Performance Optimization WordPress Plugins by W3 EDGE