Java can be a fun language to play with. The
platform independence makes it a very inviting language. It is however, rather
slow compared to other languages. For that reason, I do not use it extensively.
Nonetheless, I have written a few applets with it, so I include them here.
|
This is my Java version of the
Mandelbrot set. You can zoom in on it by selecting a rectangular region with your mouse. It won't
show you any sort of indication that it is selecting that region, but it is. Just
click and drag as if you were drawing a diagonal line across the region you want to
zoom in on.
Run this applet
Given the amount of calculation that needs to be done, this will run at a
relatively slow pace. This applet used to be accompanied by a warning that a fast
machine is required. Fortunately, due to the increasing computational power of
today's technology, it's not slow enough to worry about. You may notice that
it does slow down as you zoom in. This is because, as you magnify the detailed
areas, the necessary amount of processing increases.
|
|
This applet demonstrates a neat (albeit simple) algorithm that I came up with
once when trying to simulate a chain. If you drag your mouse pointer around
within the applet, a series of balls drags along begind it, forming a string.
It behaves much like one would expect if they dragged a real string around with
their finger.
Run this applet
The algorithm behind it is actually a very simple one. It works by taking a
series of points which are connected to form the string. Each point in the
string needs to be a particular distance from the preceeding one. When you drag the
mouse, the first point moves with it. Because of this, it's neighbour follows along
and is in turn followed by it's next neighbour and so on down the chain.
In order for them to follow along, a vector is formed between the leading point
and the following one. That vector is then divided by it's length, forming a unit
vector. The unit vector is then multiplied by the required distance between those
two points, and added to the leading one. This gives us the new location of the
following point. That process is then repeated all the way through the series.
|
|
This applet is a variation on the previously mentioned worm algorithm. A series
of points trails along behind a leading one. In this case, the leading one moves
automatically, instead of following the mouse. Also, instead of drawing a series
of line segments, it draws a series of filled circles with the colours changing - making
it look more like a comet than a worm.
Run this applet
|
Copyright © 2009, Jacob A. Ewing