Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void setup(){
- background(175);
- size(600,400);
- rectMode(CORNER);
- }
- String textBoxInput = "";
- boolean textLimit = false;
- boolean drawCap = false;
- boolean drawRev = false;
- boolean drawReverse = false;
- boolean drawDelSp = false;
- boolean drawMidChar = false;
- boolean doOnce = true;
- boolean storeRev = false;
- void draw(){
- background(175);
- float buttonWidth = width*0.2916;
- float buttonHeight = height*0.08;
- int buttonPosX = (width/14)*9;
- int buttonPosY = height/6;
- int textBoxPosX = width/14;
- int textBoxPosY = height/6;
- float textBoxWidth = width*0.533;
- String clearText = "Clear";
- String capText = "Capitals";
- String revText = "Reverse";
- String delSpText = "Delete Spaces";
- String midCharText = "Middle Character";
- float textMarginX = buttonWidth/20;
- float textMarginY = buttonHeight/4;
- String textCap = textBoxInput.toUpperCase();
- String textRev ="";
- String finalReversed = "";
- //TextBox
- fill(255);
- rect(textBoxPosX,textBoxPosY,textBoxWidth,buttonHeight);
- fill(0);
- textSize(width*0.03);
- text(textBoxInput,textBoxPosX+textMarginX,textBoxPosY+buttonHeight-textMarginY);
- //BUTTONS
- //Clear button
- fill(175);
- rect(buttonPosX,buttonPosY,buttonWidth,buttonHeight);
- fill(0);
- textSize(width*0.03);
- text(clearText,buttonPosX+textMarginX,buttonPosY+buttonHeight-textMarginY);
- //Capital button
- fill(175);
- rect(buttonPosX,buttonPosY*2,buttonWidth,buttonHeight);
- fill(0);
- textSize(width*0.03);
- text(capText,buttonPosX+textMarginX,(buttonPosY*2)+buttonHeight-textMarginY);
- //Reverse button
- fill(175);
- rect(buttonPosX,buttonPosY*3,buttonWidth,buttonHeight);
- fill(0);
- textSize(width*0.03);
- text(revText,buttonPosX+textMarginX,(buttonPosY*3)+buttonHeight-textMarginY);
- //Delete Spaces button
- fill(175);
- rect(buttonPosX,buttonPosY*4,buttonWidth,buttonHeight);
- fill(0);
- textSize(width*0.03);
- text(delSpText,buttonPosX+textMarginX,(buttonPosY*4)+buttonHeight-textMarginY);
- //Middle Character button
- fill(175);
- rect(buttonPosX,buttonPosY*5,buttonWidth,buttonHeight);
- fill(0);
- textSize(width*0.03);
- text(midCharText,buttonPosX+textMarginX,(buttonPosY*5)+buttonHeight-textMarginY);
- if(textLimit){
- fill(255,0,0);
- text("Text limit reached!",textBoxPosX,height/8);
- }
- if(drawRev){
- int i = textBoxInput.length();
- while(i>0){
- textRev += textBoxInput.substring(i-1,i);
- i--;
- }
- }
- println(textRev);
- //BUTTON BOOLEANS
- //CAPITAL
- if(drawCap){
- text(textCap,textBoxPosX,(buttonPosY*2)+buttonHeight-textMarginY);
- }
- if(drawRev){
- text(textRev,textBoxPosX,(buttonPosY*3)+buttonHeight-textMarginY);
- }
- //BUTTON CLICK
- if(mousePressed && doOnce == false){
- //Clear button
- if(mouseX >= buttonPosX && mouseX <= buttonPosX+buttonWidth && mouseY >= buttonPosY && mouseY <= buttonPosY+buttonHeight){
- textBoxInput = "";
- }
- //Capital button
- if(mouseX >= buttonPosX && mouseX <= buttonPosX+buttonWidth && mouseY >= buttonPosY*2 && mouseY <= (buttonPosY*2)+buttonHeight){
- drawCap = true;
- }
- //Reverse button
- if(mouseX >= buttonPosX && mouseX <= buttonPosX+buttonWidth && mouseY >= buttonPosY*3 && mouseY <= (buttonPosY*3)+buttonHeight){
- drawRev = true;
- }
- doOnce = true;
- }
- }
- void mouseReleased(){
- doOnce = false;
- }
- void keyTyped(){
- if((key >= 'a' && key <= 'z') || key == ' '){
- if(textBoxInput.length()<=20){
- textBoxInput = textBoxInput + key;
- } else {
- textLimit = true;
- }
- } else if ((key == BACKSPACE) && textBoxInput.length()>0){
- int inputLength = textBoxInput.length();
- textBoxInput = textBoxInput.substring(0,inputLength-1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement