Drawing and Detecting Characters Sequence
in
Programming Questions
•
8 months ago
Hi, I'm working on a poster (static) in which a given text input was transform into characters and placed onto screen with text() function.
The hard part is--I need to detect a specific word(s) in the characters, say "company", and then kind of transform it along z-axis so the word kinda "falls" into the dark behind. The neighboring characters in the radius (both in-lines and the lines above and below) will have to "fall" to follow the word too, sort of like rocks fallen after one trips down the cliff.
So far, I've only come up with a generic drawing of characters. Please look at my code and advise ASAP. Thanks!!
- import processing.opengl.*;
- String[] lines;
- String message;
- PFont f;
- float posX;
- float posY;
- int fontSize;
- void setup() {
- r = 60;
- //arclength = 0;
- posX = 0;
- posY = 10;
- fontSize = 20;
- lines = loadStrings("anytext.txt");
- message = join(lines, " ");
- size(650, 650, OPENGL);
- background(0);
- f = createFont("Arial",fontSize,true);
- textFont(f);
- textAlign(CENTER);
- smooth();
- }
- void draw() {
- // For every box
- for (int i = 0; i < message.length(); i++ ) {
- // The character and its width
- char currentChar = message.charAt(i);
- float w = textWidth(currentChar);
- posX += w/2;
- pushMatrix();
- translate(posX, posY);
- fill(255, random(50, 200));
- text(currentChar,0,0);
- // Check to see if the line hits the end of the window
- if (posX >= width-w*0.7) {
- posY = posY + fontSize*0.75;
- posX = 0;
- }
- }
- }
1