changing color of the next character in a String? Typewritter stuff
in
Programming Questions
•
1 month ago
Hello, im making a small typewriter program and i wish to change the color of the individual characters.
So far i have this but it changes the color of everything i typed plus it doesn't n keep it.
Anyone can help or point me the resources i should look into? I want to press for example 1, and change to yellow, 2, other color and so on. But keeping the typing already done in the color chosen.. I have read as much as i can and i am stuck now :/
I am using a code i found for a terminal emulator to do this.. Any help appreciated, thanks!
So far i have this but it changes the color of everything i typed plus it doesn't n keep it.
Anyone can help or point me the resources i should look into? I want to press for example 1, and change to yellow, 2, other color and so on. But keeping the typing already done in the color chosen.. I have read as much as i can and i am stuck now :/
I am using a code i found for a terminal emulator to do this.. Any help appreciated, thanks!
- PFont myFont;
String[] myString;
int numLines;
int lineSpacing = 20;
int counter;
int cursorBlink = 15;
int numColumns = 56;
void setup(){
size(640,480);
frameRate(30);
numLines = (int) (height/lineSpacing);
smooth();
myString = new String[numLines];
for (int i=0; i<numLines; i++){
myString[i] = "";
}
consolePrint(" start");
counter = 0;
myFont = loadFont("glyphs.vlw");
textFont(myFont,20);
}
void draw(){
background(0);
fill(#14FA7D);
if (keyPressed) {
if (key == '1' || key == '1') {
fill(#F3FC00);
}
} else {
fill(#14FA7D);
}
for (int i=0; i<numLines-1; i++){
text(myString[i],5,(i+1)*lineSpacing);
}
String addMe = "";
if (counter++ > cursorBlink) addMe = "r";
if (counter > 2*cursorBlink) counter = 0;
text(myString[numLines-1]+addMe,5,numLines*lineSpacing);
}
// input
void processCommand(String s){
if (s.length()>9 && s.substring(0,9).toLowerCase().equals("printfile")){
printFile(s.substring(10));
}
}
void consolePrint(String s){
myString[numLines-1] = s;
advanceLine();
}
void advanceLine(){
for (int i=0; i<numLines-1; i++){
myString[i] =myString[i+1];
}
myString[numLines-1] = " ";
}
void keyPressed(){
if (key==ENTER||key==RETURN){
advanceLine();
String s = myString[numLines-2].substring(1);
processCommand(s);
return;
}
1