Ah, my apologizes. Didn't test that out first. See new lines below:
- PFont consolas;
- String[] names;
- boolean saveMode;
- String currentName;
- int currentPos;
- String SAVE_PASSWORD = "apple";
- void setup () {
- smooth();
- size (1200, 700);
- // I like my font better. :)
- consolas = createFont("Ariel", 100 );
- // consolas = loadFont ("Consolas-100.vlw");
- textFont(consolas, 100);
- names = new String[45];
- for ( int i = 0; i < names.length; i++) {
- names[i] = "";
- }
- currentName = "";
- currentPos = 0;
- }
- void draw () {
- background (0, 255, 202);
- fill (250);
- rect (300, 100, 600, 50);
- pushStyle();
- textAlign( CENTER, CENTER );
- fill(0);
- textSize(40);
- if ( saveMode ) {
- String hidden = "";
- for ( int t=0; t < currentName.length(); t++) {
- hidden+="*";
- }
- text( hidden, 600, 120);
- }
- else {
- text( currentName, 600, 120);
- }
- popStyle();
- fill (23, 85, 167);
- textSize(80);
- text ("Hello!", 502, 71);
- fill (250);
- fill (23, 85, 167);
- textSize(20);
- if ( saveMode ) {
- fill(255, 0, 0);
- text ("Please enter the password to save and clear this list.", 300, 92);
- }
- else {
- if ( currentPos < names.length ) {
- text ("Type your name and press enter.", 442, 92);
- }
- else {
- text ("Sorry, but there's no space left!", 442, 92);
- }
- }
- fill (0);
- textSize(15);
- for ( int i = 0; i < names.length; i++) {
- text( str( i + 1 ) + ")", i>8?(292+(200 * (i/15))):(300 + (200 * (i/15))), 175 + (25 * (i%15)) );
- text( names[i], 320 + (200 * (i/15)), 175 + (25 * (i%15) ) );
- }
- }
- void keyTyped() {
- if ( key == '!' ) {
- saveMode = true;
- return;
- }
- if ( (key >= 'a' && key <= 'z') || (key >= 'A' && key <= 'Z') || (key == ' ' ) ) {
- if ( currentPos < names.length || saveMode ) {
- currentName += key;
- }
- return;
- }
- if ( key == DELETE || key == BACKSPACE ) {
- if ( currentName.length() > 0 ) {
- currentName = currentName.substring(0, currentName.length()-1);
- }
- return;
- }
- if ( key == ENTER || key == RETURN ) {
- if ( saveMode ) {
- if ( currentName.equals( SAVE_PASSWORD ) ) {
- saveStrings( "savedList-" + str( month() ) + "-" + str( day() ) + "-" + str( hour() ) + "-" + str( minute() ) + ".txt", names );
- currentName = "";
- currentPos = 0;
- for ( int i = 0; i < names.length; i++) {
- names[i] = "";
- }
- }
- saveMode = false;
- currentName = "";
- }
- else {
- if ( currentPos < names.length ) {
- names[currentPos] = currentName;
- currentName = "";
- currentPos++;
- }
- }
- }
- }
For the numbers:
str( i + 1 ) + ")", is the number followed by a ).
i>8?(292+(200 * (i/15))):(300 + (200 * (i/15))) is the x position. Notice that single digit numbers have a slightly different position because they are not as wide. Also note that for numbers above 15, i/15 will be 1, meaning that an additional 200 is added to the x position to move it over.
175 + (25 * (i%15)) is the y position. notice that it starts back at 175 for 16 because 15%15 is 0 again, 25 * 0 is 0, and 175 + 0 = 175.
The names are the same, except they don't have a x position that changes for smaller numbers, and are moved 20 pixels over so they don;t overlap the numbers.