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

              
                <svg viewBox="0 0 3000 2300" fill="none" xmlns="http://www.w3.org/2000/svg" id="container">
  <defs>
    <filter id='scribble'>
      <feturbulence basefrequency='0.05' id='turbulence' numoctaves='2' result='noise' seed='0'></feturbulence>
      <fedisplacementmap id='displacement' in2='noise' in='SourceGraphic' scale='3'></fedisplacementmap>
    </filter>

    <filter id='pencil-filter'>
      <feturbulence basefrequency='0.05' id='turbulence' numoctaves='2' result='noise' seed='0'></feturbulence>
      <feOffset result="offOut" in="SourceAlpha" dx="2" dy="5" />
      <feColorMatrix result="matrixOut" in="offOut" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .5 0" />
      <feGaussianBlur result="blurOut" in="matrixOut" stdDeviation="4" />
      <feBlend in="SourceGraphic" in2="blurOut" mode="normal" result="newGraphic" />
      <fedisplacementmap id='displacement' in2='noise' in='newGraphic' scale='3'></fedisplacementmap>
    </filter>

    <mask id="pencil-mask">
      <path d="M2 158C2 134.5 36 11 38 4.5s8.5-4 10.5 0S92 148.5 92 158v371a24 24 0 0 1-24 24H26a24 24 0 0 1-24-24V158Z" fill="#fff" />
      <rect y="480" x="1.5" width="90" fill="#fff" rx="35" ry="20" height="950" />
    </mask>

    <g id="pencil-source" mask="url(#pencil-mask)">

      <rect y="0" x="0" width="90" fill="black" rx="15" ry="15" height="1435" style="fill: var(--fill-color);" />
      <path d="M69.5 74C80.6 112.1 92 153 92 158v1a61 61 0 0 0-20-4c-5.4 0-9.5 2.8-14.3 6.1-6.8 4.7-15 10.4-30.2 10.4-10.7 0-18.3-7-25.5-15 .6-12.5 8-44.8 16-76.5 17.3 7.4 39 9.3 51.5-6Z" style="fill: var(--wood-color);" />
      <path opacity=".07" fill="#171D22" d="M0 25h28v1410H0z" />
      <path opacity=".16" fill="#171D22" d="M67 47h27v1388H67z" />
    </g>
    <g id="space-scribble">
      <path id="space-scribble-path" d="m211 1496-95-2c-19 0-40-1-52-20 42-7 107-13 149-20-2-14-15-17-25-17l-178-3c-1-5 4-9 8-11 56-26 154-13 210-37-4-11-15-13-24-13l-181 1c59-10 152-21 211-31l-221-9c80-45 144-18 222-67-81-12-144 12-224-12l224-43-228-9 87-17c34-6 89-13 121-27l-194-1c32-22 89-21 124-27 29-5 57-15 85-24l-218-3c60-19 122-34 163-46 16-5 45-10 60-18-64-20-154 0-219 6 52-24 144-49 197-64-47 12-135 11-183 14 46-22 122-40 171-52-57 0-134-1-191-5 12-13 28-17 43-22 51-14 118-24 169-32H71c-18 0-37 0-54-7 65-18 151-13 212-48-57 2-130 1-187-3 44-17 126-31 171-42-55 5-146 5-201 4 66-19 151-39 217-58l-157-1c-15 0-31 0-46 5 63-26 145-52 210-60H60c-17 0-33 0-48 7 54-10 155-22 208-38-55-1-128-2-183 2 46-4 110-17 153-40 11-6 22-12 34-13-63 15-147-4-209 14 47-15 98-25 146-30 21-2 44-3 64-14-75-1-142-14-217-8 81-14 149-53 231-58-78 19-150-17-228 1 34-14 62-23 98-27 40-4 81-1 120-16-74 19-149-8-224-5 71-22 155-23 223-57-22 0-44 1-66-1l-63-7c-28-2-56 2-84 6 64-37 150-32 218-52-14-4-29-4-43-4l-172-1 165-33c15-3 29-6 43-14-16 4-32 4-48 4-50 0-115 0-165-2 9-6 20-6 30-6 57 0 129-9 185-27-65 3-144 5-207-11 65-18 146-31 212-39-61-5-151-4-212 3 10-9 22-13 33-17 23-8 59-11 82-16l91-22-210-5c53-30 145-36 203-44L12 97l206-37H33c51-21 114-17 165-35L116 6" style="stroke: var(--stroke-color);" stroke-width="6" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round" />
    </g>
  </defs>

  <g class="spaces">
    <rect y="0" height="2300" fill="#000" class="space space-0" data-index="0" />
    <rect y="0" height="2300" fill="#000" class="space space-1" data-index="1" />
    <rect y="0" height="2300" fill="#000" class="space space-2" data-index="2" />
    <rect y="0" height="2300" fill="#000" class="space space-3" data-index="3" />
    <rect y="0" height="2300" fill="#000" class="space space-4" data-index="4" />
    <rect y="0" height="2300" fill="#000" class="space space-5" data-index="5" />
    <rect y="0" height="2300" fill="#000" class="space space-6" data-index="6" />
    <rect y="0" height="2300" fill="#000" class="space space-7" data-index="7" />
    <rect y="0" height="2300" fill="#000" class="space space-8" data-index="8" />
    <rect y="0" height="2300" fill="#000" class="space space-9" data-index="9" />
    <rect y="0" height="2300" fill="#000" class="space space-10" data-index="10" />
  </g>

  <g class="scribbles">
    <path d="M89.3 5c-20 .2-71 1.3-83.5 24.4C-6.8 53 128.5 56.1 129.5 59.7c2.8 9.7-65.1 40.3-71.5 45-19.3 14.2 2.8 14.4 16.3 16.7" />
    <path d="M80 23.8c-20 0-44-4.3-59.1 12-11 11.9-10.9 36.6-1 48 16.7 19.6 70.1 27.3 71.5-10.4.6-16.8-16-52.6-35.7-57-8.3-1.8-18.5 2.6-26-2.2C20.6 8.6 15.6 5 5 5" />
    <path d="M37.2 5C24.3 5-9.3 4 11.8 26.7 19.5 35 54.2 47.1 39 53.8c-48 21.3-6.7 76.9-28.2 112.7" />
    <path d="M22.7 19c-3.4.5-27.4 8.6-13.3 8.6 20 0 39.5-2.6 59.2-5.5 6.3-.9 16.3-4.5 6.8 1-10 6-20.6 11-31 16.3-8 4-18 7.7-23.6 14.8-6.2 7.9 39.3 7.8 44 7.8 4.3.1 2.4 1.2-.5 2.4-14.7 6-29.1 13-42 22.3-6 4.2-12.7 12.1-6.4 19.4 5.2 6.1 19.7 8 27 8.8 2.9.3 12.6-1.2 5.4 1-3.7 1.3-8.6 3.2-11.7 5.6-1 .7-.9-3.5-1-4.9-.5-11.1-2.2-22.2-2.7-33.3-1-19.5 0-38.6 2.4-58 .3-2.7.1-17 1-16.3A23.8 23.8 0 0 0 69 8.4c6.6-6-5-2.5-7.7-1.3a66.1 66.1 0 0 0-25.4 24c-11.7 16.6-6.2 33.6 8.6 46.4 4.3 3.7 12.2 7.5 14.8 13C61.6 95 42 104 40 105.8c-19.9 16-.9 23.7 16 28.6 10.7 3.2 21.8 5.3 32.7 7.6 3.3.7 11.5 0 9.6 2.8-.8 1.2-6.3.2-7.8.6-.6.2-3.7 1.2-1.8 1.2" />
    <path d="M12.5 5c2.7 16.7 11.3 35.8 11.3 51.7 0 14.2-5 25-8 38.4C11.5 114.5 5 131.2 5 151.4" />
    <path d="M47.8 5c-72.5 0-36.6 55.8-10 85.2 24.2 26.6-27.3 37.6-27.3 61.9" />
    <path d="M47.2 155.2C24.4 125.4 5 108.5 33.7 76.5c15.9-17.7 11-51.2 6-71.5m-30 7.5c-6.5 16.6-7.8 24.2 6.2 35.7C23.8 54.6 43 56.7 47.2 65" />
    <path d="M22.1 106.4c19.5-8.1 30-14 30-35.5 0-14.4-8.6-15-18.7-24.6-8-7.5-18.7-4.5-22.5-16.9C6.4 14.8-2.8 10.3 18.4 5" />
    <path d="M5 5c20.4 15.8 44.4 35.5 57.2 58.4C66.7 71.7 73.4 81 80 87.6m7.5-75C65 23.3 32.8 32.4 14.2 50c-9 8.5-5.4 26.4-5.4 37.5" />
    <path d="M5 86.9c15.6-17 32.8-31.4 45.7-50.7 6.6-9.9 13-19.9 20-29.5 6-8.2 7 15 7 19.9 0 11.1 3.2 22.2 3.2 33 0 3 .3 17.6-2 8.8-3-11.8-13.3-22.8-18.2-34-2.7-6.3-6.7-13.1-7.7-20-1.3-10.4 7.4 2.3 10.8 5C77.6 30 87 35 93.3 52c1.4 4 5.7 16.7 10.7 16.7" />
    <path d="M51.5 5a87.6 87.6 0 0 0-31.8 17.7C10.2 30.4 49 25.5 52.6 25c2.3-.3 14-4 10.8 2-3.2 6.1-9.5 10.5-13.4 16.3-1 1.5-8.6 12.4-5.2 14 5 2.5 15.3-2.3 20.4-3.6 7.1-2 1.2 1.7-2.1 4.6-8.5 7.3-18.2 12-25 21.3-3.4 4.6-9.7 21.7 2.8 17.9 6.3-2 12.1-7 17-11.2.1 0 6-4.5 5.8-4-1.2 4.9-16 15.5-11 6.9 2.8-4.8 17.1-15 13.4-21.2-8.2-14-29.6-17.2-39.5-29.8-6.2-8-6.7-16.1-6.7-25.8 0-9.5-8.1-1.1-12.3 2.2C-2.8 23.1 21 31.2 25.5 33.4c11.5 5.5 25.4 7.2 36.2 14 3.6 2.3 2.6 5.3.6 8.4-4.3 6.8-17.7 20-10.8 27.8 4.9 5.5 15 7.4 22 8.6 2.4.4 4.1-.4 5.2 1.7" />
  </g>

  <g class="space-scribbles">
    <use href="#space-scribble" class="space-scribble space-scribble-white" data-space-scribble="0" />
    <use href="#space-scribble" class="space-scribble space-scribble-pink" data-space-scribble="1" />
    <use href="#space-scribble" class="space-scribble space-scribble-lightblue" data-space-scribble="2" />
    <use href="#space-scribble" class="space-scribble space-scribble-brown" data-space-scribble="3" />
    <use href="#space-scribble" class="space-scribble space-scribble-black" data-space-scribble="4" />
    <use href="#space-scribble" class="space-scribble space-scribble-red" data-space-scribble="5" />
    <use href="#space-scribble" class="space-scribble space-scribble-orange" data-space-scribble="6" />
    <use href="#space-scribble" class="space-scribble space-scribble-yellow" data-space-scribble="7" />
    <use href="#space-scribble" class="space-scribble space-scribble-green" data-space-scribble="8" />
    <use href="#space-scribble" class="space-scribble space-scribble-navy" data-space-scribble="9" />
    <use href="#space-scribble" class="space-scribble space-scribble-purple" data-space-scribble="10" />
  </g>

  <g class="pencils">

    <g class="pencil" data-index="0">
      <use href="#pencil-source" class="pencil-instance" />
    </g>
    <g class="pencil" data-index="1">
      <use href="#pencil-source" class="pencil-instance" />
    </g>
    <g class="pencil" data-index="2">
      <use href="#pencil-source" class="pencil-instance" />
    </g>
    <g class="pencil" data-index="3">
      <use href="#pencil-source" class="pencil-instance" />
    </g>
    <g class="pencil" data-index="4">
      <use href="#pencil-source" class="pencil-instance" />
    </g>
    <g class="pencil" data-index="5">
      <use href="#pencil-source" class="pencil-instance" />
    </g>
    <g class="pencil" data-index="6">
      <use href="#pencil-source" class="pencil-instance" />
    </g>
    <g class="pencil" data-index="7">
      <use href="#pencil-source" class="pencil-instance" />
    </g>
    <g class="pencil" data-index="8">
      <use href="#pencil-source" class="pencil-instance" />
    </g>
    <g class="pencil" data-index="9">
      <use href="#pencil-source" class="pencil-instance" />
    </g>
    <g class="pencil" data-index="10">
      <use href="#pencil-source" class="pencil-instance" />
    </g>

  </g>
</svg>
              
            
!

CSS

              
                :root {
  --fill-color: #f7eae2;
  --wood-color: #dab28e;
  --start: 100;
  --space: 170;
  --white: #f7eae2;
  --pink: #f498c0;
  --lightblue: #7cc0ea;
  --brown: #603917;
  --black: #231f1f;
  --red: #ee3124;
  --orange: #f57f29;
  --yellow: #fff000;
  --green: #58b947;
  --navy: #0054a6;
  --purple: #9f248f;
}

$colors: white, pink, lightblue, brown, black, red, orange, yellow, green, navy,
  purple;

* {
  box-sizing: border-box;
}

body {
  display: grid;
  place-items: center;
  height: 100vh;
  width: 100vw;
  background-color: #f5ebe2;
  background-image: url("https://assets.codepen.io/1385231/moonpaper.jpg");
}

svg {
  height: auto;
  max-width: 99vw;
  max-height: 99vh;
  opacity: 0;
}

.space {
  --width: calc(3000px / 11);
  width: var(--width);
  opacity: 0;
}

.pencil {
  x: 0;
  filter: url(#pencil-filter);
}

.scribbles,
.space-scribbles {
  filter: url(#scribble);
  & path {
    transform-origin: bottom center;
    stroke: var(--fill-color, black);
    stroke-width: 9;
    stroke-linecap: round;
  }
}

.space-scribble {
  stroke-dasharray: 12248;
  stroke-dashoffset: 12248;
  transition: all 2s;
}

.space-scribble.win {
  stroke-dashoffset: 0;
}

@for $i from 0 through 10 {
  .space-#{$i} {
    x: calc(#{$i} * var(--width));
  }
}
.mask-rect {
  height: 950;
}

@for $i from 1 through length($colors) {
  .pencil:nth-child(#{length($colors)}n + #{$i}) {
    background: nth($colors, $i);
    --fill-color: var(--#{nth($colors, $i)});
    --index: #{$i};
  }

  .space-scribble:nth-child(#{length($colors)}n + #{$i}) {
    --stroke-color: var(--#{nth($colors, $i)});
  }

  .scribbles > path:nth-child(#{length($colors)}n + #{$i}) {
    --fill-color: var(--#{nth($colors, $i)});
    --index: #{$i};
  }
}

              
            
!

JS

              
                const container = document.querySelector("#container");
const pencilContainer = document.querySelector(".pencils");
const pencilHeight = 1435;
const pencilWidth = 90;

const scribblePathLength = 12248;

const gridWidth = 3000;
const gridHeight = 2300;
const gridCount = 11;
const spaceWidth = gridWidth / gridCount;

function checkEndState() {
  const index = this.target.dataset.index;
  const space = document.querySelector(`.space-${index}`);
  const spaceScribble = document.querySelector(
    `[data-space-scribble="${index}"]`
  );
  if (this.hitTest(space)) {
    gsap.to(this.target, {
      y: Math.round(gridHeight / 2 - pencilHeight / 2),
      x: index * spaceWidth + spaceWidth / 2 - pencilWidth / 2
    });
    spaceScribble.classList.add("win");
  } else {
    spaceScribble.classList.remove("win");
  }
}

function init() {
  gsap.set(".pencil", {
    transformOrigin: "center",
    x: "random(0, 3000)",
    y: "random(0, 1000)"
  });

  gsap.set(".pencil-instance", {
    rotate: "random(0, 360)",
    transformOrigin: "center"
  });

  gsap.set(".scribbles > *", {
    x: (i) => i * spaceWidth + spaceWidth / 2 - 20,
    y: 250
  });

  gsap.set(".space-scribble", {
    x: (i) => i * spaceWidth,
    y: 450,
    rotate: "180deg",
    transformOrigin: "center"
  });

  gsap.to("#container", { opacity: 1 });

  Draggable.create(".pencil", {
    bounds: container,
    inertia: true,
    onDragStart: (e) => {
      gsap.to(e.target, { rotate: 0, duration: 1.5, ease: "back.out(1.4)" });
    },
    liveSnap: {
      radius: 1
    },
    onDragEnd: checkEndState,
    onThrowComplete: checkEndState
  });
}

init();

              
            
!
999px

Console