Home Web Front-end CSS Tutorial From Typewriters to Pixels: A Journey with CMYK, RGB, and Building a Color Visualizer

From Typewriters to Pixels: A Journey with CMYK, RGB, and Building a Color Visualizer

Sep 13, 2024 pm 08:17 PM

When I was a kid, I published a fanzine about comics. This was long before I had a computer—it was created using a typewriter, paper, and scissors!

The fanzine was initially in black and white, photocopied at my school. Over time, as it gained more success, I was able to afford offset printing with color covers!

However, managing those colors was quite challenging. Each cover had to be printed four times, once for each color: cyan, magenta, yellow, and key (black) — abbreviated as CMYK.

This meant I had to provide four separate sheets, each printed in black ink, but corresponding to a specific color.

Here’s one of the issues I published:

From Typewriters to Pixels: A Journey with CMYK, RGB, and Building a Color Visualizer

All the yellow you see in the image above was hand-painted by me using black ink on the “yellow” sheet. For the skin tones, I used something called “raster dots.” These were sheets you could buy with black dots of varying densities. You would cut out the dots and apply them — in this case, to the “red” sheet.

I worked on a light table — a glass-topped drawing table with built-in lighting — so I could see through the various sheets while aligning them correctly.

It was very time-consuming, but it sparked a lifelong interest in understanding colors — and the huge difference between print- and screen colors!

While CMYK is limited to four colors, it’s still relatively easy to grasp. We’ve all used colored pencils on paper and have an intuitive sense of how colors mix. CMYK is a subtractive color model. You start with a white sheet of paper, and as you add more ink, you’re actually subtracting light. Combining all colors moves you toward black. If you don’t apply any ink, the paper stays white because it reflects all light.

When I got my first computer, I had to understand RGB, which is very different from CMYK. RGB is an additive color model used for digital screens. Here, you’re mixing light itself — adding more light makes the colors brighter and moves you toward white. Turn off all the RGB lights (R=0, G=0, B=0), and the screen goes black because there’s no light emitted.

As a graphic designer back then, you had to calibrate your screen because the colors you saw on the screen and those you saw in print were often very different!


Visualizing RGB

RGB represents three light sources: red, green, and blue. When a light is off, its value is 0; when it’s fully on, its value is 255. When these lights overlap, they create different colors.

To better understand how RGB works, let’s build a small tool:

From Typewriters to Pixels: A Journey with CMYK, RGB, and Building a Color Visualizer


HTML

<fieldset class="rgb">
  <label class="r">
    R:<input
      type="number"
      name="r"
      min="0"
      max="255"
      value="255"
  /></label>
  <label class="g">
    G:<input
      type="number"
      name="g"
      min="0"
      max="255"
      value="255"
  /></label>
  <label class="b">
    B:<input
      type="number"
      name="b"
      min="0"
      max="255"
      value="255"
  /></label>
  <output class="rg">R+G</output>
  <output class="rb">R+B</output>
  <output class="gb">G+B</output>
</fieldset>
Copy after login

Styles

First, let’s create a 9x8 grid:

.rgb {
  all: unset;
  aspect-ratio: 9 / 8;
  container-type: inline-size;
  display: grid;
  font-size: 1.75cqi;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
}
Copy after login

It’s an unusual size, but that's because our R, G and B circles are 5x5 and overlap:

.r, .g, .b {
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  display: grid;
  font-size: 5cqi;
  mix-blend-mode: difference;
}
Copy after login

The CSS for .r, .g and .b is:

.r {
  background-color: rgb(var(--r), 0, 0);
  grid-area: 1 / 3 / 6 / 8;
}

.g {
  background-color: rgb(0, var(--g), 0);
  grid-area: 4 / 1 / 9 / 6;
}

.b {
  background-color: rgb(0, 0, var(--b));
  grid-area: 4 / 5 / 9 / 10;
}
Copy after login

I’ve used grid-area a lot lately. It lets you place a grid item at a very specific location:

row-start / col-start / row-end / col-end

It’s easier to visualize this if you enable Dev Tools’ grid visualizer:

From Typewriters to Pixels: A Journey with CMYK, RGB, and Building a Color Visualizer

Did you notice the three CSS Custom Properties, --r, --g and --b? We’ll update these in a small JS snippet:

const rgb = document.querySelector('.rgb');
rgb.addEventListener('input', e => {
  const N = e.target;
  document.body.style.setProperty(`--${N.name}`, N.value);
})
Copy after login

And that’s basically it. I’ve added some -elements and minor adjustments … but I almost forgot to mention the single most important line to make the visualizer work:

mix-blend-mode: difference

Read about it here — it’s great fun to loop through all the modes.


Demo

Here’s a Codepen. Click and edit the numbers below R, G and B, and notice how the page background and the overlapping parts of all three circles change.

The above is the detailed content of From Typewriters to Pixels: A Journey with CMYK, RGB, and Building a Color Visualizer. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Vue 3 Vue 3 Apr 02, 2025 pm 06:32 PM

It&#039;s out! Congrats to the Vue team for getting it done, I know it was a massive effort and a long time coming. All new docs, as well.

Building an Ethereum app using Redwood.js and Fauna Building an Ethereum app using Redwood.js and Fauna Mar 28, 2025 am 09:18 AM

With the recent climb of Bitcoin’s price over 20k $USD, and to it recently breaking 30k, I thought it’s worth taking a deep dive back into creating Ethereum

Can you get valid CSS property values from the browser? Can you get valid CSS property values from the browser? Apr 02, 2025 pm 06:17 PM

I had someone write in with this very legit question. Lea just blogged about how you can get valid CSS properties themselves from the browser. That&#039;s like this.

A bit on ci/cd A bit on ci/cd Apr 02, 2025 pm 06:21 PM

I&#039;d say "website" fits better than "mobile app" but I like this framing from Max Lynch:

Stacked Cards with Sticky Positioning and a Dash of Sass Stacked Cards with Sticky Positioning and a Dash of Sass Apr 03, 2025 am 10:30 AM

The other day, I spotted this particularly lovely bit from Corey Ginnivan’s website where a collection of cards stack on top of one another as you scroll.

Using Markdown and Localization in the WordPress Block Editor Using Markdown and Localization in the WordPress Block Editor Apr 02, 2025 am 04:27 AM

If we need to show documentation to the user directly in the WordPress editor, what is the best way to do it?

Comparing Browsers for Responsive Design Comparing Browsers for Responsive Design Apr 02, 2025 pm 06:25 PM

There are a number of these desktop apps where the goal is showing your site at different dimensions all at the same time. So you can, for example, be writing

Why are the purple slashed areas in the Flex layout mistakenly considered 'overflow space'? Why are the purple slashed areas in the Flex layout mistakenly considered 'overflow space'? Apr 05, 2025 pm 05:51 PM

Questions about purple slash areas in Flex layouts When using Flex layouts, you may encounter some confusing phenomena, such as in the developer tools (d...

See all articles