Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
108 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import {RED, ORANGE, YELLOW, GREEN, BLUE, PURPLE, PINK, WHITE, BLACK, GRAY, BROWN} from './constants.js'; | ||
import Artifier from './Artifier.js'; | ||
|
||
class BasicColorTerminalHsl extends Artifier { | ||
constructor() { | ||
super(); | ||
this.colorsForCanvas = [RED, ORANGE, YELLOW, GREEN, BLUE, PURPLE, PINK, WHITE, BLACK, GRAY, BROWN] | ||
this.colors = this.colorsForCanvas.map(this.rgbToHsl); | ||
} | ||
|
||
artFunction(ctx, width, height) { | ||
const imageData = ctx.getImageData(0, 0, width, height).data; | ||
const colors = this.colors; | ||
let newImageArray = []; | ||
|
||
for (let h = 0; h < height; h++) { | ||
for (let w = 0; w < width; w++) { | ||
let currentRgb = this.getPixelAt(h, w, width, imageData); | ||
|
||
if (currentRgb[3] !== 255) { | ||
currentRgb = this.rgbaToRgb(currentRgb); | ||
} | ||
|
||
const current = this.rgbToHsl(currentRgb) | ||
|
||
let closest; | ||
let minDist = 1000000000; // temporary | ||
for (let i = 0; i < colors.length; i++) { | ||
let color = colors[i]; | ||
let redDiff = color[0] - current[0]; | ||
let greenDiff = color[1] - current[1]; | ||
let blueDiff = color[2] - current[2] | ||
let dist = (redDiff * redDiff) + (greenDiff * greenDiff) + (blueDiff * blueDiff); | ||
if (dist < minDist) { | ||
minDist = dist; | ||
closest = i; | ||
} | ||
} | ||
this.mergeArrays(newImageArray, this.colorsForCanvas[closest]); | ||
} | ||
} | ||
return new Uint8ClampedArray(newImageArray); | ||
} | ||
} | ||
|
||
const bct = new BasicColorTerminalHsl(); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<!doctype html> | ||
|
||
<html> | ||
|
||
<head> | ||
<title>huemanities</title> | ||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<script src="bcthsl-bundle.js" type="text/javascript"></script> | ||
<link rel="stylesheet" type="text/css" href="huemanity.css"> | ||
</head> | ||
|
||
<body> | ||
<header> | ||
<h1>basic color terminal (hsl)</h1> | ||
</header> | ||
|
||
<div class="Content"> | ||
<div class="UploadWrapper"> | ||
<label class="Label" for="photo">Upload a picture!</label> | ||
<input type="file" name="photo" class="Uploader" /> | ||
</div> | ||
<canvas class="Canvas"></canvas> | ||
</div> | ||
|
||
<footer class="Footer"> | ||
<h2>Cool, what's it do?</h2> | ||
<p>All the pixels are "rounded" to whatever English | ||
<a target="_blank" href="https://en.wikipedia.org/wiki/Color_term#Basic_colour_terms">"basic color term"</a> (think Crayola marker ten-pack + white) | ||
<a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/CSS/color_value">CSS color</a> is the closest based on the | ||
<a target="_blank" href="https://en.wikipedia.org/wiki/Euclidean_distance">Euclidean distance</a> between their | ||
<a target="_blank" href="https://en.wikipedia.org/wiki/RGB_color_model">HSL</a> values. | ||
</p> | ||
<p>Is this a reasonable thing to do? Who knows.</p> | ||
<p><a target="_blank" href="https://github.com/jennazee/huemanities">Code</a></p> | ||
</footer> | ||
</body> | ||
|
||
</html> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters