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

              
                <canvas></canvas>

<h1>Frontend Horse</h1>
              
            
!

CSS

              
                canvas {
  position: absolute;
  top: 0;
  left: 0;
}

body {
  display: grid;
  place-items: center;
  height: 100vh;
  width: 100%;
}

h1 {
  color: white;
  font-size: 15vmax;
  text-align: center;
  text-transform: uppercase;
  font-weight: 800;
  letter-spacing: -1vmax;

  pointer-events: none;
  z-index: 1;
  position: relative;
}

              
            
!

JS

              
                const canvas = document.querySelector("canvas");

const canvasImages = [];

const images = [
  "https://images.unsplash.com/photo-1576692194458-ea3f97b227af?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NTc4MjE2MjQ&ixlib=rb-1.2.1&q=80&w=400",
  "https://images.unsplash.com/photo-1534307250431-ef2530a9d8c5?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NTc4MjE2MjQ&ixlib=rb-1.2.1&q=80&w=400",
  "https://images.unsplash.com/photo-1552908768-910f4cd7b201?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NTc4MjE2MjQ&ixlib=rb-1.2.1&q=80&w=400",
  "https://images.unsplash.com/photo-1578001357658-46d0b9d5ec79?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NTc4MjE2MjQ&ixlib=rb-1.2.1&q=80&w=400",

  "https://images.unsplash.com/photo-1517887121-557af22472e1?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NTc4MjE2MjQ&ixlib=rb-1.2.1&q=80&w=400",
  "https://images.unsplash.com/photo-1460999158988-6f0380f81f4d?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NTc4MjE2MjQ&ixlib=rb-1.2.1&q=80&w=400"
];

images.forEach((image) => {
  const canvasImage = new Image();
  canvasImage.src = image;
  canvasImages.push(canvasImage);
});

canvas.width = innerWidth;
canvas.height = innerHeight;

const ctx = canvas.getContext("2d");

const horsePath =
  "M81.9 399.8c44-39.1 68.7-67.6 74.3-85.3 8.3-26.6 30.2-74.6 48.2-74.6 18 0 22.7 28.6 45.4 28.6s21.9-13.9 40.5-7c18.5 7 6.6 11.4 24.3 15.8 17.8 4.5 53.8 12.8 58.2 19.2 4.5 6.3 16.1 33.8 36 33.8 20 0 17.8-10.3 18.9-10.3 1 0 14.7-3.3 20.2-16.6 5.6-13.3 0-27.2 0-31 0-4 2.8-33-12.5-45.5-15.2-12.4-42.9-43.5-48.4-48.2-5.6-4.7-82.3-98-96.7-103.3a208 208 0 0 0-24.1-7.5c4.2-4.5 8.2-6.7 11.9-6.7 3.7 0 7.7 2.2 12.2 6.7-3.5-9.6-7.6-14.4-12.2-14.4h-21c.2-4.4 1.2-10.4 3-18 2.6-11.5 6-17 6-21.6 0-4.8 4-14.7-16.3-3-13.5 7.6-19.2 21.9-17.2 42.6-9.4-10-17-16-22.7-18-8.6-3-44.6-35.5-50.7-35.5-6 0-.5 45.7 11.4 53.5 8 5.1 13.4 10 16.6 14.4l-35.8 7.5a69 69 0 0 0-25.2-7.5c-5.7 0-14.3 1.2-25.7 3.6 9 1.6 16.1 3.5 21.3 5.5 5.2 2 8.5 4.7 10 8l-15.3 7.8c-4.2-3.1-9-5.7-14-7.7-5.3-2-13.2-.5-24 4.7 9.6 1.2 14.1 2.2 13.7 3-.9 1.4-11.1 3.3-10.3 4.5.7 1 4.2 1.3 4.2 2.7 0 2-1.4 5.3-4.2 9.7l-14.4 10c-55.6 73-76.7 137.9-63.2 194.8 13.5 56.9 39.4 85.3 77.6 85.3Z";

let p = new Path2D(horsePath);

function placeImage(ctx, horse, rotation, scale) {
  ctx.save();
  ctx.clip(horse);
  ctx.rotate(-rotation);
  ctx.drawImage(
    gsap.utils.random(canvasImages),
    (-451 / 2) * scale,
    (-451 / 2) * scale,
    451 * scale,
    451 * scale
  );
  ctx.restore();
}
let black = false;

const draw = (x, y) => {
  let horse = new Path2D();

  const scale = gsap.utils.random(0.1, 0.5, 0.1);
  const rotation = gsap.utils.random(0, 6.2832);
  const matrix = {
    a: scale, // Scale X
    b: 0,
    c: 0,
    d: scale, // Scale Y
    e: (scale * -451) / 2, //width / 2
    f: (scale * -400) / 2 //height / 2
  };
  horse.addPath(p, matrix);

  ctx.rotate(-prevRotation);
  ctx.translate(x - prevX, y - prevY);
  ctx.rotate(rotation);

  if (black) {
    ctx.fill(horse);
    black = false;
  } else {
    placeImage(ctx, horse, rotation, scale);
    black = true;
  }

  // ctx.fill(horse);

  // ctx.rotate(rotation);
  prevRotation = rotation;
  ctx.restore();
};

let prevX = 0;
let prevY = 0;
let prevRotation = 0;

function setDraw(e) {
  draw(e.clientX, e.clientY);
  prevX = e.clientX;
  prevY = e.clientY;
}

canvas.addEventListener("mousemove", _.throttle(setDraw, 100), false);

              
            
!
999px

Console