Compare commits
No commits in common. '264367cef14bcb4f17c143b2377affe1cfd8680f' and '04356237ae1c9fdc6b38601ceac2653069ca5018' have entirely different histories.
264367cef1
...
04356237ae
@ -1,35 +0,0 @@
|
|||||||
---
|
|
||||||
draft: true
|
|
||||||
title: "Deterministically Mapping Strings to RGB Colors"
|
|
||||||
aliases: ["Deterministically Mapping Strings to RGB Colors"]
|
|
||||||
date: "2025-1-25"
|
|
||||||
series: ["strings-to-colors"]
|
|
||||||
series_order: 0
|
|
||||||
author: "Nick Dumas"
|
|
||||||
authorTwitter: ""
|
|
||||||
cover: ""
|
|
||||||
tags: ["golang"]
|
|
||||||
keywords: ["golang"]
|
|
||||||
summary: "Using Go so I don't have to think about color palettes."
|
|
||||||
showFullContent: false
|
|
||||||
---
|
|
||||||
{{< lead >}} {{ </ lead >}}
|
|
||||||
|
|
||||||
## The Plan
|
|
||||||
- Take an arbitrary UTF-8 string
|
|
||||||
- Generate an RGB or RGBA color code for it in a deterministic way
|
|
||||||
- SHA1 the string
|
|
||||||
- Interpret equally sized chunks of the hash as integers
|
|
||||||
- Scale those integers into an 8-bit space
|
|
||||||
## The Implementation
|
|
||||||
## The Results
|
|
||||||
Below is a sample of the "lorum ipsum" text with each word colored using this algorithm.
|
|
||||||
|
|
||||||
<p><span style="color:#FDC749;">Lorem</span> <span style="color:#D39A85;">ipsum</span> <span style="color:#452D59;">dolor</span> <span style="color:#3A852F;">sit</span> <span style="color:#0454D4;">amet</span>, <span style="color:#886B09;">consectetur</span> <span style="color:#31A0E5;">adipiscing</span> <span style="color:#99215D;">elit</span>. </p>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Possible Improvements
|
|
||||||
- Provide HSV or HSL color values
|
|
||||||
- Light/dark mode awareness
|
|
||||||
- Accessibility. The colors chosen are effectively random with no regard for color schemes, background, display device capability
|
|
Loading…
Reference in New Issue