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 id="root"></div>
              
            
!

CSS

              
                // Globals
body,
html {
  margin: 0;
  padding: 0;
  background: #EAF6FF;
  font-family: 'Mukta Malar', sans-serif;
  font-weight: 700;
  overflow: hidden;
}

h1 {
  margin: 0;
  color: white;
  text-transform: uppercase;
  font-size: 8vw;
  text-shadow: 0px 4px #d6e5e3;
}

button {
  display: inline-block;
  padding: 10px;
  margin: 2px;
  font-size: 10px;
  font-weight: 700;
  font-family: 'Mukta Malar', sans-serif;
  text-transform: uppercase;
  color: black;
  background: transparent;
  border-radius: 255px 15px 225px 15px/15px 235px 5px 275px;
  border: 5px solid white;
  cursor: pointer;
  transition: all 0.3s ease;
}
@media (min-width: 650px) {
  button {
    padding: 20px;
    margin: 10px;
    font-size: 14px;
  }
}

button:focus,
button:hover {
  border-color: #1b4353;
  outline: 0;
}

// App wrapper
.app {
  display: flex;
  height: 100vh;
  max-width: 100vh;
  margin: 0 auto;
  align-items: center;
  justify-content: space-around;
  flex-direction: column;
  background: radial-gradient(ellipse at center, #fff 30%, #EAF6FF 47%);
}

// SVG wrapper
.wrapper {
  position: relative;
  height: 400px;
  width: 300px;
}

// Controls wrapper
.controls {
  position: absolute;
  bottom: 5%;
  left: 0;
  right: 0;
  padding: 0 20px;
  text-align: center
}
@media (min-width: 650px) {
  .controls {
    padding: 0;
  }
}

// Sliders (visible when stressed)
.sliders {
  position: fixed;
  right: 0;
  top: 20%;
  width: 100%;
  display: flex;
  justify-content: center;
}
@media (min-width: 650px) {
  .sliders {
    top: 34%;
  }
}

input[type=range] {
  background: #ebf6ff;
  border-radius: 20px;
  margin: 10px;
  -webkit-appearance: none;
  
  &:focus {
    outline: none;
  }
}

input[type=range]::-webkit-slider-thumb {
  height: 20px;
  width: 20px;
  border-radius: 50%;
  background: #a0d9cb;
  cursor: pointer;
  -webkit-appearance: none;
}


// Main character (body and eyes)
.character {
  position: relative;
  
  &__eye {
    transition: transform 0.3s ease;
    transform: translate(10px, 0px);
  }
  
  &__body {
    fill: #a0d8cb;
    transition: transform 0.3s ease;
  }
  
  &__eye.-eye-l-extra {
    transform: translate(34px, -10px)
  }
  
  &.-sleeping {
    .-eye-l-extra {
      visibility: hidden;
      transform: translate(18px, 12px);
    }
    .-eye-l {
      transform: translate(10px, 15px);
    }
    .-eye-r {
      transform: translate(18px, 12px);
    }
  }
  
  &.-passive {
    .-part-1 {
      transform: translate(30px, -10px);
    }
    .-part-2 {
      transform: translate(23px, 3px);
    }
    .-part-3 {
      transform: translate(10px, 3px);
    }
    .-eye-l {
      transform: translate(40px, -10px);
    }
    .-eye-r {
      transform: translate(34px, -10px)
    }
  }
  
  &.-waiting {
    .-part-1 {
      transform: translate(12px, 0px);
    }
    .-part-2 {
      transform: translate(10px, 1px);
    }
    .-part-3 {
      transform: translate(5px, 2px);
    }
    .-eye-l {
      transform: translate(52px, -8px);
    }
    .-eye-r {
      visibility: hidden;
      transform: translate(42px, -7px);
    }
    .-eye-l-extra {
      visibility: visible;
      transform: translate(42px, -7px);
    }
  }
  
  &.-thinking {
    .-part-1 {
      transform: translate(-9px, 5px);
    }
    .-part-2 {
      transform: translate(-5px, 2.5px);
    }
    .-eye-l {
      transform: translate(1px, 10px);
    }
    .-eye-l-extra {
      transform: translate(-1.5px, 10px)
    }
    .-eye-r {
      transform: translate(-1.5px, 10px)
    }
  }
  
  &.-typing {
    .-part-1 {
      transform: translate(-18px, 10px);
    }
    .-part-2 {
      transform: translate(-10px, 5px);
    }
    .-part-3 {
      transform: translate(-4px, 2px);
    }
    .-eye-l {
      transform: translate(2px, 21px);
    }
    .-eye-l-extra {
      visibility: hidden;
      transform: translate(-3px, 20px)
    }
    .-eye-r {
      transform: translate(-3px, 20px)
    }
  }
  
  &.-stressed {
    .-part-1 {
      transform: translate(-17px, 20px);
    }
    .-part-2 {
      transform: translate(-8px, 10px);
    }
    .-part-3 {
      transform: translate(-2px, 4px);
    }
    .-eye-l {
      transform: translate(2px, 41px);
    }
    .-eye-l-extra {
      visibility: hidden;
      transform: translate(-3px, 40px)
    }
    .-eye-r {
      transform: translate(-3px, 40px)
    }
  }
}

// Laptop on table
.computer {
  position: absolute;
  width: 30%;
  top: 49%;
  left: 12%;
  
  &__screen {
    fill: #D6E5E3;
  }
  
  &__keyboard {
    fill: #CACFD6;
  }
  
  &.-typing {
    animation: vibrate 0.6s linear infinite both;
  }
  
  &.-stressed {
    animation: vibrate-crazy 0.5s linear infinite both;
  }
}

// Table
.table {
  position: absolute;
  top: 58%;
  left: -60%;
  fill: #EAF6FF;
  width: 200%;
}

// Various arm variants
.arm {
  position: absolute;
  top: 0;
  left: 0;

  & path {
    fill: none;
    stroke: #eaf6ff;
    stroke-width: 12;
    stroke-linecap: round;
    stroke-miterlimit: 10;
  }
}

.arm-typing-right {
  transform-origin: 200px 168px;
  transform: rotate(140deg);
  // transform: translateY(42%) translateX(155%) rotate(140deg);
}

.arm-typing-left {
 transform-origin: 190px 160px;
  transform: rotate(143deg);
  // transform: translateY(45%) translateX(145%) rotate(143deg);
}

.arm-thinking-right {
  transform-origin: 200px 168px;
  animation: scratch-chin 10s ease 0s infinite normal ;
}


// Animations
@-webkit-keyframes scratch-chin {
  0%{
	  transform: rotate(-40deg);
  }
  5%{
	  transform: rotate(-3deg);
  }
  40%{
	  transform: rotate(0deg);
  }
  50%{
	  transform: rotate(-3deg);
  }
  60%{
	  transform: rotate(0deg);
  }
  80%{
	  transform: rotate(-40deg);
  }
  100%{
	  transform: rotate(-40deg);
  }
}

@keyframes vibrate {
  0% {
    transform: rotate(0deg);
  }
  50% {
    transform: rotate(-1deg);
  }
  100% {
    transform: rotate(0deg);
  }
}

@keyframes vibrate-crazy {
  0% {
    transform: translate(0);
  }
  10% {
    transform: translate(-2px, -2px);
  }
  20% {
    transform: translate(2px, -2px);
  }
  30% {
    transform: translate(-2px, 2px);
  }
  40% {
    transform: translate(2px, 2px);
  }
  50% {
    transform: translate(-2px, -2px);
  }
  60% {
    transform: translate(2px, -2px);
  }
  70% {
    transform: translate(-2px, 2px);
  }
  80% {
    transform: translate(-2px, -2px);
  }
  90% {
    transform: translate(2px, -2px);
  }
  100% {
    transform: translate(0);
  }
}
              
            
!

JS

              
                // Silly svg experiment
// The original idea was an animated "presence indicator"
// i.e "Carl is typing..."
// SVG sine loop based on https://codepen.io/jaromvogel/pen/jWjWqN
// Color scheme: https://coolors.co/009ffd-eaf6ff-cacfd6-d6e5e3-9fd8cb

// Character component
const Character = ({ animation, armPath }) => {
  const characterClass = `character -${animation}`;
  return (
    <svg className={characterClass} xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 400">
      <circle className="character__eye -eye-r" cx="87.59" cy="134.46" r="5.12"/>
      <g id="body">
          <circle className="character__body -part-1" cx="140.71" cy="122.62" r="42.88"/>
          <circle className="character__body -part-2" cx="166.95" cy="141.82" r="42.88"/>
          <circle className="character__body -part-3" cx="191.26" cy="173.82" r="42.88"/>
          <circle className="character__body" cx="197.02" cy="335.1" r="42.88"/>
          <circle className="character__body" cx="197.02" cy="295.42" r="42.88"/>
          <circle className="character__body" cx="206.62" cy="216.06" r="42.88"/>
          <circle className="character__body" cx="205.98" cy="258.94" r="42.88"/>
      </g>
      <circle className="character__eye -eye-l-extra" cx="87.59" cy="134.46" r="5.12"/>
      <circle className="character__eye -eye-l" cx="115.11" cy="134.46" r="5.12"/>
    </svg>
  );
};

// Left arm component
const ArmLeft = ({ animation, armPath }) => (
  <svg className="arm" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 400">
    { animation === 'typing' && <path className="arm-typing-left" d={armPath} /> }
    { animation === 'stressed' && <path className="arm-typing-left" d={armPath} /> }
    { animation === 'waiting' && <path d="M175.27,152.06s55.19,87.24-65.77,74.44" /> }
    { animation === 'thinking' && <path d="M175.93,152.78s-10.18,82-36.43,103.72" /> }
    { animation === 'passive' && <path d="M175.93,152.78s-10.18,82-36.43,103.72" /> }
    { animation === 'sleeping' && <path d="M175.93,152.78s-10.18,82-36.43,103.72" /> }
  </svg>
);

// Right arm component
const ArmRight = ({ animation, armPath }) => (
  <svg className="arm" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 400">
    { animation === 'typing' && <path className="arm-typing-right" d={armPath} /> }
    { animation === 'stressed' && <path className="arm-typing-right" d={armPath} /> }
    { animation === 'waiting' && <path d="M207.26,171.26s45.19,85-75.76,72.24" /> }
    { animation === 'thinking' && <path className="arm-thinking-right" d="M207.48,172.34s-76,114.16-93-9.84" /> }
    { animation === 'passive' && <path d="M207.93,172c.57-.48,11.3,86.45-23.43,112.52" /> }
    { animation === 'sleeping' && <path d="M207.93,172c.57-.48,11.3,86.45-23.43,112.52" /> }
  </svg>
);

// Computer component
const Computer = ({ animation }) => {
  const computerClass = `computer -${animation}`;
  return (
    <svg className={computerClass} xmlns="http://www.w3.org/2000/svg" viewBox="0 0 82 55">
      <polygon className="computer__keyboard" points="29,42.5 81,51.5 45,55.5 30,49.5 "/>
      <path className="computer__keyboard" d="M80.3,55.5H45.7c-0.9,0-1.7-0.7-1.7-1.7v-0.7c0-0.9,0.7-1.7,1.7-1.7h34.7c0.9,0,1.7,0.7,1.7,1.7v0.7
        C82,54.8,81.2,55.5,80.3,55.5z"/>
      <path className="computer__screen" d="M38.9,55.4l-27.3-6.3c-1.6-0.4-2.8-1.6-3.1-3.2l-8.4-41C-0.5,2.2,1.7-0.2,4.5,0l27.4,2.5
        c1.8,0.2,3.3,1.5,3.7,3.3l8.3,44.8C44.4,53.6,41.8,56.1,38.9,55.4z"/>
    </svg>
  );
};

// Table component
const Table = () => (
  <svg className="table" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 530 160.1">
    <polygon points="530,65.8 197.7,0 0,10.6 274.9,160.1 " />
  </svg>
);

class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      animation: "sleeping",
      armPath: "M 207 171",
      frequency: 3,
      amplitude: 0.1,
      xstart: 207,
      ystart: 171,
      length: 110,
      offset: 0,
      fps: 60,
    };
    this.createCurve = this.createCurve.bind(this);
    this.setAnimation = this.setAnimation.bind(this);
    this.setConfig = this.setConfig.bind(this);
    this.updateArms = this.updateArms.bind(this);
    this.loop = this.loop.bind(this);
    this.loopref = null;
  }
  
  createCurve(x, offset, inverted = false) {
    const { frequency, ystart, xstart, amplitude } = this.state;
    const phase = inverted ? Math.sqrt(x*frequency) - offset : Math.sqrt(x*frequency) + offset;
    return ystart - (Math.sin(phase)) * (x-xstart) * amplitude;
  }
  
  updateArms() {
    const { ystart, xstart, length } = this.state;
    let x = xstart;
		let dataL = `M ${xstart} ${ystart}`;
    let dataR = `M ${xstart} ${ystart}`;

		while (x < xstart + length) {
			const newYL = this.createCurve(x, this.state.offset);
      const newYR = this.createCurve(x, this.state.offset, true);
			dataL = `${dataL} L ${x} ${newYL}`;
      dataR = `${dataR} L ${x} ${newYR}`;
			x += 1;
		}
    this.setState({
      armPathL: dataL,
      armPathR: dataR,
    })
  }
  
  loop() {
    const { offset, animation, fps } = this.state;
    if (animation !== "typing" && animation !== "stressed") {
      clearTimeout(this.loopRef);
      return;
    }
    this.setState({
      offset: offset + 0.3,
    })
    this.updateArms();
    this.loopRef = setTimeout(() => {
      requestAnimationFrame(this.loop);	
    },(1000 / fps));
  }
  
  setAnimation(newAnimation, speed) {
    this.setState({
      animation: newAnimation,
      fps: speed || 60,
    })
    if (newAnimation === "typing" || newAnimation === "stressed") {
      clearTimeout(this.loopRef);
      requestAnimationFrame(this.loop);	
    }
  }
  
  setConfig(e) {
    const type = e.target.name;
    console.log(type);
    this.setState({
      [type]: e.target.value,
    })
  }
  
  render() {
    const { frequency, amplitude, animation } = this.state;
    return (
      <div className="app">
        <h1>Wormco</h1>
        <div className="wrapper">
          <ArmLeft animation={this.state.animation} armPath={this.state.armPathL} />
          <Character animation={this.state.animation} />
          <ArmRight animation={this.state.animation} armPath={this.state.armPathR} />
          <Table />
          <Computer animation={this.state.animation} />
        </div>
        <div className="controls">
          <button onClick={() => this.setAnimation('passive')}>Passive</button>
          <button onClick={() => this.setAnimation('waiting')}>Waiting</button>
          <button onClick={() => this.setAnimation('thinking')}>Thinking</button>
          <button onClick={() => this.setAnimation('typing')}>Typing</button>
          <button onClick={() => this.setAnimation('stressed', 240)}>Nailing it</button>
        </div>
        { animation === 'stressed' &&
          <div className="sliders">
            <input
              type="range"
              step="0.01"
              name="frequency"
              value={frequency}
              onChange={this.setConfig}
              min="0"
              max="10"
            />
            <input
              type="range"
              step="0.01"
              name="amplitude"
              value={amplitude}
              onChange={this.setConfig}
              min="0.05"
              max="2"
            />
          </div>
        }
      </div>
    );
  }
}

ReactDOM.render(
	<App />,
  document.getElementById('root')
);
              
            
!
999px

Console