Senin, 06 Mei 2013

A Little Variation of Good 'Ol J2ME Analog Clock

If you manage to get here by typing "analog clock j2me" or some sort in Google, chances are you have five or more tabs opened in your browser. It's just that an analog clock is pretty much a common thing around, with J2ME being no exception.
That's why this time I'll take a little spin on the analog clock and give it a way to make the thing run faster - or so I hope. In this post we will see how  - instead of the usual sine & cos function (or method, whatever) - to use arrays containing values that corresponds to certain sine & cos value of an angle in an analog clock program using J2ME.

Why Array?

If you have done this before using the sine & cos function, you may ask "Why reinvent the wheels?". You see, the wheels are really a staple of human creativity, as it allow us to move heavy things such as a carriage with much ease than before. That's why, to improve it's usefulness, many improvements are made to the wheels itself, such as using rubber instead of just wood or iron as the outer shell to maximize friction while maintaining the same reliability, and also...
Wait, why are we talking about wheels? Okay, so using sine & cos function, the same goal can be achieved (which is making a line spin, seriously) but if there's one thing we all know about mobile phone: it's slow. Okay, maybe not that slow, but it still run very slowly compared to PCs. So, instead of telling the phone to calculate sine & cos value of an angle every second (which is the same sixty values, anyway) we will give the phone a set of numbers, perfectly ordered from 0 to 360 degrees value of sine & cos, and then told the phone to "skim the catalog" instead. It will be much faster to simply look up a value from a table than calculating it all the way (even humans know it). A lecturer in my college told me about this - and even manage to give an assignment about it (guess which one it is, haha).