Laitofai

Untitled

Jun 21st, 2022
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. let targetText = "Всем привет меня зовут Лев";
  2. let textBox;
  3. let start = -1;
  4.  
  5. function setup() {
  6. createCanvas(windowWidth, windowHeight);
  7. textBox = createInput("");
  8. textBox.center();
  9. textBox.input(textEntered);
  10. textSize(20);
  11. rectMode(CENTER);
  12. textAlign(CENTER);
  13. textWrap(WORD);
  14. }
  15.  
  16. // эта функция всегда повторяется
  17. function draw() {
  18. background(220);
  19. text(targetText, width/2, height/2 * 0.5, width * 0.7);
  20. }
  21.  
  22. // функция выводит в консоль текст который мы пишем в поле ввода
  23. function textEntered() {
  24. if (start === -1) { // если отчет еще не начат
  25. start = millis(); // millis - время прошедшее от запуска программы (в мс)
  26. }
  27. let userText = this.value();
  28. // если userText равен targetText => "Вы победили"
  29. if (userText === targetText) {
  30. let finish = millis(); // время конца
  31. let result = finish - start; // получаем разницу
  32. result = (result / 1000).toFixed(2);
  33. let symbPerSec = (targetText.length / result).toFixed(2);
  34. targetText = "Вы победили!!! \nВаше время - " + result + "с.\nСимволов в секунду - " + symbPerSec;
  35. textBox.hide();
  36. }
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment