// comment out the following two lines to disable line-breaks
typedText += "\n";
break;
case ESC:
case DELETE:
break;
default:
typedText += key;
}
}
}
For this to work properly a background(255); in draw{} is executed every loop to 'refresh' the sketch and draw the updated text. Is there a simple way how this can be done without using background(255) in the draw method?
In other words if I modify the program above so that it generates a random number as show below, the number will be show in my sketch (it is only shown when background(255) is removed).
String typedText = "your text here";
PFont font;
void setup() {
size(400, 400);
font = createFont("Helvetica", 18);
randomNumber();
}
void draw() {
background(255);
fill(255,0,0);
textFont(font,18);
line(0,0,200,200);
// this adds a blinking cursor after your text, at the expense of redrawing everything every frame
Hi guy I am new in this forum and I need some help. I have the following program. Now I need this program to work such that every time the user enters a number from 1-4, the last entry is replaced with the previous one. I know it can be done by using background(255) and therefore the screen is refreshed every time, but it is not a good method when you have other stuff rather than just the number...since everything will disappear.
Any help is appreciated :D
int leftmargin = 10;
String buff = "";
boolean cell_full = false;
void setup()
{
size(640, 360);
background(255);
textFont(loadFont("AngsanaNew-Bold-25.vlw"), 45);
}
void draw()
{
background(255);
if((millis() % 900) < 250)
{ // at regular intervals the curser turns white so it looks like it is blinking
stroke(255);
}
else
{ //else for the rest of the time the colour of the cursor is black
fill(255);
stroke(0);
}
float rPos; // x position of the cursor
rPos = textWidth(buff) + leftmargin; //textWidth(buff) is the length of all entered char PLUS the last margin
line(rPos, 9, rPos, 40);
println(textWidth(buff)); //Proof
fill(0);
pushMatrix();
translate(rPos,10+25);
char k;
for(int i = 0;i < buff.length(); i++) //buff.length always 1