// Experiments with text and Strings // Global variables PFont [] fonts; int currentFont; // index of some array element String myText; // Text to be displayed // Track where text is drawn int xPos; int yPos; int distance = 0; int oldR; int oldG; int oldB; void setup() { size(400, 400, P3D); fonts = new PFont[4]; fonts[0] = createFont("Ageoneserif", 24, true); fonts[1] = createFont("AmericanTypewriter", 48, false); fonts[2] = createFont("Apple-Chancery", 36, true); fonts[3] = createFont("Wingdings2", 56, true); currentFont = 0; myText = "A long time ago\nin a galaxy far, far away\nit was a dark time\nfor the Rebellion"; xPos = width/2; yPos = height/2; fill(170, 200, 180); frameRate(10); } void draw() { background(10); pushMatrix(); // Save old values ellipse(350, 250, 75, 75); popMatrix(); // restore old values pushMatrix(); textFont(fonts[currentFont]); translate(width/2, height/2, distance); // Shift origin to center rotateX(radians(25)); rotateY(radians(-1*mouseX)); rotateZ(radians(-1*mouseY)); textAlign(CENTER); text(myText, 0, yPos); yPos -= 1; distance = distance - 1; if (distance < -100) { distance = -100; } if (yPos < (0 - 2 * textWidth(myText))) { yPos = height/2; } popMatrix(); } void mousePressed() { currentFont += 1; // Increase currentFont by 1 if (currentFont >= fonts.length) // stay inside array { currentFont = 0; } fill(mouseX/2, 200, mouseY/2); } void keyPressed() { String newText = myText + key; // Get key that was pressed // If text is too long, cut off the first character if (newText.length() > 200) { newText = newText.substring(1, newText.length()); } myText = newText; }