alohci

Nicholas Stimpson

Posted on March 29, 2024

Hot Cross Buns

This is a submission for DEV Challenge v24.03.20, CSS Art: Favorite Snack.

Inspiration

Easter is a time for Hot Cross Buns

Demo

(Note that codepen is quite slow in displaying this image)

OK, here's the thing. While I consider myself competent at CSS, my artistic skill is close to zero. So I cheated.

While the image created in the codepen above is formed in CSS, the text-shadow was not hand written. I photographed some real hot cross buns, loaded it in a canvas

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

const image = new Image();
image.src = "...";
image.addEventListener("load", () => {
  ctx.drawImage(image, 0, 0, 100, 100);

  const imageData = ctx.getImageData(0, 0, 100, 100);
  ...;
});

Enter fullscreen mode Exit fullscreen mode

I then looped over the image data pixel by pixel, and wrote it back out as a text-shadow.

  const data = imageData.data;
  let fs = 1;
  let d = 0;
  let ts = [];
  for (let y = 0; y < imageData.height; y++) {
    for (let x = 0; x < imageData.width; x++, d+=4) {
      ts.push((x * fs - 50) + 'vmin ' + (y * fs - 50) + 'vmin ' 
         + '0vmin rgba('
         + data[d] + ', ' 
         + data[d + 1] + ', ' 
         + data[d + 2] + ', ' 
         + data[d + 3] / 255 + ')');
    }
  }
  console.log(ts.join());
Enter fullscreen mode Exit fullscreen mode

The text-shadow is of a single character - the Unicode Character 'BLACK SQUARE' β€œβ– β€ (U+25A0) with a transparent colour.

Licence: CC-BY

πŸ’– πŸ’ͺ πŸ™… 🚩
alohci
Nicholas Stimpson

Posted on March 29, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Space Art Challenge - CSS Art
frontendchallenge Space Art Challenge - CSS Art

September 15, 2024

CSS Art: Space - Solar System Exploration
frontendchallenge CSS Art: Space - Solar System Exploration

September 16, 2024

CSS Art: Space - UFO animation
frontendchallenge CSS Art: Space - UFO animation

September 16, 2024

Sunrise in Space (Quiet)
frontendchallenge Sunrise in Space (Quiet)

September 8, 2024

Frontend Challenge: Space Trucking.
frontendchallenge Frontend Challenge: Space Trucking.

September 13, 2024