wszystkie-strachy-pis/wordcram.pde

241 wiersze
6.0 KiB
Plaintext

/*
Wszystkie strachy pis
Wg listy marcina Mellera
ChunkFive Ex font from https://www.dafont.com/chunkfive-ex.font
*/
import processing.pdf.*;
import wordcram.*;
import java.awt.*;
WordCram wc;
Word[] names;
Word[] names2;
Shape imageShape;
ShapeBasedPlacer placer;
PImage image;
int frameColor = #505050;
int backColor = #AAAAAA;
int blackColor = #000000;
int redColor = #E40303;
int orangeColor = #FF8C00;
int yellowColor = #FFED00;
int greenColor = #008026;
int blueColor = #004DFF;
int violetColor = #750787;
void setup() {
colorMode(RGB);
size(1000, 1418, PDF, "./rainbow.pdf");
//size(1000, 1418);
background(backColor);
image = loadImage("./rainbow.png");
loadNames();
makeWordCram();
}
void loadNames() {
String[] nameData = loadStrings("./wrogowie.csv");
int len = nameData.length ;
names = new Word[len ];
for (int i = 0; i < len; i++) {
names[i] = parseName(nameData[i]);
}
nameData = loadStrings("./wrogowie2.csv");
len = nameData.length ;
names2 = new Word[len ];
for (int i = 0; i < len; i++) {
names2[i] = parseName(nameData[i]);
}
}
void makeWordCram() {
println("start");
imageShape = new ImageShaper().shape(image, redColor);
placer = new ShapeBasedPlacer(imageShape);
new WordCram(this)
.fromWords(names)
//.withFont(createFont("./MINYN___.TTF", 1))
//.withFont(createFont("./BebasNeue-Regular.ttf", 1))
.withFont(createFont("./Chunkfive Ex.ttf", 1))
.withPlacer(placer)
.withNudger(placer)
.withColor(redColor)
.angledAt(0)
.sizedByWeight(10,20)
.drawAll();
println("red done");
imageShape = new ImageShaper().shape(image, orangeColor);
placer = new ShapeBasedPlacer(imageShape);
new WordCram(this)
.fromWords(names)
//.withFont(createFont("./MINYN___.TTF", 1))
//.withFont(createFont("./BebasNeue-Regular.ttf", 1))
.withFont(createFont("./Chunkfive Ex.ttf", 1))
.withPlacer(placer)
.withNudger(placer)
.withColor(orangeColor)
.angledAt(0)
.sizedByWeight(10,20)
.drawAll();
println("orange done");
imageShape = new ImageShaper().shape(image, yellowColor);
placer = new ShapeBasedPlacer(imageShape);
new WordCram(this)
.fromWords(names)
//.withFont(createFont("./MINYN___.TTF", 1))
//.withFont(createFont("./BebasNeue-Regular.ttf", 1))
.withFont(createFont("./Chunkfive Ex.ttf", 1))
.withPlacer(placer)
.withNudger(placer)
.withColor(yellowColor)
.angledAt(0)
.sizedByWeight(10,20)
.drawAll();
println("yellow done");
imageShape = new ImageShaper().shape(image, greenColor);
placer = new ShapeBasedPlacer(imageShape);
new WordCram(this)
.fromWords(names)
//.withFont(createFont("./MINYN___.TTF", 1))
//.withFont(createFont("./BebasNeue-Regular.ttf", 1))
.withFont(createFont("./Chunkfive Ex.ttf", 1))
.withPlacer(placer)
.withNudger(placer)
.withColor(greenColor)
.angledAt(0)
.sizedByWeight(10,20)
.drawAll();
println("green done");
imageShape = new ImageShaper().shape(image, blueColor);
placer = new ShapeBasedPlacer(imageShape);
new WordCram(this)
.fromWords(names)
//.withFont(createFont("./MINYN___.TTF", 1))
//.withFont(createFont("./BebasNeue-Regular.ttf", 1))
.withFont(createFont("./Chunkfive Ex.ttf", 1))
.withPlacer(placer)
.withNudger(placer)
.withColor(blueColor)
.angledAt(0)
.sizedByWeight(10,20)
.drawAll();
println("blue done");
imageShape = new ImageShaper().shape(image, violetColor);
placer = new ShapeBasedPlacer(imageShape);
new WordCram(this)
.fromWords(names)
//.withFont(createFont("./MINYN___.TTF", 1))
//.withFont(createFont("./BebasNeue-Regular.ttf", 1))
.withFont(createFont("./Chunkfive Ex.ttf", 1))
.withPlacer(placer)
.withNudger(placer)
.withColor(violetColor)
.angledAt(0)
.sizedByWeight(10,20)
.drawAll();
println("violet done");
imageShape = new ImageShaper().shape(image, blackColor);
placer = new ShapeBasedPlacer(imageShape);
new WordCram(this)
.fromWords(names2)
//.withFont(createFont("./MINYN___.TTF", 1))
//.withFont(createFont("./BebasNeue-Regular.ttf", 1))
.withFont(createFont("./Chunkfive Ex.ttf", 1))
.withPlacer(placer)
.withNudger(placer)
.withColor(blackColor)
.angledAt(0)
.sizedByWeight(10,40)
.drawAll();
println("black done");
imageShape = new ImageShaper().shape(image, frameColor);
placer = new ShapeBasedPlacer(imageShape);
new WordCram(this)
.fromWords(names)
//.withFont(createFont("./MINYN___.TTF", 1))
//.withFont(createFont("./BebasNeue-Regular.ttf", 1))
.withFont(createFont("./Chunkfive Ex.ttf", 1))
.withPlacer(placer)
.withNudger(placer)
.withColor(frameColor)
.angledAt(0,PI/2)
.sizedByWeight(10,20)
.drawAll();
println("frame done");
println("Done! Open *.pdf to see the results.");
//exit();
}
//void draw() {
// if (wc.hasMore()) {
// wc.drawNext();
// }
// else {
// println("done");
// // report();
// noLoop();
// }
//}
//void mouseClicked() {
// background(255);
// makeWordCram();
// loop();
//}
void report() {
for (Word word : wc.getSkippedWords()) {
switch (word.wasSkippedBecause()) {
case SHAPE_WAS_TOO_SMALL:
println(word.word + " shape was too small");
break;
case WAS_OVER_MAX_NUMBER_OF_WORDS:
println(word.word + " was over max # of words");
break;
case NO_SPACE:
println(word.word + " no room to place it");
break;
}
}
}
// Each row looks like:
// Mary\t1.0\tf
// ...or:
// {name} {tab} {frequency} {tab} {'f' for females, 'm' for males}
Word parseName(String data) {
String[] parts = split(data, '\t');
String name = parts[0];
float frequency = float(parts[1]);
// boolean isFemale = "f".equals(parts[2]);
Word word = new Word(name, frequency);
// word.setColor(blackColor);
return word;
}