Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <!-- <div style="position: absolute;">WIP</div> -->
<div id="app"></div>

              
            
!

CSS

              
                body {
  height: 100vh;
}

#app {
  height: 100vh;
}

              
            
!

JS

              
                const NUM_OF_BARS = 10;
const MAX_RENDA = 18;

const BACK_ALPHA = 0.2;
const FRONT_ALPHA = 0.8;

class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      countPerSec: 0,
      ceil: 0
    };
  }
  render() {
    const App = window.styled.div`
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      height: 100vh;
    `;
    const SiiyaButton = window.styled.button`
      flex: 1 1 auto;
      width: 20em;
      background-color: #eefeba;
      font-family: "M PLUS Rounded 1c";
      margin-top: 3px;
      transition: all 1s ease;
      &:hover {
        background-color: #efabaa;
      }
    `;
    return (
      <App>
        <Bars
          countPerSec={this.state.countPerSec}
          numOfBars={NUM_OF_BARS}
          ceil={this.state.ceil}
        />
        <SiiyaButton onClick={() => this.pound()}>連打しや</SiiyaButton>
      </App>
    );
  }
  pound() {
    const currentTime = performance.now();
    if (this.lastTime == null) {
      this.lastTime = currentTime;
    } else {
      const delta = currentTime - this.lastTime;
      this.lastTime = currentTime;
      // calc hz
      const cPerSec = (1 / delta) * 1000;
      if (cPerSec > this.state.ceil) {
        this.setState({
          countPerSec: cPerSec,
          ceil: cPerSec
        });
      } else {
        this.setState({
          countPerSec: cPerSec
        });
      }
    }
  }
}

class Bars extends React.Component {
  render() {
    const bars = [];
    const delta = Math.floor(255 / this.props.numOfBars);
    const progress = Math.floor(
      (this.props.countPerSec / MAX_RENDA) * NUM_OF_BARS
    );
    for (let i = 0; i < this.props.numOfBars; i++) {
      const rr = i * delta;
      const gg = 20;
      const bb = 255 - rr;
      const alpha = i < progress ? FRONT_ALPHA : BACK_ALPHA;
      const code = `#${hexColor(rr)}${hexColor(gg)}${hexColor(bb)}`;
      bars.push(<Bar key={code} rr={rr} gg={gg} bb={bb} alpha={alpha} />);
    }
    const Bars = window.styled.div`
      display: flex;
      flex-direction: column-reverse;
      flex: 3 1 auto;
      width: 20em;
    `;
    const Count = window.styled.div`
      position: absolute;
      top: 14px;
      left: 0;
      right: 0;
      text-align: center;
      font-size: 2em;
      font-family: "Nico Moji", "M PLUS Rounded 1c";
    `;
    return (
      <Bars>
        <Count>
          {this.props.countPerSec.toFixed(2)}回/s
          <br />
          MAX:{this.props.ceil.toFixed(2)}回/s
        </Count>
        {bars}
      </Bars>
    );
  }
}

class Bar extends React.Component {
  render() {
    let changeAlpha = null;
    if (this.props.alpha >= 0.5) {
      changeAlpha = window.styled.keyframes`
        from {
          background-color: rgba(${this.props.rr}, ${this.props.gg}, ${this.props.bb}, ${this.props.alpha});
        }
        to {
          background-color: rgba(${this.props.rr}, ${this.props.gg}, ${this.props.bb}, ${BACK_ALPHA});
        }
      `;
    }
    const Bar = window.styled.div`
      flex: 1 1 auto;
      background-color: rgba(${this.props.rr}, ${this.props.gg}, ${this.props.bb}, ${BACK_ALPHA});
      animation: ${changeAlpha} 1s linear;
    `;
    return <Bar></Bar>;
  }
}

function hexColor(c) {
  if (c < 256) {
    if (c < 16) {
      return "0" + Math.abs(c).toString(16);
    }
    return Math.abs(c).toString(16);
  }
  return 0;
}

ReactDOM.render(<App />, document.getElementById("app"));

              
            
!
999px

Console