editing "TypeStar"
in
Programming Questions
•
1 year ago
hi there,
some days ago i found an amazing script called "typestar" ( http://scott.j38.net/work/interactive/typestar/)
it's like a karaoke machine that renders lyrics in realtime.
when a song has a lot of lyrics the animation gets quite slow and shaky. i want to cut the text off so that only the last ~100 syllables are shown. i've been searching the plugintowers.java for a while but couldnt find a line to add a cut-off.
someone has a clue?
plugintower.java:
import java.util.TreeMap;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Arrays;
import processing.core.*;
class pluginTower {
PApplet myPApplet;
Song mySong;
PFont myFont, myFontEm;
int targetWidth;
public PVector eye, target, nextEye, nextTarget;
public float aimFrame, nextAimFrame, aimRotation, nextAimRotation;
pluginTower (PApplet newPApplet, Song newSong, PFont newFont, PFont newFontEm, int newTargetWidth) {
try {
mySong = (Song)ObjectCloner.deepCopy(newSong);
}
catch(Exception e)
{
System.out.println("Exception in main = " + e);
}
myPApplet = newPApplet;
myFont = newFont;
myFontEm = newFontEm;
eye = new PVector();
target = new PVector();
aimFrame = 0;
aimRotation = 0;
nextEye = new PVector();
nextTarget = new PVector();
nextAimFrame = 0;
nextAimRotation = 0;
myPApplet.resetMatrix();
TreeMap songLines = mySong.getLines();
Iterator<Integer> lineItr = songLines.keySet().iterator();
myPApplet.textFont(myFont);
int lastRotationFactor = 0;
int rotationFactorCount = 0;
targetWidth = newTargetWidth;
int lineCounter = 1;
float lastLineHeight = 0;
float lastLineCount = 1;
while (lineItr.hasNext()) {
int curLineKey = lineItr.next();
Line curLine = (Line)songLines.get(curLineKey);
int lineRotate = 0;
// if (lineCounter % 3 == 1)
// lineRotate = 0;
// else if (lineCounter %3 == 2)
// lineRotate = 90;
// else if (lineCounter %3 == 0)
// lineRotate = -180;
lineCounter++;
// ------------------------------
// Set Line Transformation Matrix
// ------------------------------
PMatrix3D lineMatrix = new PMatrix3D();
lastLineHeight = 0;
float[] lineMatrixRaw = new float[16];
lineMatrix.get(lineMatrixRaw);
curLine.setMatrix(lineMatrixRaw);
int letterCount = curLine.getLetters().length();
int wordCount = myPApplet.splitTokens(curLine.getLetters()).length;
float lineCount;
if (wordCount <= 3)
lineCount = 1;
else if (wordCount > 3 && wordCount <= 7)
lineCount = 2;
else if (wordCount > 7 && wordCount <= 13)
lineCount = 3;
else
lineCount = 4;
int lineStep = myPApplet.ceil(wordCount / lineCount);
lastLineCount = lineCount;
//
// Determine Segment sizes
//
ArrayList segmentScales = new ArrayList();
for (int curSegment = 0; curSegment < lineCount; curSegment++) {
int fromIndex = curSegment * lineStep;
int toIndex = (curSegment * lineStep) + lineStep;
if (toIndex > myPApplet.splitTokens(curLine.getLetters()).length)
toIndex = myPApplet.splitTokens(curLine.getLetters()).length;
ArrayList segmentWords = new ArrayList(Arrays.asList(myPApplet.splitTokens(curLine.getLetters())).subList(fromIndex, toIndex ));
String segmentString = "";
Iterator<String> itr = segmentWords.iterator();
while (itr.hasNext()) {
segmentString = segmentString + " " +itr.next();
}
float segmentScale = targetWidth/myPApplet.textWidth(segmentString.trim());
//println(textWidth(segmentString.trim()) + " " + segmentScale + " " + segmentString);
segmentScales.add(segmentScale);
}
//println(wordCount + " " + lineCount + " " + lineStep + " " + curLine.getLetters());
TreeMap songWords = curLine.getWords();
Iterator<Integer> wordItr = songWords.keySet().iterator();
int wordCounter = 0;
int segmentCounter = 0;
float wordOffsetX = 0;
float wordOffsetY = 0;
float wordScale = 1;
float wordTotalX = 0;
float wordTotalY = 0;
boolean newSegment = true;
while (wordItr.hasNext()) {
int curWordKey = wordItr.next();
Word curWord = (Word)songWords.get(curWordKey);
//println(curWord.getLetters());
if (wordCounter % lineStep == 0) {
newSegment = true;
}
if (newSegment) {
if (segmentCounter < segmentScales.size()) {
float lastScale = 1;
float curScale = 1;
for (int curSegment = 0; curSegment <= segmentCounter; curSegment++) {
//println(lastScale + " " + 1/lastScale);
curScale = Float.valueOf(segmentScales.get(curSegment).toString()).floatValue() * (1/lastScale);
lastScale = Float.valueOf(segmentScales.get(curSegment).toString()).floatValue();
}
wordScale = curScale;
lastLineHeight += ((myPApplet.textAscent() * .95) * lastScale) + (targetWidth/100);
segmentCounter++;
}
}
else {
wordScale = 1;
}
if (wordCounter % lineStep == 0) {
wordOffsetX = wordOffsetX - wordTotalX;
wordTotalX = 0;
wordOffsetY = (float)((myPApplet.textAscent() * .95) * wordScale) + (targetWidth/50);
}
else {
wordOffsetY = 0;
}
//
// Set Word Transformation Matrix
//
PMatrix3D wordMatrix = new PMatrix3D();
wordMatrix.translate(wordOffsetX, wordOffsetY);
wordMatrix.scale(wordScale);
float[] wordMatrixRaw = new float[16];
wordMatrix.get(wordMatrixRaw);
curWord.setMatrix(wordMatrixRaw);
if (curWord.getLetters().charAt(0) == ' ' && newSegment)
curWord.setLetters(curWord.getLetters().substring(1));
wordOffsetX = myPApplet.textWidth(curWord.getLetters());
TreeMap songSyllables = curWord.getSyllables();
Iterator<Integer> syllableItr = songSyllables.keySet().iterator();
float syllableOffset = 0;
while (syllableItr.hasNext()) {
int curSyllableKey = syllableItr.next();
Syllable curSyllable = (Syllable)songSyllables.get(curSyllableKey);
//
// Set Word Transformation Matrix
//
PMatrix3D syllableMatrix = new PMatrix3D();
syllableMatrix.translate(syllableOffset, 0);
float[] syllableMatrixRaw = new float[16];
syllableMatrix.get(syllableMatrixRaw);
curSyllable.setMatrix(syllableMatrixRaw);
if (curSyllable.getLetters().charAt(0) == ' ' && newSegment)
curSyllable.setLetters(curSyllable.getLetters().substring(1));
syllableOffset = myPApplet.textWidth(curSyllable.getLetters());
wordTotalX += syllableOffset;
//curSyllable.setEndFrame(curSyllable.getStartFrame() + 600);
curWord.addSyllable(curSyllable);
}
//curWord.setEndFrame(curWord.getStartFrame() + 600);
curLine.addWord(curWord);
wordCounter++;
newSegment = false;
}
//curLine.setEndFrame(curLine.getStartFrame() + 600);
// Pick left or right rotation
int newRotationFactor;
if(myPApplet.round(myPApplet.random(2)) == 1) {
newRotationFactor = 1;
} else {
newRotationFactor = -1;
}
if (lastRotationFactor == newRotationFactor)
rotationFactorCount++;
if (rotationFactorCount > 1) {
newRotationFactor *= -1;
rotationFactorCount = 0;
}
curLine.setRotationFactor(newRotationFactor);
lastRotationFactor = newRotationFactor;
curLine.setHeight(lastLineHeight);
mySong.addLine(curLine);
}
}
void draw(int currentFrame, int textColor, PMatrix3D songMatrix, PMatrix3D lineMatrix, boolean stepWidth, boolean stepHeight, boolean dropShadow, int[] autoRotate, int[] syllableAnimation) {
float lastLineHeight = 0;
myPApplet.pushMatrix();
myPApplet.applyMatrix(songMatrix);
//myPApplet.translate(0,(float)(0 - currentFrame * 2));
TreeMap songLines = mySong.getLines();
Iterator<Integer> lineItr = songLines.keySet().iterator();
aimRotation = nextAimRotation = 0;
myPApplet.pushMatrix();
int lineCounter = 0;
while (lineItr.hasNext()) {
lineCounter++;
int curLineKey = lineItr.next();
Line curLine = (Line)songLines.get(curLineKey);
if (stepWidth) myPApplet.translate(targetWidth,0);
if (stepHeight) myPApplet.translate(0,lastLineHeight);
lastLineHeight = curLine.getHeight();
myPApplet.applyMatrix(lineMatrix);
PMatrix3D curLineMatrix = new PMatrix3D();
curLineMatrix.set(curLine.getMatrix());
//curLineMatrix.print();
myPApplet.applyMatrix(curLineMatrix);
int modFactor = ((lineCounter%2) == 0) ? -1 : 1;
if (autoRotate[0] == 1) myPApplet.rotateX(myPApplet.radians(90 * modFactor));
if (autoRotate[1] == 1) myPApplet.rotateY(myPApplet.radians(90 * curLine.getRotationFactor()));
if (autoRotate[2] == 1) myPApplet.rotateZ(myPApplet.radians(90 * curLine.getRotationFactor()));
if ((currentFrame < curLine.getStartFrame()) && lineCounter==1){
myPApplet.textFont(myFont,30);
myPApplet.text(mySong.artist + " - " + mySong.title,1,1);
}
if (curLine.getStartFrame() > currentFrame){
myPApplet.pushMatrix();
nextTarget.set(myPApplet.modelX(0,0,0),myPApplet.modelY(0,0,0),myPApplet.modelZ(0,0,0));
nextEye.set(myPApplet.modelX(0,0,500),myPApplet.modelY(0,0,500),myPApplet.modelZ(0,0,500));
nextAimFrame = curLine.getStartFrame();
myPApplet.popMatrix();
break;
}
myPApplet.pushMatrix();
target.set(myPApplet.modelX(0,0,0),myPApplet.modelY(0,0,0),myPApplet.modelZ(0,0,0));
eye.set(myPApplet.modelX(0,0,500),myPApplet.modelY(0,0,500),myPApplet.modelZ(0,0,500));
aimFrame = curLine.getStartFrame();
myPApplet.popMatrix();
TreeMap songWords = curLine.getWords();
Iterator<Integer> wordItr = songWords.keySet().iterator();
myPApplet.pushMatrix();
while (wordItr.hasNext()) {
int curWordKey = wordItr.next();
Word curWord = (Word)songWords.get(curWordKey);
if (curWord.getStartFrame() > currentFrame)
continue;
PMatrix3D curWordMatrix = new PMatrix3D();
curWordMatrix.set(curWord.getMatrix());
myPApplet.applyMatrix(curWordMatrix);
TreeMap songSyllables = curWord.getSyllables();
Iterator<Integer> syllableItr = songSyllables.keySet().iterator();
myPApplet.pushMatrix();
while (syllableItr.hasNext()) {
int curSyllableKey = syllableItr.next();
Syllable curSyllable = (Syllable)songSyllables.get(curSyllableKey);
if (curSyllable.getStartFrame() > currentFrame)
continue;
PMatrix3D curSyllableMatrix = new PMatrix3D();
curSyllableMatrix.set(curSyllable.getMatrix());
myPApplet.applyMatrix(curSyllableMatrix);
if (currentFrame - curSyllable.getStartFrame() < 8 ) {
float aniFactor = (currentFrame - curSyllable.getStartFrame()) / 8f;
if (syllableAnimation[0] == 1)
myPApplet.translate(0,0,myPApplet.round(256 - ( aniFactor* 256)));
if (syllableAnimation[1] == 1)
myPApplet.rotateX(myPApplet.radians(myPApplet.round(85 - ( aniFactor* 85))));
if (syllableAnimation[2] == 1)
myPApplet.scale(aniFactor);
}
//myPApplet.println( curSyllable.getLetters() + " " + currentFrame + " " + (curSyllable.getStartFrame()));
if (curSyllable.getEndFrame() - curSyllable.getStartFrame() < 5)
myPApplet.textFont(myFont);
else
myPApplet.textFont(myFontEm);
if (dropShadow){
myPApplet.shininess(0);
myPApplet.fill(0,0,0,(float)(curLine.getStartFrame() * 1.0 / currentFrame) * 128) ;
myPApplet.pushMatrix();
myPApplet.translate(targetWidth/80,targetWidth/80,-targetWidth/80);
myPApplet.text(curSyllable.getLetters(), 0, 0);
myPApplet.popMatrix();
}
myPApplet.shininess(100);
myPApplet.fill(textColor , (float)(curLine.getStartFrame() * 1.0 / currentFrame) * 255) ;
myPApplet.text(curSyllable.getLetters(), 0, 0);
}
myPApplet.popMatrix();
}
if (!lineItr.hasNext()) {
myPApplet.pushMatrix();
if (stepWidth) myPApplet.translate(targetWidth,0);
if (stepHeight) myPApplet.translate(0,curLine.getHeight());
nextTarget.set(myPApplet.modelX(0,0,0),myPApplet.modelY(0,0,0),myPApplet.modelZ(0,0,0));
nextEye.set(myPApplet.modelX(0,0,500),myPApplet.modelY(0,0,500),myPApplet.modelZ(0,0,500));
nextAimFrame = curLine.getEndFrame();
myPApplet.popMatrix();
}
myPApplet.popMatrix();
}
myPApplet.popMatrix();
myPApplet.popMatrix();
}
PVector getAim(int currentFrame) {
int curAimX, curAimY, curAimZ;
if(nextAimFrame - aimFrame > 300) {
if (currentFrame < ((nextAimFrame - aimFrame)/2) + aimFrame) {
nextTarget.set(0,0,0);
}
else {
target.set(0,0,0);
}
}
if (currentFrame > nextAimFrame) {
curAimX = myPApplet.floor(nextTarget.x);
curAimY = myPApplet.floor(nextTarget.y);
curAimZ = myPApplet.floor(nextTarget.z);
}
else {
curAimX = myPApplet.floor(target.x + (nextTarget.x - target.x) * ((currentFrame - aimFrame) / (nextAimFrame - aimFrame)));
curAimY = myPApplet.floor(target.y + (nextTarget.y - target.y) * ((currentFrame - aimFrame) / (nextAimFrame - aimFrame)));
curAimZ = myPApplet.floor(target.z + (nextTarget.z - target.z) * ((currentFrame - aimFrame) / (nextAimFrame - aimFrame)));
}
return(new PVector(curAimX, curAimY, curAimZ));
}
PVector getEye(int currentFrame) {
int curEyeX, curEyeY, curEyeZ;
if(nextAimFrame - aimFrame > 300) {
if (currentFrame < ((nextAimFrame - aimFrame)/2) + aimFrame) {
nextEye.set(0,0,0);
}
else {
eye.set(0,0,0);
}
}
if (currentFrame > nextAimFrame) {
curEyeX = myPApplet.floor(nextEye.x);
curEyeY = myPApplet.floor(nextEye.y);
curEyeZ = myPApplet.floor(nextEye.z);
}
else {
curEyeX = myPApplet.floor(eye.x + (nextEye.x - eye.x) * ((currentFrame - aimFrame) / (nextAimFrame - aimFrame)));
curEyeY = myPApplet.floor(eye.y + (nextEye.y - eye.y) * ((currentFrame - aimFrame) / (nextAimFrame - aimFrame)));
curEyeZ = myPApplet.floor(eye.z + (nextEye.z - eye.z) * ((currentFrame - aimFrame) / (nextAimFrame - aimFrame)));
}
return(new PVector(curEyeX, curEyeY, curEyeZ));
}
}
some days ago i found an amazing script called "typestar" ( http://scott.j38.net/work/interactive/typestar/)
it's like a karaoke machine that renders lyrics in realtime.
when a song has a lot of lyrics the animation gets quite slow and shaky. i want to cut the text off so that only the last ~100 syllables are shown. i've been searching the plugintowers.java for a while but couldnt find a line to add a cut-off.
someone has a clue?
plugintower.java:
import java.util.TreeMap;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Arrays;
import processing.core.*;
class pluginTower {
PApplet myPApplet;
Song mySong;
PFont myFont, myFontEm;
int targetWidth;
public PVector eye, target, nextEye, nextTarget;
public float aimFrame, nextAimFrame, aimRotation, nextAimRotation;
pluginTower (PApplet newPApplet, Song newSong, PFont newFont, PFont newFontEm, int newTargetWidth) {
try {
mySong = (Song)ObjectCloner.deepCopy(newSong);
}
catch(Exception e)
{
System.out.println("Exception in main = " + e);
}
myPApplet = newPApplet;
myFont = newFont;
myFontEm = newFontEm;
eye = new PVector();
target = new PVector();
aimFrame = 0;
aimRotation = 0;
nextEye = new PVector();
nextTarget = new PVector();
nextAimFrame = 0;
nextAimRotation = 0;
myPApplet.resetMatrix();
TreeMap songLines = mySong.getLines();
Iterator<Integer> lineItr = songLines.keySet().iterator();
myPApplet.textFont(myFont);
int lastRotationFactor = 0;
int rotationFactorCount = 0;
targetWidth = newTargetWidth;
int lineCounter = 1;
float lastLineHeight = 0;
float lastLineCount = 1;
while (lineItr.hasNext()) {
int curLineKey = lineItr.next();
Line curLine = (Line)songLines.get(curLineKey);
int lineRotate = 0;
// if (lineCounter % 3 == 1)
// lineRotate = 0;
// else if (lineCounter %3 == 2)
// lineRotate = 90;
// else if (lineCounter %3 == 0)
// lineRotate = -180;
lineCounter++;
// ------------------------------
// Set Line Transformation Matrix
// ------------------------------
PMatrix3D lineMatrix = new PMatrix3D();
lastLineHeight = 0;
float[] lineMatrixRaw = new float[16];
lineMatrix.get(lineMatrixRaw);
curLine.setMatrix(lineMatrixRaw);
int letterCount = curLine.getLetters().length();
int wordCount = myPApplet.splitTokens(curLine.getLetters()).length;
float lineCount;
if (wordCount <= 3)
lineCount = 1;
else if (wordCount > 3 && wordCount <= 7)
lineCount = 2;
else if (wordCount > 7 && wordCount <= 13)
lineCount = 3;
else
lineCount = 4;
int lineStep = myPApplet.ceil(wordCount / lineCount);
lastLineCount = lineCount;
//
// Determine Segment sizes
//
ArrayList segmentScales = new ArrayList();
for (int curSegment = 0; curSegment < lineCount; curSegment++) {
int fromIndex = curSegment * lineStep;
int toIndex = (curSegment * lineStep) + lineStep;
if (toIndex > myPApplet.splitTokens(curLine.getLetters()).length)
toIndex = myPApplet.splitTokens(curLine.getLetters()).length;
ArrayList segmentWords = new ArrayList(Arrays.asList(myPApplet.splitTokens(curLine.getLetters())).subList(fromIndex, toIndex ));
String segmentString = "";
Iterator<String> itr = segmentWords.iterator();
while (itr.hasNext()) {
segmentString = segmentString + " " +itr.next();
}
float segmentScale = targetWidth/myPApplet.textWidth(segmentString.trim());
//println(textWidth(segmentString.trim()) + " " + segmentScale + " " + segmentString);
segmentScales.add(segmentScale);
}
//println(wordCount + " " + lineCount + " " + lineStep + " " + curLine.getLetters());
TreeMap songWords = curLine.getWords();
Iterator<Integer> wordItr = songWords.keySet().iterator();
int wordCounter = 0;
int segmentCounter = 0;
float wordOffsetX = 0;
float wordOffsetY = 0;
float wordScale = 1;
float wordTotalX = 0;
float wordTotalY = 0;
boolean newSegment = true;
while (wordItr.hasNext()) {
int curWordKey = wordItr.next();
Word curWord = (Word)songWords.get(curWordKey);
//println(curWord.getLetters());
if (wordCounter % lineStep == 0) {
newSegment = true;
}
if (newSegment) {
if (segmentCounter < segmentScales.size()) {
float lastScale = 1;
float curScale = 1;
for (int curSegment = 0; curSegment <= segmentCounter; curSegment++) {
//println(lastScale + " " + 1/lastScale);
curScale = Float.valueOf(segmentScales.get(curSegment).toString()).floatValue() * (1/lastScale);
lastScale = Float.valueOf(segmentScales.get(curSegment).toString()).floatValue();
}
wordScale = curScale;
lastLineHeight += ((myPApplet.textAscent() * .95) * lastScale) + (targetWidth/100);
segmentCounter++;
}
}
else {
wordScale = 1;
}
if (wordCounter % lineStep == 0) {
wordOffsetX = wordOffsetX - wordTotalX;
wordTotalX = 0;
wordOffsetY = (float)((myPApplet.textAscent() * .95) * wordScale) + (targetWidth/50);
}
else {
wordOffsetY = 0;
}
//
// Set Word Transformation Matrix
//
PMatrix3D wordMatrix = new PMatrix3D();
wordMatrix.translate(wordOffsetX, wordOffsetY);
wordMatrix.scale(wordScale);
float[] wordMatrixRaw = new float[16];
wordMatrix.get(wordMatrixRaw);
curWord.setMatrix(wordMatrixRaw);
if (curWord.getLetters().charAt(0) == ' ' && newSegment)
curWord.setLetters(curWord.getLetters().substring(1));
wordOffsetX = myPApplet.textWidth(curWord.getLetters());
TreeMap songSyllables = curWord.getSyllables();
Iterator<Integer> syllableItr = songSyllables.keySet().iterator();
float syllableOffset = 0;
while (syllableItr.hasNext()) {
int curSyllableKey = syllableItr.next();
Syllable curSyllable = (Syllable)songSyllables.get(curSyllableKey);
//
// Set Word Transformation Matrix
//
PMatrix3D syllableMatrix = new PMatrix3D();
syllableMatrix.translate(syllableOffset, 0);
float[] syllableMatrixRaw = new float[16];
syllableMatrix.get(syllableMatrixRaw);
curSyllable.setMatrix(syllableMatrixRaw);
if (curSyllable.getLetters().charAt(0) == ' ' && newSegment)
curSyllable.setLetters(curSyllable.getLetters().substring(1));
syllableOffset = myPApplet.textWidth(curSyllable.getLetters());
wordTotalX += syllableOffset;
//curSyllable.setEndFrame(curSyllable.getStartFrame() + 600);
curWord.addSyllable(curSyllable);
}
//curWord.setEndFrame(curWord.getStartFrame() + 600);
curLine.addWord(curWord);
wordCounter++;
newSegment = false;
}
//curLine.setEndFrame(curLine.getStartFrame() + 600);
// Pick left or right rotation
int newRotationFactor;
if(myPApplet.round(myPApplet.random(2)) == 1) {
newRotationFactor = 1;
} else {
newRotationFactor = -1;
}
if (lastRotationFactor == newRotationFactor)
rotationFactorCount++;
if (rotationFactorCount > 1) {
newRotationFactor *= -1;
rotationFactorCount = 0;
}
curLine.setRotationFactor(newRotationFactor);
lastRotationFactor = newRotationFactor;
curLine.setHeight(lastLineHeight);
mySong.addLine(curLine);
}
}
void draw(int currentFrame, int textColor, PMatrix3D songMatrix, PMatrix3D lineMatrix, boolean stepWidth, boolean stepHeight, boolean dropShadow, int[] autoRotate, int[] syllableAnimation) {
float lastLineHeight = 0;
myPApplet.pushMatrix();
myPApplet.applyMatrix(songMatrix);
//myPApplet.translate(0,(float)(0 - currentFrame * 2));
TreeMap songLines = mySong.getLines();
Iterator<Integer> lineItr = songLines.keySet().iterator();
aimRotation = nextAimRotation = 0;
myPApplet.pushMatrix();
int lineCounter = 0;
while (lineItr.hasNext()) {
lineCounter++;
int curLineKey = lineItr.next();
Line curLine = (Line)songLines.get(curLineKey);
if (stepWidth) myPApplet.translate(targetWidth,0);
if (stepHeight) myPApplet.translate(0,lastLineHeight);
lastLineHeight = curLine.getHeight();
myPApplet.applyMatrix(lineMatrix);
PMatrix3D curLineMatrix = new PMatrix3D();
curLineMatrix.set(curLine.getMatrix());
//curLineMatrix.print();
myPApplet.applyMatrix(curLineMatrix);
int modFactor = ((lineCounter%2) == 0) ? -1 : 1;
if (autoRotate[0] == 1) myPApplet.rotateX(myPApplet.radians(90 * modFactor));
if (autoRotate[1] == 1) myPApplet.rotateY(myPApplet.radians(90 * curLine.getRotationFactor()));
if (autoRotate[2] == 1) myPApplet.rotateZ(myPApplet.radians(90 * curLine.getRotationFactor()));
if ((currentFrame < curLine.getStartFrame()) && lineCounter==1){
myPApplet.textFont(myFont,30);
myPApplet.text(mySong.artist + " - " + mySong.title,1,1);
}
if (curLine.getStartFrame() > currentFrame){
myPApplet.pushMatrix();
nextTarget.set(myPApplet.modelX(0,0,0),myPApplet.modelY(0,0,0),myPApplet.modelZ(0,0,0));
nextEye.set(myPApplet.modelX(0,0,500),myPApplet.modelY(0,0,500),myPApplet.modelZ(0,0,500));
nextAimFrame = curLine.getStartFrame();
myPApplet.popMatrix();
break;
}
myPApplet.pushMatrix();
target.set(myPApplet.modelX(0,0,0),myPApplet.modelY(0,0,0),myPApplet.modelZ(0,0,0));
eye.set(myPApplet.modelX(0,0,500),myPApplet.modelY(0,0,500),myPApplet.modelZ(0,0,500));
aimFrame = curLine.getStartFrame();
myPApplet.popMatrix();
TreeMap songWords = curLine.getWords();
Iterator<Integer> wordItr = songWords.keySet().iterator();
myPApplet.pushMatrix();
while (wordItr.hasNext()) {
int curWordKey = wordItr.next();
Word curWord = (Word)songWords.get(curWordKey);
if (curWord.getStartFrame() > currentFrame)
continue;
PMatrix3D curWordMatrix = new PMatrix3D();
curWordMatrix.set(curWord.getMatrix());
myPApplet.applyMatrix(curWordMatrix);
TreeMap songSyllables = curWord.getSyllables();
Iterator<Integer> syllableItr = songSyllables.keySet().iterator();
myPApplet.pushMatrix();
while (syllableItr.hasNext()) {
int curSyllableKey = syllableItr.next();
Syllable curSyllable = (Syllable)songSyllables.get(curSyllableKey);
if (curSyllable.getStartFrame() > currentFrame)
continue;
PMatrix3D curSyllableMatrix = new PMatrix3D();
curSyllableMatrix.set(curSyllable.getMatrix());
myPApplet.applyMatrix(curSyllableMatrix);
if (currentFrame - curSyllable.getStartFrame() < 8 ) {
float aniFactor = (currentFrame - curSyllable.getStartFrame()) / 8f;
if (syllableAnimation[0] == 1)
myPApplet.translate(0,0,myPApplet.round(256 - ( aniFactor* 256)));
if (syllableAnimation[1] == 1)
myPApplet.rotateX(myPApplet.radians(myPApplet.round(85 - ( aniFactor* 85))));
if (syllableAnimation[2] == 1)
myPApplet.scale(aniFactor);
}
//myPApplet.println( curSyllable.getLetters() + " " + currentFrame + " " + (curSyllable.getStartFrame()));
if (curSyllable.getEndFrame() - curSyllable.getStartFrame() < 5)
myPApplet.textFont(myFont);
else
myPApplet.textFont(myFontEm);
if (dropShadow){
myPApplet.shininess(0);
myPApplet.fill(0,0,0,(float)(curLine.getStartFrame() * 1.0 / currentFrame) * 128) ;
myPApplet.pushMatrix();
myPApplet.translate(targetWidth/80,targetWidth/80,-targetWidth/80);
myPApplet.text(curSyllable.getLetters(), 0, 0);
myPApplet.popMatrix();
}
myPApplet.shininess(100);
myPApplet.fill(textColor , (float)(curLine.getStartFrame() * 1.0 / currentFrame) * 255) ;
myPApplet.text(curSyllable.getLetters(), 0, 0);
}
myPApplet.popMatrix();
}
if (!lineItr.hasNext()) {
myPApplet.pushMatrix();
if (stepWidth) myPApplet.translate(targetWidth,0);
if (stepHeight) myPApplet.translate(0,curLine.getHeight());
nextTarget.set(myPApplet.modelX(0,0,0),myPApplet.modelY(0,0,0),myPApplet.modelZ(0,0,0));
nextEye.set(myPApplet.modelX(0,0,500),myPApplet.modelY(0,0,500),myPApplet.modelZ(0,0,500));
nextAimFrame = curLine.getEndFrame();
myPApplet.popMatrix();
}
myPApplet.popMatrix();
}
myPApplet.popMatrix();
myPApplet.popMatrix();
}
PVector getAim(int currentFrame) {
int curAimX, curAimY, curAimZ;
if(nextAimFrame - aimFrame > 300) {
if (currentFrame < ((nextAimFrame - aimFrame)/2) + aimFrame) {
nextTarget.set(0,0,0);
}
else {
target.set(0,0,0);
}
}
if (currentFrame > nextAimFrame) {
curAimX = myPApplet.floor(nextTarget.x);
curAimY = myPApplet.floor(nextTarget.y);
curAimZ = myPApplet.floor(nextTarget.z);
}
else {
curAimX = myPApplet.floor(target.x + (nextTarget.x - target.x) * ((currentFrame - aimFrame) / (nextAimFrame - aimFrame)));
curAimY = myPApplet.floor(target.y + (nextTarget.y - target.y) * ((currentFrame - aimFrame) / (nextAimFrame - aimFrame)));
curAimZ = myPApplet.floor(target.z + (nextTarget.z - target.z) * ((currentFrame - aimFrame) / (nextAimFrame - aimFrame)));
}
return(new PVector(curAimX, curAimY, curAimZ));
}
PVector getEye(int currentFrame) {
int curEyeX, curEyeY, curEyeZ;
if(nextAimFrame - aimFrame > 300) {
if (currentFrame < ((nextAimFrame - aimFrame)/2) + aimFrame) {
nextEye.set(0,0,0);
}
else {
eye.set(0,0,0);
}
}
if (currentFrame > nextAimFrame) {
curEyeX = myPApplet.floor(nextEye.x);
curEyeY = myPApplet.floor(nextEye.y);
curEyeZ = myPApplet.floor(nextEye.z);
}
else {
curEyeX = myPApplet.floor(eye.x + (nextEye.x - eye.x) * ((currentFrame - aimFrame) / (nextAimFrame - aimFrame)));
curEyeY = myPApplet.floor(eye.y + (nextEye.y - eye.y) * ((currentFrame - aimFrame) / (nextAimFrame - aimFrame)));
curEyeZ = myPApplet.floor(eye.z + (nextEye.z - eye.z) * ((currentFrame - aimFrame) / (nextAimFrame - aimFrame)));
}
return(new PVector(curEyeX, curEyeY, curEyeZ));
}
}
1