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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

              
                <p>Make some <strong>NOISE</strong>, see what happend!</p>
<div class="wrapper">
 <?xml version="1.0" encoding="UTF-8"?>
<svg width="304px" height="285px" viewBox="0 0 304 285" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
    <!-- Generator: Sketch 52.2 (67145) - http://www.bohemiancoding.com/sketch -->
    <title>shy-elf</title>
    <desc>Created with Sketch.</desc>
    <defs>
        <rect id="path-1" x="29" y="30" width="245" height="245"></rect>
        <filter x="-6.1%" y="-6.1%" width="112.2%" height="112.2%" filterUnits="objectBoundingBox" id="filter-2">
            <feOffset dx="0" dy="0" in="SourceAlpha" result="shadowOffsetOuter1"></feOffset>
            <feGaussianBlur stdDeviation="1" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
            <feColorMatrix values="0 0 0 0 0   0 0 0 0 0   0 0 0 0 0  0 0 0 0.2 0" type="matrix" in="shadowBlurOuter1"></feColorMatrix>
        </filter>
    </defs>
    <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
        <g id="Artboard" transform="translate(-235.000000, -100.000000)">
            <g id="shy-elf" transform="translate(235.000000, 100.000000)">
                <g id="pygmie-1" transform="translate(51.000000, 0.000000)">
                    <path d="M12.8142857,22.8164042 L12.8142857,34 L10.1857143,34 L10.1857143,22.8164042 C4.45751199,22.1906942 7.21898318e-16,17.3370548 0,11.4423077 C-7.73904773e-16,5.12289565 5.12289565,-6.1549968e-16 11.4423077,-1.77635684e-15 L11.5576923,-1.77635684e-15 C17.8771043,-2.937214e-15 23,5.12289565 23,11.4423077 C23,17.3370548 18.542488,22.1906942 12.8142857,22.8164042 Z" id="Combined-Shape" fill="#000000"></path>
                    <g id="Group" transform="translate(6.000000, 7.000000)" fill="#FFFFFF">
                        <rect id="Rectangle-Copy" x="0" y="0" width="2.66666667" height="3" rx="1.33333333"></rect>
                        <rect id="Rectangle-Copy-2" x="9.33333333" y="0" width="2.66666667" height="3" rx="1.33333333"></rect>
                    </g>
                </g>
                <g id="pygmie-2" transform="translate(89.000000, 0.000000)">
                    <path d="M12.8142857,22.8164042 L12.8142857,34 L10.1857143,34 L10.1857143,22.8164042 C4.45751199,22.1906942 7.21898318e-16,17.3370548 0,11.4423077 C-7.73904773e-16,5.12289565 5.12289565,-6.1549968e-16 11.4423077,-1.77635684e-15 L11.5576923,-1.77635684e-15 C17.8771043,-2.937214e-15 23,5.12289565 23,11.4423077 C23,17.3370548 18.542488,22.1906942 12.8142857,22.8164042 Z" id="Combined-Shape" fill="#000000"></path>
                    <g id="Group" transform="translate(6.000000, 7.000000)" fill="#FFFFFF">
                        <rect id="Rectangle-Copy" x="0" y="0" width="2.66666667" height="3" rx="1.33333333"></rect>
                        <rect id="Rectangle-Copy-2" x="9.33333333" y="0" width="2.66666667" height="3" rx="1.33333333"></rect>
                    </g>
                </g>
                <g id="pygmie-3" transform="translate(146.000000, 0.000000)">
                    <path d="M12.8142857,22.8164042 L12.8142857,34 L10.1857143,34 L10.1857143,22.8164042 C4.45751199,22.1906942 7.21898318e-16,17.3370548 0,11.4423077 C-7.73904773e-16,5.12289565 5.12289565,-6.1549968e-16 11.4423077,-1.77635684e-15 L11.5576923,-1.77635684e-15 C17.8771043,-2.937214e-15 23,5.12289565 23,11.4423077 C23,17.3370548 18.542488,22.1906942 12.8142857,22.8164042 Z" id="Combined-Shape" fill="#000000"></path>
                    <g id="Group" transform="translate(6.000000, 7.000000)" fill="#FFFFFF">
                        <rect id="Rectangle-Copy" x="0" y="0" width="2.66666667" height="3" rx="1.33333333"></rect>
                        <rect id="Rectangle-Copy-2" x="9.33333333" y="0" width="2.66666667" height="3" rx="1.33333333"></rect>
                    </g>
                </g>
                <g id="pygmie-4" transform="translate(218.000000, 0.000000)">
                    <path d="M12.8142857,22.8164042 L12.8142857,34 L10.1857143,34 L10.1857143,22.8164042 C4.45751199,22.1906942 7.21898318e-16,17.3370548 0,11.4423077 C-7.73904773e-16,5.12289565 5.12289565,-6.1549968e-16 11.4423077,-1.77635684e-15 L11.5576923,-1.77635684e-15 C17.8771043,-2.937214e-15 23,5.12289565 23,11.4423077 C23,17.3370548 18.542488,22.1906942 12.8142857,22.8164042 Z" id="Combined-Shape" fill="#000000"></path>
                    <g id="Group" transform="translate(6.000000, 7.000000)" fill="#FFFFFF">
                        <rect id="Rectangle-Copy" x="0" y="0" width="2.66666667" height="3" rx="1.33333333"></rect>
                        <rect id="Rectangle-Copy-2" x="9.33333333" y="0" width="2.66666667" height="3" rx="1.33333333"></rect>
                    </g>
                </g>
                <g id="pygmie-5" transform="translate(286.500000, 51.000000) rotate(90.000000) translate(-286.500000, -51.000000) translate(275.000000, 34.000000)">
                    <path d="M12.8142857,22.8164042 L12.8142857,34 L10.1857143,34 L10.1857143,22.8164042 C4.45751199,22.1906942 7.21898318e-16,17.3370548 0,11.4423077 C-7.73904773e-16,5.12289565 5.12289565,-6.1549968e-16 11.4423077,-1.77635684e-15 L11.5576923,-1.77635684e-15 C17.8771043,-2.937214e-15 23,5.12289565 23,11.4423077 C23,17.3370548 18.542488,22.1906942 12.8142857,22.8164042 Z" id="Combined-Shape" fill="#000000"></path>
                    <g id="Group" transform="translate(6.000000, 7.000000)" fill="#FFFFFF">
                        <rect id="Rectangle-Copy" x="0" y="0" width="2.66666667" height="3" rx="1.33333333"></rect>
                        <rect id="Rectangle-Copy-2" x="9.33333333" y="0" width="2.66666667" height="3" rx="1.33333333"></rect>
                    </g>
                </g>
                <g id="pygmie-6" transform="translate(287.000000, 152.500000) rotate(90.000000) translate(-287.000000, -152.500000) translate(275.500000, 135.500000)">
                    <path d="M12.8142857,22.8164042 L12.8142857,34 L10.1857143,34 L10.1857143,22.8164042 C4.45751199,22.1906942 7.21898318e-16,17.3370548 0,11.4423077 C-7.73904773e-16,5.12289565 5.12289565,-6.1549968e-16 11.4423077,-1.77635684e-15 L11.5576923,-1.77635684e-15 C17.8771043,-2.937214e-15 23,5.12289565 23,11.4423077 C23,17.3370548 18.542488,22.1906942 12.8142857,22.8164042 Z" id="Combined-Shape" fill="#000000"></path>
                    <g id="Group" transform="translate(6.000000, 7.000000)" fill="#FFFFFF">
                        <rect id="Rectangle-Copy" x="0" y="0" width="2.66666667" height="3" rx="1.33333333"></rect>
                        <rect id="Rectangle-Copy-2" x="9.33333333" y="0" width="2.66666667" height="3" rx="1.33333333"></rect>
                    </g>
                </g>
                <g id="pygmie-7" transform="translate(287.000000, 196.500000) rotate(90.000000) translate(-287.000000, -196.500000) translate(275.500000, 179.500000)">
                    <path d="M12.8142857,22.8164042 L12.8142857,34 L10.1857143,34 L10.1857143,22.8164042 C4.45751199,22.1906942 7.21898318e-16,17.3370548 0,11.4423077 C-7.73904773e-16,5.12289565 5.12289565,-6.1549968e-16 11.4423077,-1.77635684e-15 L11.5576923,-1.77635684e-15 C17.8771043,-2.937214e-15 23,5.12289565 23,11.4423077 C23,17.3370548 18.542488,22.1906942 12.8142857,22.8164042 Z" id="Combined-Shape" fill="#000000"></path>
                    <g id="Group" transform="translate(6.000000, 7.000000)" fill="#FFFFFF">
                        <rect id="Rectangle-Copy" x="0" y="0" width="2.66666667" height="3" rx="1.33333333"></rect>
                        <rect id="Rectangle-Copy-2" x="9.33333333" y="0" width="2.66666667" height="3" rx="1.33333333"></rect>
                    </g>
                </g>
                <g id="pygmie-8" transform="translate(17.000000, 173.500000) rotate(-90.000000) translate(-17.000000, -173.500000) translate(5.500000, 156.500000)">
                    <path d="M12.8142857,22.8164042 L12.8142857,34 L10.1857143,34 L10.1857143,22.8164042 C4.45751199,22.1906942 7.21898318e-16,17.3370548 0,11.4423077 C-7.73904773e-16,5.12289565 5.12289565,-6.1549968e-16 11.4423077,-1.77635684e-15 L11.5576923,-1.77635684e-15 C17.8771043,-2.937214e-15 23,5.12289565 23,11.4423077 C23,17.3370548 18.542488,22.1906942 12.8142857,22.8164042 Z" id="Combined-Shape" fill="#000000"></path>
                    <g id="Group" transform="translate(6.000000, 7.000000)" fill="#FFFFFF">
                        <rect id="Rectangle-Copy" x="0" y="0" width="2.66666667" height="3" rx="1.33333333"></rect>
                        <rect id="Rectangle-Copy-2" x="9.33333333" y="0" width="2.66666667" height="3" rx="1.33333333"></rect>
                    </g>
                </g>
                <g id="pygmie-9" transform="translate(17.000000, 106.500000) rotate(-90.000000) translate(-17.000000, -106.500000) translate(5.500000, 89.500000)">
                    <path d="M12.8142857,22.8164042 L12.8142857,34 L10.1857143,34 L10.1857143,22.8164042 C4.45751199,22.1906942 7.21898318e-16,17.3370548 0,11.4423077 C-7.73904773e-16,5.12289565 5.12289565,-6.1549968e-16 11.4423077,-1.77635684e-15 L11.5576923,-1.77635684e-15 C17.8771043,-2.937214e-15 23,5.12289565 23,11.4423077 C23,17.3370548 18.542488,22.1906942 12.8142857,22.8164042 Z" id="Combined-Shape" fill="#000000"></path>
                    <g id="Group" transform="translate(6.000000, 7.000000)" fill="#FFFFFF">
                        <rect id="Rectangle-Copy" x="0" y="0" width="2.66666667" height="3" rx="1.33333333"></rect>
                        <rect id="Rectangle-Copy-2" x="9.33333333" y="0" width="2.66666667" height="3" rx="1.33333333"></rect>
                    </g>
                </g>
                <g id="pygmie-10" transform="translate(17.000000, 252.500000) rotate(-90.000000) translate(-17.000000, -252.500000) translate(5.500000, 235.500000)">
                    <path d="M12.8142857,22.8164042 L12.8142857,34 L10.1857143,34 L10.1857143,22.8164042 C4.45751199,22.1906942 7.21898318e-16,17.3370548 0,11.4423077 C-7.73904773e-16,5.12289565 5.12289565,-6.1549968e-16 11.4423077,-1.77635684e-15 L11.5576923,-1.77635684e-15 C17.8771043,-2.937214e-15 23,5.12289565 23,11.4423077 C23,17.3370548 18.542488,22.1906942 12.8142857,22.8164042 Z" id="Combined-Shape" fill="#000000"></path>
                    <g id="Group" transform="translate(6.000000, 7.000000)" fill="#FFFFFF">
                        <rect id="Rectangle-Copy" x="0" y="0" width="2.66666667" height="3" rx="1.33333333"></rect>
                        <rect id="Rectangle-Copy-2" x="9.33333333" y="0" width="2.66666667" height="3" rx="1.33333333"></rect>
                    </g>
                </g>
                <g id="board">
                    <use fill="black" fill-opacity="1" filter="url(#filter-2)" xlink:href="#path-1"></use>
                    <use fill="#FFFFFF" fill-rule="evenodd" xlink:href="#path-1"></use>
                </g>
            </g>
        </g>
    </g>
</svg>
</div>
              
            
!

CSS

              
                *{
  margin:0;
  padding:0;
  box-sizing:border-box;
}
html, body {
    width: 100%;
    height: 100%;
    font-family: "PingFangSC-light","Segoe UI", "Lucida Grande", "Ubuntu", "Roboto", "Helvetica Neue", "Helvetica", "Arial", sans-serif;
}
body {
    margin: 0;
}
.wrapper {
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    padding: 40px;
    position: relative;
}
svg {
    width:50vw;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
/*     opacity: 0; */
}
p{
  display:inline-block;
  text-align:center;
  border-left:10px orange solid;
  padding-left:15px;
  margin-top:20px;
  strong{
    color:orange;
  }
}
              
            
!

JS

              
                  'use strict';

var ctx, analyser, frequencies, getByteFrequencyDataAverage,draw;

// 兼容性
window.AudioContext = window.AudioContext || window.webkitAudioContext;
// 获取音频上下文
ctx = new window.AudioContext();

// 用户获取stream当中的时间、频率信息
analyser = ctx.createAnalyser();
frequencies = new Uint8Array(analyser.frequencyBinCount);
getByteFrequencyDataAverage = function() {
  // 将当前频域数据拷贝进数组
    analyser.getByteFrequencyData(frequencies);
  // 求得频域的平均值
    return frequencies.reduce(function(previous, current) {
        return previous + current;
    }) / analyser.frequencyBinCount;
};

// 返回 Promise 对象
navigator.mediaDevices.getUserMedia({audio: true})
    .then(function(stream) {
        // window.hackForMozzila = stream;
        ctx.createMediaStreamSource(stream)
          // 连接到AnalyserNode
          .connect(analyser);
    })
    .catch(function(err) {
        console.log(err.message);
    });


var pygmies = [];
for(let i = 0;i < 10;i++){
  pygmies.push(document.getElementById(`pygmie-${i+1}`));
}
console.log(pygmies);

// 改变小人的位置
(draw = function() {
  var moveValue = getByteFrequencyDataAverage()*10;
  if(moveValue >= 35){
    moveValue = 35;
  }
  pygmies[0].style.transform = `translate(51.000000px, ${moveValue}px)`;
    console.log(getByteFrequencyDataAverage());
  pygmies[1].style.transform = `translate(89.000000px, ${0.000000+moveValue}px)`;
    pygmies[2].style.transform = `translate(149.000000px, ${0.000000+moveValue}px)`;
  pygmies[3].style.transform = `translate(218.000000px, ${0.000000+moveValue}px)`;
  pygmies[4].style.transform = `translate(286.500000px, 51.000000px) rotate(90.000000deg) translate(-286.500000px, -51.000000px) translate(275.000000px, ${34.000000+moveValue}px)`;
  pygmies[5].style.transform = `translate(286.500000px, 152.000000px) rotate(90.000000deg) translate(-286.500000px, -152.000000px) translate(275.000000px, ${135.500000+moveValue}px)`;
    pygmies[6].style.transform = `translate(286.500000px, 196.5000000px) rotate(90.000000deg) translate(-286.500000px, -196.500000px) translate(275.000000px, ${179.500000+moveValue}px)`;
    pygmies[7].style.transform = `translate(17.500000px, 173.500000px) rotate(-90.000000deg) translate(-17.00000px, -173.500000px) translate(5.500000px, ${156.500000+moveValue}px)`;
    pygmies[8].style.transform = `translate(17.000000px, 106.500000px) rotate(-90.000000deg) translate(-17.00000px, -106.500000px) translate(5.500000px, ${89.500000+moveValue}px)`;
    pygmies[9].style.transform = `translate(17.00000px, 252.500000px) rotate(-90.000000deg) translate(-17.00000px, -252.500000px) translate(5.500000px, ${235.500000+moveValue}px)`;
    requestAnimationFrame(draw);
})();
              
            
!
999px

Console