<commit_before>package example;

/*
Copyright 2010 <NAME>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import processing.core.PApplet;
import processing.core.PFont;
import wordcram.*;
import wordcram.text.*;

public class Main extends PApplet {
	
	WordCram wordcram;
	
	public void setup() {
		size(1200, 700); //(int)random(300, 800)); //1200, 675); //1600, 900);
		smooth();
		colorMode(HSB);
		initWordCram();
		//frameRate(1);
	}
	
	private PFont randomFont() {
		String[] fonts = PFont.list();
		return createFont(fonts[(int)random(fonts.length)], 1);
	}
	
	private void initWordCram() {
		background(55);
		
		wordcram = new WordCram(this)
					//.forWebPage("http://cnn.com")
					//.forWords(alphabet())
					//.forWords(loadWords())
					.forTextFile(textFilePath())
					//.forHtmlFile("webPage.html")
					//.forHtml("<html><b>Hippolyta Hall</b> and <i>The Kindly Ones</i> for Congress!</html>")
					//.forText("Cthulhu for President! Why choose the lesser of two evils?")
					.withFonts(randomFont())
					.withColors(color(0, 0, 175))
					.withAngler(Anglers.random());
	}
	
	public void draw() {
		//fill(55);
		//rect(0, 0, width, height);
		
		boolean allAtOnce = false;
		if (allAtOnce) {
			wordcram.drawAll();
			println("Done");
			noLoop();
		}
		else {
			int wordsPerFrame = 1;
			while (wordcram.hasMore() && wordsPerFrame-- > 0) {
				wordcram.drawNext();
			}
			if (!wordcram.hasMore()) {
				println("Done");
				noLoop();
			}
		}
	}
	
	public void mouseClicked() {
		initWordCram();
		loop();
	}
	
	public void keyPressed() {
		if (keyCode == ' ') {
			saveFrame("wordcram-##.png");
		}
	}
	
	private Word[] loadWords() {
		String[] text = loadStrings(textFilePath());
		return new TextSplitter().split(text);
	}
	
	private String textFilePath() {
		boolean linux = true;
		String projDir = linux ? "/home/dan/projects/" : "c:/dan/";
		String path = projDir + "eclipse/wordcram/trunk/ideExample/tao-te-ching.txt";
		return path;		
	}
	
	private Word[] alphabet() {
		Word[] w = new Word[26];
		for (int i = 0; i < w.length; i++) {
			w[i] = new Word(new String(new char[]{(char)(i+65)}), 26-i);
		}
		return w;
	}
}
<commit_msg>some new placer experiments, and other changes<commit_after>package example;

/*
 Copyright 2010 <NAME>

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */

import java.util.*;

import processing.core.*;
import wordcram.*;
import wordcram.text.*;

public class Main extends PApplet {
	
	WordCram wordcram;
	
	public void setup() {

		// destination.image.getGraphics():
		// P2D -> sun.awt.image.ToolkitImage, JAVA2D -> java.awt.image.BufferedImage.

		// parent.getGraphics():
		// P2D -> sun.java2d.SunGraphics2D, JAVA2D -> same thing.

		// P2D can't draw to destination.image.getGraphics(). Interesting.

		size(1300, 1000); // (int)random(300, 800)); //1200, 675); //1600, 900);
		smooth();
		colorMode(HSB);
		initWordCram();
		//frameRate(1);
	}
	
	private PFont randomFont() {
		String[] fonts = PFont.list();
		String noGoodFontNames = "Dingbats|Standard Symbols L";
		String blockFontNames = "OpenSymbol|Mallige Bold|Mallige Normal|Lohit Punjabi|Webdings";
		Set<String> noGoodFonts = new HashSet<String>(Arrays.asList((noGoodFontNames+"|"+blockFontNames).split("|")));
		String fontName;
		do {
			fontName = fonts[(int)random(fonts.length)];
		} while (fontName == null || noGoodFonts.contains(fontName));
		System.out.println(fontName);
		//return createFont(fontName, 1);
		return createFont("Molengo", 1);
	}
	
	private void initWordCram() {
		background(30);

		wordcram = new WordCram(this)
					//.forWebPage("http://cnn.com")
					//.forWords(alphabet())
					//.forWords(loadWords())
					.forTextFile(textFilePath())
					//.forHtmlFile("webPage.html")
					//.forHtml("<html><b>Hippolyta Hall</b> and <i>The Kindly Ones</i> for Congress!</html>")
					//.forText("Cthulhu for President! Why choose the lesser of two evils?")
					.withFonts(randomFont())
					.withColorer(Colorers.twoHuesRandomSats(this))
					.withAngler(Anglers.horiz())
					//.withPlacer(Placers.horizLine())
					.withPlacer(new WordPlacer() {
						private java.util.Random r = new java.util.Random();

						public PVector place(Word word, int wordIndex,
								int wordsCount, int wordImageWidth,
								int wordImageHeight, int fieldWidth, int fieldHeight) {

							float x = (float) (r.nextGaussian() * (1 - word.weight)) / 2;
							float y = (float) (r.nextGaussian() * (1 - word.weight)) / 2;
							//x *= Math.abs(x);
							y *= Math.abs(y);
							x = PApplet.map(x, -2, 2, 0, fieldWidth - wordImageWidth);
							y = PApplet.map(y, -2, 2, 0, fieldHeight - wordImageHeight);
							
							y = PApplet.map((float)wordIndex, wordsCount, 0, 0, fieldHeight - wordImageHeight);
							y = PApplet.map((float)word.weight, 0, 1, 0, fieldHeight - wordImageHeight);
							
							x = PApplet.map((float)word.weight, 1, 0, 0, fieldWidth - wordImageWidth);
							//y = (float)(r.nextGaussian() * (1-word.weight)) / 2;
							//y *= Math.abs(y);
							//y = PApplet.map(y, -2, 2, 0, fieldHeight - wordImageHeight);
							
							int firstLetter = word.word.toCharArray()[0];
							x = PApplet.map(firstLetter, 97, 122, 0, fieldWidth - wordImageWidth);
							
							return new PVector(x, y);
						}
					})
					//.withPlacer(Placers.horizBandAnchoredLeft())
					.withSizer(Sizers.byWeight(10, 100))
					.withNudger(new SpiralWordNudger());
	}
	
	public void draw() {
		//fill(55);
		//rect(0, 0, width, height);
		
		boolean allAtOnce = true;
		if (allAtOnce) {
			wordcram.drawAll();
			println("Done");
			noLoop();
		}
		else {
			int wordsPerFrame = 1;
			while (wordcram.hasMore() && wordsPerFrame-- > 0) {
				wordcram.drawNext();
			}
			if (!wordcram.hasMore()) {
				println("Done");
				noLoop();
			}
		}
	}
	
	public void mouseClicked() {
		initWordCram();
		loop();
	}
	
	public void keyPressed() {
		if (keyCode == ' ') {
			saveFrame("wordcram-##.png");
		}
	}
	
	private Word[] loadWords() {
		String[] text = loadStrings(textFilePath());
		return new TextSplitter().split(text);
	}
	
	private String textFilePath() {
		boolean linux = true;
		String projDir = linux ? "/home/dan/projects/" : "c:/dan/";
		String path = projDir + "eclipse/wordcram/trunk/ideExample/tao-te-ching.txt";
		return path;		
	}
	
	private Word[] alphabet() {
		Word[] w = new Word[26];
		for (int i = 0; i < w.length; i++) {
			w[i] = new Word(new String(new char[]{(char)(i+65)}), 26-i);
		}
		return w;
	}
}

{'fraction_non_alphanumeric': 0.14957153985977667, 'fraction_numerical': 0.01986497013762659, 'mean_word_length': 2.8323383084577114, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6618104', 'n_tokens_mistral': 3176, 'n_tokens_neox': 2567, 'n_words': 648}