Skip to content

Instantly share code, notes, and snippets.

@krclark

krclark/book.pde Secret

Created October 28, 2016 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krclark/7e8623c3e77b92459d90f6f8177f4dfb to your computer and use it in GitHub Desktop.
Save krclark/7e8623c3e77b92459d90f6f8177f4dfb to your computer and use it in GitHub Desktop.
import processing.pdf.*;
import java.util.Collections;
String poems[];
String lyrics[];
String line;
String newline;
String sub;
PFont headerfont;
PFont subfont;
String[] rappers = { "Tupac", "Lil Uzi Vert", "Lil Yachty", "21 Savage", "Schoolboy Q", "Ice Cube", "DMX", "Method Man", "Eminem", "Busta Rhymes",
"Gang Starr", "Immortal Technique", "A$AP Rocky", "Trick Daddy", "Jay-Z", "Snoop Dogg", "Dr Dre", "WuTang Clan", "Future",
"OG Maco", "OT Genasis", "The Notorious BIG", "50 Cent", "Nate Dogg", "Chief Keef", "Rae Sremmurd", "Fetty Wap", "Young Thug",
"Gucci Mane", "Rich Homie Quan", "Kodak Black", "Lil Wayne", "Rick Ross", "Birdman", "Tyler The Creator", "Nipsey Hussle", "YG",
"Tyga", "Soulja Boy", "Schoolboy Q", "WuTang Clan", "50 Cent", "Jay-Z", "Lil Uzi Vert", "Young Thug", "Chief Keef", "OG Maco", "YG", "Gucci Mane",
"21 Savage", "Ludacris", "Chingy", "Juicy J", "David Banner", "G-Unit", "Nelly",
"The Game", "Chamillionaire", "Slim Thug", "Young Buck", "Bun B", "Big Sean", "Ace Hood", "Plies", "T-Pain",
"T.I.", "B.O.B." };
void setup() {
poems = loadStrings("50 most popular poem lines.txt");
lyrics = loadStrings("lyrics_"+rappers[10]+".txt");
size(400, 400, PDF, "finalbook.pdf");
newline="Something really long I can put on a page for some reason.";
sub="-Someone Irrelevant";
headerfont = createFont("LinLibertine_RI.ttf", 12);
subfont = createFont("LinLibertine_RI.ttf", 10);
}
void draw() {
String first = poems[int(random(0, poems.length))];
String[] ok = first.split("~");
//split at ~
int r = int(random(0, rappers.length));
String rapper = rappers[r];
String name[] = rapper.split(" ");
println(rapper);
lyrics = loadStrings("lyrics_"+rapper+".txt");
String[] poemwords = ok[0].split(" ");
String wordtofind = poemwords[poemwords.length -1];
first = "";
for (int p = 0; p < poemwords.length - 1; p++) {
first+=poemwords[p];
first+=" ";
}
println(wordtofind);
//if lyrics frameCount = "\n" choose a different line
int l = int(random(0,lyrics.length));
int matchindex = lyrics[l].indexOf(" "+wordtofind+" ");
String rest = lyrics[l];
String also = "";
for (int m = 0; m < lyrics.length; m++) {
if (lyrics[m].indexOf(" "+wordtofind+" ") != -1) {
matchindex = lyrics[m].indexOf(" "+wordtofind+" ");
l = m;
rest = lyrics[m].substring(matchindex);
if (l+1 != lyrics.length && lyrics[l+1].indexOf("...") == -1 && lyrics[l+1].indexOf(")") == -1) also = " " + lyrics[l+1];
break;
}
}
while(matchindex == -1) {
r = (r+1)%rappers.length;
rapper = rappers[r];
name = rapper.split(" ");
lyrics = loadStrings("lyrics_"+rapper+".txt");
//Collections.shuffle(lyrics);
for (int m = 0; m < lyrics.length; m++) {
if (lyrics[m].indexOf(" "+wordtofind+" ") != -1) {
matchindex = lyrics[m].indexOf(" "+wordtofind+" ");
l = m;
rest = lyrics[m].substring(matchindex);
if (l+1 != lyrics.length && lyrics[l+1].indexOf("...") == -1 && lyrics[l+1].indexOf(")") == -1) also = " " + lyrics[l+1];
break;
}
}
}
if (l+1 != lyrics.length && lyrics[l+1].indexOf("...") == -1 && lyrics[l+1].indexOf(")") == -1) also = " " + lyrics[l+1];
newline = first + " " + rest.substring(1)+also;
// Draw something good here
textFont(headerfont);
fill(0);
textAlign(CENTER, CENTER);
text(newline, 50, 0, 350, 400);
textFont(subfont);
text("- "+name[0]+" "+ok[1], 200, 250);
PGraphicsPDF pdf = (PGraphicsPDF) g; // Get the renderer
// When finished drawing, quit and save the file
if (frameCount == 70) {
println("Success");
exit();
} else {
pdf.nextPage(); // Tell it to go to the next page
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment