Advertisement
Python253

Lust_Script

Jun 29th, 2018
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.53 KB | None | 0 0
  1. <script>
  2. // ——————————————————————————————————————————————————
  3. // TextScramble
  4. // ——————————————————————————————————————————————————
  5.  
  6. class TextScramble {
  7.   constructor(el) {
  8.     this.el = el
  9.     this.chars = '!<>-_\\/[]{}—=+*^?#________'
  10.     this.update = this.update.bind(this)
  11.   }
  12.   setText(newText) {
  13.     const oldText = this.el.innerText
  14.     const length = Math.max(oldText.length, newText.length)
  15.     const promise = new Promise((resolve) => this.resolve = resolve)
  16.     this.queue = []
  17.     for (let i = 0; i < length; i++) {
  18.      const from = oldText[i] || ''
  19.      const to = newText[i] || ''
  20.      const start = Math.floor(Math.random() * 40)
  21.      const end = start + Math.floor(Math.random() * 40)
  22.      this.queue.push({ from, to, start, end })
  23.    }
  24.    cancelAnimationFrame(this.frameRequest)
  25.    this.frame = 0
  26.    this.update()
  27.    return promise
  28.  }
  29.  update() {
  30.    let output = ''
  31.    let complete = 0
  32.    for (let i = 0, n = this.queue.length; i < n; i++) {
  33.      let { from, to, start, end, char } = this.queue[i]
  34.      if (this.frame >= end) {
  35.         complete++
  36.         output += to
  37.       } else if (this.frame >= start) {
  38.         if (!char || Math.random() < 0.28) {
  39.          char = this.randomChar()
  40.          this.queue[i].char = char
  41.        }
  42.        output += `<span class="dud">${char}</span>`
  43.       } else {
  44.         output += from
  45.       }
  46.     }
  47.     this.el.innerHTML = output
  48.     if (complete === this.queue.length) {
  49.       this.resolve()
  50.     } else {
  51.       this.frameRequest = requestAnimationFrame(this.update)
  52.       this.frame++
  53.     }
  54.   }
  55.   randomChar() {
  56.     return this.chars[Math.floor(Math.random() * this.chars.length)]
  57.   }
  58. }
  59.  
  60.  
  61. const phrases = [
  62.   'Ana,',
  63.   'there will come a time',
  64.   'when you will decide',
  65.   'between yourself and your loved ones.',
  66.   'When it comes,',
  67.   'walk the path your peers would not',
  68.   'and triumph in the victory that you feel in your heart.',
  69.   'A Cab Cede Ether Summer Fruit.',
  70.   'A Bash Steg Mr Hemmer Prate.',
  71.   'Weighted Jetport Moth'
  72. ]
  73.  
  74. const el = document.querySelector('.text')
  75. const fx = new TextScramble(el)
  76.  
  77. let counter = 0
  78. const next = () => {
  79.   fx.setText(phrases[counter]).then(() => {
  80.     setTimeout(next, 800)
  81.   })
  82.   counter = (counter + 1) % phrases.length
  83. }
  84.  
  85. next()
  86. </script>
  87.  
  88. // http://1711141131131.xyz/Kees.mp3 //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement