Advertisement
Guest User

Untitled

a guest
Feb 25th, 2017
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.23 KB | None | 0 0
  1. alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", " "];
  2. textsize = 30;
  3. var typing = [];
  4.  
  5. function setup() {
  6.   createCanvas(900, 200);
  7.   textSize(textsize);
  8.  
  9.   sent = new Sentence("to be or not to be");
  10.  
  11.   sent.placePhraseInArray();
  12.  
  13.  
  14. }
  15.  
  16. function draw() {
  17.   background(0);
  18.   sent.getLetter();
  19.  
  20.   sent.render();
  21.  
  22. }
  23.  
  24. function Sentence(phrase) {
  25.   this.phrase = String(phrase);
  26.   this.phraseLen = phrase.length;
  27.   this.sentLen = typing.length;
  28.  
  29.  
  30.   this.switchLetter = random(2, 25);
  31.  
  32.   this.getLetter = function() {
  33.  
  34.     randomLetter = random(alphabet);
  35.  
  36.   }
  37.  
  38.   this.letterFuck = function() {
  39.     this.letter = text(randomLetter, 25, 100);
  40.  
  41.   }
  42.  
  43.  
  44.   this.placePhraseInArray = function() {
  45.     arrayPrompt = this.phrase.split('');
  46.     for (i = 0; i < arrayPrompt.length; i++) {
  47.       typing.push(arrayPrompt[i]);  
  48.     }
  49.    
  50.   }
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.   this.render = function() {
  58.     fill(255);
  59.     b = 0;
  60.     print(this.letter);
  61.     print(typing[0]);
  62.     if (this.letter == typing[b]) {
  63.  
  64.       this.letter = text(randomLetter, 25 + textsize, 100);
  65.       b += 1;
  66.     } else {
  67.       this.letterFuck();
  68.     }
  69.   }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement