DEV Community

Cover image for Hot Cross Buns
Nicholas Stimpson
Nicholas Stimpson

Posted on

3 1

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

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay