Simple Processing problem
in
Programming Questions
•
9 months ago
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
- {
- k = buff.charAt(i);
- translate(-textWidth(k),0); //-15,0
- text(k,0,0);
- }
- popMatrix();
- }
- void keyPressed()
- {
- char k;
- k = (char)key;
- if(k==char(8))
- {
- if(buff.length()>0)
- buff = buff.substring(1);
- // cell_full=false;
- }
- if(cell_full==false)
- {
- if(k=='1')
- buff=k+buff;
- else if(k=='2')
- buff=k+buff;
- else if(k=='3')
- buff=k+buff;
- else if(k=='4')
- buff=k+buff;
- cell_full=true;
- }
- else
- {
- if(k=='1')
- {
- buff="";
- buff=k+buff;
- }
- else if(k=='2')
- {
- buff="";
- buff=k+buff;
- }
- else if(k=='3')
- {
- buff="";
- buff=k+buff;
- }
- else if(k=='4')
- {
- buff="";
- buff=k+buff;
- }
- }
- }
1