2013-03-11 15:56:43 +00:00
|
|
|
|
import processing.core.*;
|
|
|
|
|
import wordcram.WordCram;
|
|
|
|
|
|
|
|
|
|
import java.awt.*;
|
2013-03-11 17:16:46 +00:00
|
|
|
|
import java.awt.image.PackedColorModel;
|
2013-03-11 15:56:43 +00:00
|
|
|
|
import java.io.*;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
|
|
import wordcram.*;
|
|
|
|
|
import wordcram.text.TextSource;
|
|
|
|
|
|
|
|
|
|
public class Tree extends PApplet {
|
|
|
|
|
|
|
|
|
|
private WordCram cram;
|
|
|
|
|
private boolean draw = true;
|
|
|
|
|
|
|
|
|
|
public void setup(){
|
2013-03-11 16:23:55 +00:00
|
|
|
|
Configuration config = Configuration.getInstance();
|
|
|
|
|
size(config.getWidth(),config.getHeight());
|
2013-03-11 17:16:46 +00:00
|
|
|
|
background(ColorHelper.decode(config.getBackgroundColor()));
|
2013-03-11 15:56:43 +00:00
|
|
|
|
|
2013-03-11 17:16:46 +00:00
|
|
|
|
ShapeBasedPlacer placer = ShapeBasedPlacer.fromFile(config.getShapeFile(), Color.black);
|
|
|
|
|
InputWords input = new InputWords(config.getInputFile());
|
2013-03-13 12:34:56 +00:00
|
|
|
|
Word[] words = input.getWords();
|
2013-03-11 17:16:46 +00:00
|
|
|
|
TreeColorer colorer = new TreeColorer(config.getColors());
|
2013-03-13 12:34:56 +00:00
|
|
|
|
WordSizer sizer = new WordSizer(config.getMinSize(), config.getMaxSize(), words);
|
2013-03-11 15:56:43 +00:00
|
|
|
|
|
|
|
|
|
cram = new WordCram(this)
|
2013-03-13 12:34:56 +00:00
|
|
|
|
.fromWords(words)
|
2013-03-11 17:16:46 +00:00
|
|
|
|
.withColorer(colorer)
|
2013-03-11 15:56:43 +00:00
|
|
|
|
.withPlacer(placer)
|
|
|
|
|
.withNudger(placer)
|
2013-03-13 12:34:56 +00:00
|
|
|
|
.withSizer(sizer);
|
2013-03-11 15:56:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-03-11 17:16:46 +00:00
|
|
|
|
|
|
|
|
|
|
2013-03-11 15:56:43 +00:00
|
|
|
|
public void draw() {
|
|
|
|
|
if(this.draw){
|
|
|
|
|
System.out.println("Start drawing tag cloud...");
|
|
|
|
|
cram.drawAll();
|
|
|
|
|
this.draw = false;
|
|
|
|
|
System.out.println("Finished drawing");
|
2013-03-11 17:16:46 +00:00
|
|
|
|
|
2013-03-11 16:23:55 +00:00
|
|
|
|
if(Configuration.getInstance().isDebug()){
|
2013-03-11 17:16:46 +00:00
|
|
|
|
printDebug();
|
2013-03-11 15:56:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-03-11 16:23:55 +00:00
|
|
|
|
save(Configuration.getInstance().getOutputFile());
|
2013-03-11 15:56:43 +00:00
|
|
|
|
exit();
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-03-11 17:16:46 +00:00
|
|
|
|
|
|
|
|
|
private void printDebug(){
|
|
|
|
|
//tell me what didn’t get drawn
|
|
|
|
|
int noSpace = 0;
|
|
|
|
|
int tooSmall = 0;
|
|
|
|
|
Word[] skippedWords = cram.getSkippedWords();
|
|
|
|
|
Word[] placedWords = cram.getWords();
|
|
|
|
|
for (Word skipped: skippedWords) {
|
|
|
|
|
if (skipped.wasSkippedBecause() == WordCram.NO_SPACE) {
|
|
|
|
|
noSpace++;
|
|
|
|
|
} else if (skipped.wasSkippedBecause() == WordCram.SHAPE_WAS_TOO_SMALL) {
|
|
|
|
|
tooSmall++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
System.out.println("Total placed Words: " + placedWords.length);
|
|
|
|
|
System.out.println("Total Skipped Words: " + skippedWords.length);
|
|
|
|
|
System.out.println("Skipped because no Space: " + noSpace);
|
|
|
|
|
System.out.println("Skipped because too small: " + tooSmall);
|
|
|
|
|
System.out.println("Finished");
|
|
|
|
|
}
|
2013-03-11 15:56:43 +00:00
|
|
|
|
}
|