Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <body>
  
  <div class="outer_wrapper">
    <div class="wrapper flex_box">
      <div class="grid">
      </div>
    </div>
  </div>

  <div? class="outer_wrapper flex_box">
    <div class="instruction">
      Type any alphabet on your keyboard, or enter something below and press button...
    </div>
    <div class="input_wrapper">
      <input placeholder= "Enter something here..." type="text">
      <button>animate</button>
    </div>
  </div>

  <div class="sign">
    by masahito / <a href="http://www.ma5a.com/" >ma5a.com</a>
  </div>

              
            
!

CSS

              
                
* {
  box-sizing: border-box;
}


body {
  padding: 0;
  margin: 0;
  font-family: serif;
  background-color: #010044;
}

.outer_wrapper{
  position: fixed;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

.wrapper {
  width: 100%;
  height: 100%;
}

.flex_box {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}

.sign {
  position: absolute;
  font-family: sans-serif;
  color: white;
  bottom: 10px;
  right: 10px;
  font-size: 10px;
}

a {  
  color: white;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.grid {
  height: 240px;
  width: 240px;
  display: flex;
  flex-wrap: wrap;
}

.cell {
  height: calc(100% / 16);
  width: calc(100% / 16);
  font-size: 10px;
}


.star {
  position: absolute;
  transition: 1s;
  overflow: hidden;
  opacity: 0.3;
  height: 15px;
  width: 15px;
  border-radius: 50%;
}

.star svg {
  height: 100%;
  width: auto;
}

.star_inner {
  height: 15px;
}

.instruction {
  position: absolute;
  top: 30px;
  color: rgb(255, 255, 255);
  font-style: italic;
  text-align: center;
  transition: 1s;
  width: 300px;
  opacity: 0;
}

.input_wrapper {
  position: absolute;
  bottom: 0px;
  width: 100%;
  height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
}

input, button {
  border-width: 0;
  border-radius: 50px;
  padding: 10px 16px;
  margin: 5px;
}

button {
  color: white;
  background-color: steelblue;
  transition: 0.3s;
}

button:hover {
  color: steelblue;
  background-color: white;
}


              
            
!

JS

              
                function init() {
  
  const letters = [
    //a
    '0000000000000000000000000000000000000001100000000000001111000000000001100110000000000110011000000000110000110000000011000011000000011111111110000001111111111000001100000000110000110000000011000110000000000110011000000000011000000000000000000000000000000000', 
    //b
    '0000000000000000000000000000000000011111110000000011111111110000001100000011000000110000000110000011000000011000001111111111000000111111111110000011000000001100001100000000110000110000000111000011111111111000000111111111000000000000000000000000000000000000',
    //c
    '0000000000000000000000000000000000000011111000000000111111111000000111000001110000011000000011000011000000000000001100000000000000110000000000000011000000000000000110000000110000011100000111000000111111111000000000111110000000000000000000000000000000000000',
    //d
    '0000000000000000000000000000000000011111110000000011111111110000001100000011000000110000000110000011000000001100001100000000110000110000000011000011000000001100001100000001110000110000001110000011111111110000000111111100000000000000000000000000000000000000',
    //e
    '0000000000000000000000000000000000111111111100000011111111111000001100000000000000110000000000000011000000000000001111111111000000111111111100000011000000000000001100000000000000110000000000000011111111111000000111111111000000000000000000000000000000000000',
    //f
    '0000000000000000000000000000000000111111111110000011111111111000001100000000000000110000000000000011000000000000001111111111000000111111111100000011000000000000001100000000000000110000000000000011000000000000000100000000000000000000000000000000000000000000',
    //g
    '0000000000000000000000000000000000000011111000000000111111111000000111000001110000011000000000000011000000000000001100000000000000110000001111100011000000111110000110000000110000011100000111000000111111111000000000111110000000000000000000000000000000000000',
    //h
    '0000000000000000000000000000000000010000000011000011000000001100001100000000110000110000000011000011000000001100001111111111110000111111111111000011000000001100001100000000110000110000000011000011000000001100000100000000100000000000000000000000000000000000',
    //i
    '0000000000000000000000000000000000000111111000000000011111100000000000011000000000000001100000000000000110000000000000011000000000000001100000000000000110000000000000011000000000000001100000000000011111100000000001111100000000000000000000000000000000000000',
    //j
    '0000000000000000000000000000000000000011111110000000011111111100000000000110000000000000011000000000000001100000000000000110000000000000011000000000000001100000000011000110000000000100011000000000001111100000000000011000000000000000000000000000000000000000',
    //k
    '0000000000000000000000000000000000110000000110000011000000111000001100000111000000110000111000000011000111000000001101111000000000111111000000000011101110000000001100011110000000110000011100000011000000111000001100000001100000000000000000000000000000000000',
    //l
    '0000000000000000000000000000000000011000000000000001100000000000000110000000000000011000000000000001100000000000000110000000000000011000000000000001100000000000000110000000000000011000000000000001111111111000000111111111100000000000000000000000000000000000',
    //m
    '0000000000000000000000000000000000010000000010000011100000011100001111000011110000111110011111000011011111101100001100111100110000110001100011000011000000001100001100000000110000110000000011000011000000001100000100000000100000000000000000000000000000000000',
    //n
    '0000000000000000000000000000000000010000000011000011100000001100001111000000110000111110000011000011011100001100001100111000110000110001110011000011000011101100001100000111110000110000001111000011000000011100000100000000110000000000000000000000000000000000',
    //o
    '0000000000000000000000000000000000000011110000000000111111100000000111000011100000011000000110000011000000001100001100000000110000110000000011000011000000001100000110000001100000011100001100000000111111100000000000111100000000000000000000000000000000000000',
    //p
    '0000000000000000000000000000000000111111111000000011111111110000001100000011100000110000000110000011000000011000001100000011100000111111111100000011111111100000001100000000000000110000000000000011000000000000001100000000000000000000000000000000000000000000',
    //q
    '0000000000000000000000000000000000000011110000000000111111110000000011000011000000011000000110000011000000001100001100000000110000110000110011000011000011101100000110000111100000011100001110000000111111111100000000111100110000000000000000000000000000000000',
    //r
    '0000000000000000000000000000000000011111111000000011111111110000001100000011000000110000000110000011000000111000001111111111000000111111111000000011011100000000001100111000000000110001111000000011000001111000000100000011000000000000000000000000000000000000',
    //s
    '0000000000000000000000000000000000001111111000000001111111110000001110000011100000110000000110000011100000000000000111111100000000000111111100000000000001111000001100000001100000111000001110000001111111110000000011111110000000000000000000000000000000000000',
    //t
    '0000000000000000000000000000000000001111111100000001111111111000000000011000000000000001100000000000000110000000000000011000000000000001100000000000000110000000000000011000000000000001100000000000000110000000000000011000000000000000000000000000000000000000',
    //u
    '0000000000000000000000000000000000010000000010000011000000001100001100000000110000110000000011000011000000001100001100000000110000110000000011000011000000001100001100000000110000011000000110000000111111110000000001111110000000000000000000000000000000000000',
    //v
    '0000000000000000000000000000000000000000000000000011000000001100001100000000110000011000000110000001100000011000000011000011000000001100001100000000011001100000000001100110000000000011110000000000000110000000000000011000000000000000000000000000000000000000',
    //w
    '0000000000000000000000000000000000100000000001000110000000000110011000000000011001100000000001100110000110000110011000011000011001100011110001100110011111100110001101100110110000111110011111000001110000111000000010000001000000000000000000000000000000000000',
    //x
    '0000000000000000000000000000000000010000000010000011100000011100000111000011100000001110011100000000011111100000000000111100000000000011110000000000011111100000000011100111000000011100001110000011100000011100001100000000100000000000000000000000000000000000',
    //y
    '0000000000000000000000000000000000110000000011000011100000011100000111000011100000001110011100000000011111100000000000111100000000000001100000000000000110000000000000011000000000000001100000000000000110000000000000011000000000000000000000000000000000000000',
    //z
    '0000000000000000000000000000000000011111111110000011111111111100000000000001110000000000001110000000000001110000000000001110000000000001110000000000001110000000000001110000000000001110000000000001111111111100000111111111110000000000000000000000000000000000',
    //space
    '0'
  ]

  const letterIndex = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ '

  const starSvg = `
  <svg x="0px" y="0px" width="565.4px" height="51.4px" viewBox="0 0 565.4 51.4" >
    <style type="text/css">
    .st0{fill:#FFFFFF;}
    .st1{fill:#226D87;}
    .st2{fill:#7EBAE0;}
    </style>
    <polygon class="st0" points="28.3,28.4 34.3,25.9 28.3,23.3 25.8,17.3 23.2,23.3 17.2,25.9 23.2,28.4 25.8,34.4 "/>
    <polygon class="st0" points="80.2,28.2 85.7,25.7 80.2,23.2 77.2,11.5 74.2,23.1 68.6,25.7 74.2,28.3 77.2,40 "/>
    <circle class="st1" cx="180" cy="25.8" r="2.8"/>
    <circle class="st1" cx="231.4" cy="25.7" r="5.7"/>
    <polygon class="st1" points="285.7,28.2 291.2,25.7 285.7,23.2 282.7,11.5 279.7,23.1 274.1,25.7 279.7,28.3 282.7,40 "/>
    <polygon class="st1" points="339.3,29.3 348.5,25.7 339.2,22.2 334.3,5.7 329.3,22.2 320,25.7 329.2,29.3 334.3,45.9 "/>
    <polygon class="st0" points="133.7,30.4 148.8,25.7 133.6,21 128.5,0.1 123.4,21 108.2,25.7 123.3,30.4 128.5,51.6 "/>
    <polygon class="st1" points="390.7,30.2 405.8,25.5 390.6,20.8 385.5,-0.1 380.4,20.8 365.2,25.5 380.3,30.2 385.5,51.4 "/>
    <polygon class="st2" points="539.7,4.5 546.6,18.5 562.1,20.8 550.9,31.7 553.5,47.1 539.7,39.8 525.9,47.1 528.5,31.7 517.3,20.8 
    532.8,18.5 "/>
    <polygon class="st2" points="488.3,12.1 492.8,21.1 502.8,22.6 495.6,29.6 497.3,39.5 488.3,34.8 479.4,39.5 481.1,29.6 473.9,22.6 
    483.9,21.1 "/>
    <polygon class="st2" points="437,17.7 439.6,23 445.5,23.9 441.2,28 442.2,33.9 437,31.1 431.7,33.9 432.7,28 428.4,23.9 434.3,23 
  "/>
  </svg>
  `

  const animationPatterns = [
    ['0','1'],['0','1'],['0','1'],['0','1'],['0','1'],['0','1'],['0','1'],
    ['2','2'],['2','2'],['2','2'],['2','2'],
    ['1','1'],['1','1'],['1','1'],['1','1'],
    ['0','2'],['0','2'],
    ['3','5'],['3','5'],
    ['8','9'],['8','9'],
    ['3','6'],['3','6'],
    ['9','10'],['9','10'],
    ['10','10'],['10','10'],
    ['3','7'],
    ['6','7']

  ]
  const wrapper = document.querySelector('.wrapper')
  const grid = document.querySelector('.grid')
  const input = document.querySelector('input')
  const button = document.querySelector('button')
  const instruction = document.querySelector('.instruction')
  const frameSize = 15

  let pos = []
  let mappedPos
  let prevMappedPos = []
  let timer = 5
  let interval

  
  //star blinking animation
  const animateStar = (target, start, end, speed) => {
    let i = start   
    setInterval(function () {
      target.style.margin = `0px ${-(i * frameSize)}px`
      if (i >= end) {
        i = start
      } else {
        i++
      }
    }, speed)
  }


  //position stars
  const stars = new Array(100).fill('')
  stars.forEach(()=>{

    const animationPattern = animationPatterns[Math.floor(Math.random() * animationPatterns.length)]
    const speed = Math.random() < 0.1 ?
      140
      :
      300

    const starDiv = document.createElement('div')
    starDiv.classList.add('star')
    
    const starInside = document.createElement('div')
    starInside.classList.add('star_inner')
    starInside.innerHTML = starSvg
    starInside.style.width = `${frameSize * 11}px`

    starDiv.appendChild(starInside)
    starDiv.style.top = `${Math.ceil(Math.random() * 100)}%`
    starDiv.style.left = `${Math.ceil(Math.random() * 100)}%`
    wrapper.appendChild(starDiv)

    animateStar(starInside, animationPattern[0], animationPattern[1], speed)
  })

  //create grid
  grid.innerHTML = new Array(256).fill('').map((_cell,i)=>{
    return `
      <div class=cell id=${i} >
      </div>
    `
  }).join('')
  wrapper.appendChild(grid)
  const cells = document.querySelectorAll('.cell')


  //create letter
  const createLetter = letter =>{
    const textCode = letter.split('')
    pos = []
    textCode.forEach((cell, i)=> cell === '1' ? pos.push(i) : null)

    mappedPos = pos.map(p=>{
      return {
        x: cells[p].getBoundingClientRect().x,
        y: cells[p].getBoundingClientRect().y
      }
    })
  }
  

  //position
  const setPosition = ()=>{
    const stars = document.querySelectorAll('.star')
  
    stars.forEach((star,i)=>{
      const offsetX = Math.ceil(Math.random() * 5) - 5
      const offsetY = Math.ceil(Math.random() * 5) - 5
      if (i >= mappedPos.length) return
      star.style.top = `${mappedPos[i].y + offsetY}px`
      star.style.left = `${mappedPos[i].x + offsetX}px`
      star.style.opacity = '1'
      star.style.backgroundColor = Math.random() < 0.5 ? 'rgba(195, 232, 253, 0.1)' : ''
    })
  }

  const setRandomPosition = () =>{
    const stars = document.querySelectorAll('.star')
    stars.forEach((star,i)=>{
      if (i >= prevMappedPos.length) return
      star.style.top = `${Math.ceil(Math.random() * 100)}%`
      star.style.left = `${Math.ceil(Math.random() * 100)}%`
      star.style.opacity = '0.3'
      star.style.backgroundColor = 'transparent'
    })
  }

  const readjustPosition = ()=>{
    createLetter(letters[letterIndex.indexOf(currentLetter)])
    setRandomPosition()
    setPosition()
  }
  

  //letter animation
  const animateLetterWithKeyboard = e =>{
    clearInterval(interval)
    const keyPressed = e.key.toUpperCase()
    instruction.style.opacity = 0
    timer = 5
    if (letterIndex.indexOf(keyPressed) === -1) return

    createLetter(letters[letterIndex.indexOf(keyPressed)])
    setRandomPosition()
    setPosition()
    prevMappedPos = mappedPos
    currentLetter = keyPressed
  }
  
  const animateLettersFromInput = (value, index) =>{
    const selectedLetter = value[index].toUpperCase()
    const selectedLetterIndex = letterIndex.indexOf(selectedLetter)
    createLetter(letters[selectedLetterIndex])
    setRandomPosition()
    setPosition()
    prevMappedPos = mappedPos
    currentLetter = selectedLetter
  }

  const triggerAnimateLettersFromInput = ()=>{
    clearInterval(interval)
    const lettersToAnimate = input.value
    let letterCount = 0 
    timer = (input.value.length * 1.5) + 5
    
    interval = setInterval(()=>{
      if (letterCount >= lettersToAnimate.length){
        clearInterval(interval)
        return
      }    
      animateLettersFromInput(lettersToAnimate, letterCount)
      letterCount++
    },1500)
  }

  //event
  document.addEventListener('keydown', animateLetterWithKeyboard)
  window.addEventListener('resize', readjustPosition)
  button.addEventListener('click', triggerAnimateLettersFromInput)

  // initial setup
  createLetter(letters[0])
  setRandomPosition()
  setPosition()
  prevMappedPos = mappedPos
  let currentLetter = letterIndex[0]
  
  // makes instruction appear when no action
  setInterval(()=>{
    if (!timer) return
    timer--
    if (timer === 0) instruction.style.opacity = 1
  },1000)
}

window.addEventListener('DOMContentLoaded', init)
              
            
!
999px

Console