You might want to read how it works..
Words are chosen from the document to pop
into the active window. The choice alternates
between randomly selected words, and words that
often appear near words that are already in the
active window.
A kind of physics simulation is run in the active window.
Each word is "magnetically" attracted to all the words
within a specified distance from it.
Its left edge is attracted by the right edge of
other words, and its right edge is attracted by
the left edge of other words.
The strength of attraction increases between words
that were often near each other in the original document.
The strength of attraction drops off
with increasing distance between the words.
The simulation is run by iterating through pairs
of words in the active area. All candidate
word pairs are considered in succession. In order
to keep the animation running smoothly, display
is updated at regular time intervals, independently
of these continual readjustments in position.
In order to keep the words in a reasonable and pleasant
arrangement, flocking behavior is employed.
Words which are near each other generally have a slight
repulsion for each other
which is overcome only by the attraction of strongly
attracting side edges of words.
Also, all words are weakly attracted to the center
of the active area. This attraction to the center
tends to keep the entire
flock on-screen and prevents any word from drifting away.
Source code:
Poetry2.java
extends
Poetry.java
extends
BufferedApplet.java
How it works
The program examines an existing poem and looks for
the most frequent word-pairs.
For each word, the most N frequent preceding and
succeeding words are remembered.
Each of these neighbor words is
recorded, along with
how many times it occurs near
the word in question.