Nice question. Building a word cloud from scratch may be a big project. Here are a few ideas that may be useful. To keep things really simple, maybe start with a list of only 3 to 5 words and a list of how many times each is used. This will be handy as proof of concept. At first make a word tower, with the most frequently used words on the bottom. For each word in the list, apply ImageCrop
to the Graphics
. Students can then use ImageDimensions
to find the size of each word. They may want to scale these images to the most common word has the most greatest area, rather than just the the biggest font. Maybe you will want to use the same font size for all words, and ImageResize
to scale the images.
Individual words can be placed into a common graphics object at specific locations using Inset
. The MMA documentation contains some interesting applications. For instance, the students may want to inset the images, if they can get the sizes right, or they may want to inset the words, using Style
, and letting Inset
do the scaling. To get this work
Once the students have their word towers working, they can add more words. A long string can split into words using StringSplit
. Common articles (a, an, the) can be ignored using StringCases
. Word counts can be obtained using Tally
.
After the tower comes the cloud. One idea that may work is to generate random (x,y) points with -1<x<1 and -1<y<1. Then sort the points by distance from the origin. The biggest word goes closest to the origin, etc. To prevent overlap, when a word image is added to the graphics, all the remaining points must be pushed away, depending on the size of the word image. Points that are above the word image must be pushed up to make room for the image. Points below the image must be pushed down, etc. Students may come up with much better ways of ordering the images. Or, they may google it.
Attached is a notebook that contains some scratch work done as a proof of concept. It is nothing close to finished product.
Attachments: