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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <canvas id="canvas"></canvas>
  <div class="manz">
    <img src="https://manzdev.github.io/twitch-matrix-canvas/matrix.gif" alt="Manztrix">
    <div>ENTER TO THE <a href="https://manz.dev/">MANZ.DEV</a></div>
  </div>

<div class="created">
  <span>Created by</span>
  <a href="https://manz.dev/"><h2>Manz.dev</h2></a>
  <p>on <a href="https://twitch.tv/ManzDev">Twitch</a> / <a href="https://youtu.be/">Youtube</a></p>
</div>
              
            
!

CSS

              
                @use postcss-nested;

@font-face {
  font-family: "Comic Sans MS";
  src:
    url("https://manzdev.github.io/twitch-matrix-canvas/fonts/comic-sans-ms.woff2") format("woff2"),
    url("https://manzdev.github.io/twitch-matrix-canvas/fonts/comic-sans-ms.woff") format("woff");
}

@font-face {
  font-family: "Bebas Neue";
  src:
    url("https://manzdev.github.io/twitch-matrix-canvas/fonts/bebas-neue.woff2") format("woff2"),
    url("https://manzdev.github.io/twitch-matrix-canvas/fonts/bebas-neue.woff") format("woff");
}

body {
  background: #000;
  margin: 0;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

.manz {
  position: absolute;
  top: calc(50% - 200px);
  left: calc(50% - 400px);
  width: 800px;
  height: 400px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
}

.manz img {
  transform: scale(1);
  image-rendering: pixelated;
  clip-path: inset(5%);
}

.manz div {
  width: 800px;
  height: 105px;
  text-align: center;
  font-family: "Bebas Neue", monospace;
  font-size: 92px;
  color: #fff;
  background: #000e;
  text-shadow: 0 0 10px #0f0;
  box-shadow: 0 0 10px 4px #0f0;
}

.manz a {
  color: #0f0;
  text-shadow: 0 0 35px #0f0;
  text-decoration: none;
}

.moved {
  transform: translate(10px, 10px);
}

.color {
  filter: hue-rotate(250deg);
}

.manz div.comic {
  font-family: "Comic Sans MS", sans-serif;
  font-size: 53px;
  line-height: 190%;
}

.created {
  background: 
    url(https://assets.codepen.io/154065/internal/avatars/users/default.png),
    linear-gradient(to bottom, #884ced, #ec1cce);
  background-size: 75px 75px, cover;
  background-repeat: no-repeat;
  position: absolute;
  top: 0;
  right: 0;
  width: 250px;
  height: 75px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-left: 2em;
  
  & span,
  & h2,
  & p,
  & a {
    font-family: Montserrat;
    margin: 0;
  }
  
  & a,
  & p,
  & span {
    color: #fff;    
  }
  
  & h2 {
    font-weight: 700;
    transform: translate(0, -4px);    
  }
  
  & a {
    text-decoration-color: rgba(255,255,255,0.4);
  }
  
  & a:hover {
    color: #e6e82a;
  }
}
              
            
!

JS

              
                const canvas = document.querySelector("#canvas");
const ctx = canvas.getContext("2d");
const columns = [];

const TEXT_HEIGHT = 20;
const LAYERS = 2;
let WIDTH = canvas.width = innerWidth;
let HEIGHT = canvas.height = innerHeight;
let totalColumns = Math.floor(WIDTH / TEXT_HEIGHT) + 1;

const music = new Howl({
  src: ["https://manzdev.github.io/twitch-matrix-canvas/loop-music-connection.mp3"],
  loop: true
});

const glitch = new Howl({
  src: ["https://manzdev.github.io/twitch-matrix-canvas/glitch.mp3"],
  loop: false
});

// patch resize codepen
addEventListener("resize", () => {
  totalColumns = Math.floor(WIDTH / TEXT_HEIGHT) + 1;
  WIDTH = canvas.width = innerWidth;
  HEIGHT = canvas.height = innerHeight;
});

const text = new URL(location.href).searchParams.get("text");

if (text) {
  document.querySelector(".manz div").textContent = text;
}

let font = "monospace";

const toggleFont = () => {
  font = font === "monospace" ? "Comic Sans MS" : "monospace";
  document.querySelector(".manz div").classList.toggle("comic");
};

const moveCanvas = () => {
  document.body.classList.add("moved");
  document.body.classList.add("color");
  setTimeout(() => document.body.classList.remove("moved"), 300);
  setTimeout(() => document.body.classList.remove("color"), 600);
};

const generateCharacter = () => {
  const CHARACTERS = Array.from(Array(94)).map((char, index) => String.fromCharCode(33 + index));
  const randomIndex = Math.floor(Math.random() * CHARACTERS.length);
  return CHARACTERS[randomIndex];
};

const init = () => {
  for (let i = 0; i < totalColumns * LAYERS; i++) {
    const size = Math.floor(Math.random() * 12) + 15;
    const letters = Array.from(Array(size)).map(char => generateCharacter());
    const initialY = -1000 + (-1 * Math.floor(Math.random() * 500));
    const fastRandomSpeed = ~~(Math.random() * 20);
    const speed = fastRandomSpeed === 0 ? 40 : 10 + Math.random() * 20;
    columns.push({
      y: initialY,
      letters,
      speed
    });
  }
  music.play();

  // Reset
  ctx.fillStyle = "black";
  ctx.fillRect(0, 0, WIDTH, HEIGHT);
};

const getColor = (index, array, x) => {
  const size = array.length;
  const COLORS = [
    "#0f01",
    "#0f02",
    "#0f05",
    "#0f0f",
    "#ffff",
  ];
  const last = index === size - 1;
  const first = index === 0;
  const second = index === 1;
  const third = index === 2;

  const color = last
    ? COLORS[4]
    : first
      ? COLORS[0]
      : second
        ? COLORS[1]
        : third
          ? COLORS[2]
          : COLORS[3];

  const alpha = x % 4
    ? "f"
    : x % 3 ? "6" : "2";

  return color.split("").slice(0, -1).join("") + alpha;
};

const matrixIteration = () => {
  ctx.fillStyle = "#000";
  ctx.fillRect(0, 0, WIDTH, HEIGHT);

  ctx.font = `18pt ${font}`;

  columns.forEach((data, x) => {
    data.letters.forEach((letter, index, array) => {
      const isWhite = index === array.length - 1;
      ctx.fillStyle = getColor(index, array, x);
      ctx.shadowColor = "#2aa144";
      ctx.shadowOffsetX = 0;
      ctx.shadowOffsetY = 0;
      if (!navigator.userAgent.includes("Firefox/"))
        ctx.shadowBlur = 10;
      isWhite && (letter = generateCharacter());
      const random = Math.floor(Math.random() * 25);
      random === 0 && (letter = generateCharacter());
      ctx.fillText(letter, x * (TEXT_HEIGHT / LAYERS), 50 + data.y + index * TEXT_HEIGHT);
    });

    data.y += data.speed;
    if (data.y > HEIGHT) {
      data.y = -500;
      data.letters = Array.from(Array(data.letters.length)).map(char => generateCharacter());
    }
  });
};

init();
setInterval(matrixIteration, 50);
setInterval(() => {
  moveCanvas();
  music.volume(0);
  setTimeout(() => (music.volume(1)), 500);
  glitch.play();
  toggleFont();
}, 12000);

              
            
!
999px

Console