I’m totally new to processing and to coding in general.
At the moment I’m really not sure if my brain is capable of learning code… have been trying to understand some of the reference section with limited success.
I’ve downloaded a bit of code from github that does something (mildly) interesting with text and am hoping to learn enough to modify it a bit to do some other things I have in mind. (see here for a more comprehensive explanation: Newbie seeking a bit of guidance... vertically falling text manipulation)
Referenced in the code is the following “Cursor” class (essentially a moving blinking cursor):
class Cursor
{
int x, y;
int blinkTime;
int previous;
boolean bLight = true;
PImage r;
int fontW;
int fontH;
Cursor(int _x, int _y, int _fW, int _fH, int _blinkTime) {
fontW = _fW;
fontH = _fH;
x = _x * fontW;
y = _y * fontH;
blinkTime = _blinkTime;
r = createImage(fontW, fontH, RGB);
r.loadPixels();
for (int i = 0; i < r.pixels.length; i++) {
r.pixels[i] = color( MONOCHROME );
}
r.updatePixels();
previous = millis();
}
void move(int _x, int _y) {
x = _x * fontW;
y = _y * fontH;
bLight = true;
}
void update(int time) {
if(time - previous> blinkTime){
bLight = !bLight;
previous = time;
}
}
void display() {
if(bLight){
pushStyle();
noStroke();
//fill(0, 255, 0);
blend(r, 0, 0, fontW, fontH, x, y, fontW, fontH, DIFFERENCE);
popStyle();
}
}
}`Preformatted text`
This Cursor is used in another script that “writes” text on screen (from a txt file: “script.txt”) in the style of the old terminal command prompt computers.
Can anyone tell me how I might write a command in the main script to “turn off” the cursor once it’s written something, i.e. to stop blinking and go blank?
At the moment, it just sits there blinking at the end of the written line.
Here’s the part of the main script that seems to deal mostly with the cursor class:
void scriptLoad() {
lineIdx = 0;
lineChar = 0;
script = loadStrings("script.txt");
if( script == null ) {
println("\nloadString returned NULL");
exit();
} else {
println("Script loaded!");
println("Script contains " + script.length + " lines");
for (int i = 0 ; i < script.length; i++) {
print("line "+i+" has "+ script[i].length() + " characters");
if( script[i].isEmpty() ) {
// empty line
println(";");
continue;
} else if( scriptIsCommand(i) ) {
if( whatCommand(i) == -1) {
print(" - INVALID COMMAND!");
exit();
} else {
print(" - line "+i+" is a command! ( ");
print( script[i] +" )");
}
} else {
print(";");
}
println();
}
}
}
void scriptRead( int time ) {
if( bWaiting ) {
menageWaiting( time );
} else if( lineIdx < script.length ) {
if( script[ lineIdx ].isEmpty() ) {
// empty line
lineIdx++;
} else if( scriptIsCommand( lineIdx )) {
//debugA("found a command:");
// Any commands in the script have already been
// evaluated during the script loading
int opCode = whatCommand( lineIdx );
// command execution
switch( opCode ) {
case 0: // #WAIT
//debugA("WAIT command");
bWaiting = true;
waitTime = idleWaitTime;
previousTime = time;
//previousWaitTime = time;
break;
case 1: //#CLEAR
//debugA("CLEAR command");
waitTime = charWaitTime;
waitValue = 1;
bWaiting = true;
previousTime = time;
screenClear();
cursor.move(colIdx, rowIdx);
break;
case 2: //#LINEFEED
//debugA("LINEFEED command");
rowIdx++;
colIdx = 0;
insertPrompt();
cursor.move(colIdx, rowIdx);
break;
case 3: //#RESTART
//debugA("RESTART command");
screenClear();
lineIdx = 0;
lineChar = 0;
break;
case 4: //#CLEARLINE
//debugA("CLEARLINE command");
screenClearLine();
cursor.move(colIdx, rowIdx);
default:
break;
}
lineIdx ++;
} else {
// characters
if(lineChar < script[ lineIdx ].length() ) {
waitTime = charWaitTime;
waitValue = 1;
bWaiting = true;
previousTime = time;
copyCharacter( time );
cursor.move(colIdx, rowIdx);
emitSound("char");
} else {
lineChar = 0;
lineIdx++;
scriptRead( millis() );
}
}
}
else {
//debugA("End of the script");
}
}
NOTE: the code is written for Processing 2.0