-
Notifications
You must be signed in to change notification settings - Fork 0
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
11 changed files
with
257 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2023 mineejo. All rights reserved. MIT license. | ||
|
||
import { Color } from "../../color.ts"; | ||
import { matrixColor } from "../matrix_color.ts"; | ||
|
||
/** | ||
* ### Example | ||
* | ||
* ```ts | ||
* const red = new Color(false, 255, 0, 0); | ||
* console.log(achromatopsiaColor(red).components); // [76.24..., 76.24..., 76.24...] | ||
* ``` | ||
*/ | ||
export function achromatopsiaColor(color: Color): Color { | ||
// deno-fmt-ignore | ||
return matrixColor(color, [ | ||
0.299, 0.588, 0.114, | ||
0.299, 0.588, 0.114, | ||
0.299, 0.588, 0.114, | ||
]) | ||
} |
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,21 @@ | ||
// Copyright 2023 mineejo. All rights reserved. MIT license. | ||
|
||
import { Color } from "../../color.ts"; | ||
import { matrixColor } from "../matrix_color.ts"; | ||
|
||
/** | ||
* ### Example | ||
* | ||
* ```ts | ||
* const red = new Color(false, 255, 0, 0); | ||
* console.log(deuteranomalyColor(red).components); // [204, 65.79, 0] | ||
* ``` | ||
*/ | ||
export function deuteranomalyColor(color: Color): Color { | ||
// deno-fmt-ignore | ||
return matrixColor(color, [ | ||
0.8, 0.2, 0, | ||
0.258, 0.742, 0, | ||
0, 0.142, 0.858, | ||
]) | ||
} |
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,21 @@ | ||
// Copyright 2023 mineejo. All rights reserved. MIT license. | ||
|
||
import { Color } from "../../color.ts"; | ||
import { matrixColor } from "../matrix_color.ts"; | ||
|
||
/** | ||
* ### Example | ||
* | ||
* ```ts | ||
* const red = new Color(false, 255, 0, 0); | ||
* console.log(deuteranopiaColor(red).components); // [159.37..., 178.5, 0] | ||
* ``` | ||
*/ | ||
export function deuteranopiaColor(color: Color): Color { | ||
// deno-fmt-ignore | ||
return matrixColor(color, [ | ||
0.625, 0.375, 0, | ||
0.7, 0.3, 0, | ||
0, 0.3, 0.7, | ||
]) | ||
} |
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,9 @@ | ||
// Copyright 2023 mineejo. All rights reserved. MIT license. | ||
|
||
export { achromatopsiaColor } from "./achromatopsia_color.ts"; | ||
export { deuteranomalyColor } from "./deuteranomaly_color.ts"; | ||
export { deuteranopiaColor } from "./deuteranopia_color.ts"; | ||
export { protanomalyColor } from "./protanomaly_color.ts"; | ||
export { protanopiaColor } from "./protanopia_color.ts"; | ||
export { tritanomalyColor } from "./tritanomaly_color.ts"; | ||
export { tritanopiaColor } from "./tritanopia_color.ts"; |
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,92 @@ | ||
// Copyright 2023 mineejo. All rights reserved. MIT license. | ||
|
||
import { Color } from "../../color.ts"; | ||
import * as originalFilters from "./mod.ts"; | ||
import { assertEquals } from "../../dev_deps.ts"; | ||
import { truncComponents } from "../../advanced_color_test.ts"; | ||
|
||
// deno-lint-ignore no-explicit-any | ||
const filters = originalFilters as any; | ||
|
||
// deno-lint-ignore no-explicit-any | ||
const functionValues: any = { | ||
achromatopsiaColor: [ | ||
[76, 76, 76], | ||
[149, 149, 149], | ||
[29, 29, 29], | ||
], | ||
deuteranomalyColor: [ | ||
[204, 65, 0], | ||
[51, 189, 36], | ||
[0, 0, 218], | ||
], | ||
deuteranopiaColor: [ | ||
[159, 178, 0], | ||
[95, 76, 76], | ||
[0, 0, 178], | ||
], | ||
protanomalyColor: [ | ||
[208, 84, 0], | ||
[46, 170, 31], | ||
[0, 0, 223], | ||
], | ||
protanopiaColor: [ | ||
[144, 142, 0], | ||
[110, 112, 61], | ||
[0, 0, 193], | ||
], | ||
tritanomalyColor: [ | ||
[246, 0, 0], | ||
[8, 186, 46], | ||
[0, 68, 208], | ||
], | ||
tritanopiaColor: [ | ||
[242, 0, 0], | ||
[12, 110, 121], | ||
[0, 144, 133], | ||
], | ||
}; | ||
|
||
Deno.test("color blindness functions correct", async (t) => { | ||
const red: Color = new Color(false, 255, 0, 0); | ||
const green: Color = new Color(false, 0, 255, 0); | ||
const blue: Color = new Color(false, 0, 0, 255); | ||
const white: Color = new Color(false, 255, 255, 255); | ||
const black: Color = new Color(false, 0, 0, 0); | ||
|
||
for (const filter in originalFilters) { | ||
const func = filters[filter]; | ||
|
||
await t.step(`${func.name} function correct`, () => { | ||
assertEquals( | ||
truncComponents(func(red)), | ||
functionValues?.[func.name]?.[0], | ||
`"truncComponents(func(red))"`, | ||
); | ||
|
||
assertEquals( | ||
truncComponents(func(green)), | ||
functionValues?.[func.name]?.[1], | ||
`"truncComponents(func(green))"`, | ||
); | ||
|
||
assertEquals( | ||
truncComponents(func(blue)), | ||
functionValues?.[func.name]?.[2], | ||
`"truncComponents(func(blue))"`, | ||
); | ||
|
||
assertEquals( | ||
truncComponents(func(white)), | ||
[255, 255, 255], | ||
`"truncComponents(func(white))"`, | ||
); | ||
|
||
assertEquals( | ||
truncComponents(func(black)), | ||
[0, 0, 0], | ||
`"truncComponents(func(black))"`, | ||
); | ||
}); | ||
} | ||
}); |
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,21 @@ | ||
// Copyright 2023 mineejo. All rights reserved. MIT license. | ||
|
||
import { Color } from "../../color.ts"; | ||
import { matrixColor } from "../matrix_color.ts"; | ||
|
||
/** | ||
* ### Example | ||
* | ||
* ```ts | ||
* const red = new Color(false, 255, 0, 0); | ||
* console.log(protanomalyColor(red).components); // [208.33..., 84.91..., 0] | ||
* ``` | ||
*/ | ||
export function protanomalyColor(color: Color): Color { | ||
// deno-fmt-ignore | ||
return matrixColor(color, [ | ||
0.817, 0.183, 0, | ||
0.333, 0.667, 0, | ||
0, 0.125, 0.875, | ||
]) | ||
} |
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,21 @@ | ||
// Copyright 2023 mineejo. All rights reserved. MIT license. | ||
|
||
import { Color } from "../../color.ts"; | ||
import { matrixColor } from "../matrix_color.ts"; | ||
|
||
/** | ||
* ### Example | ||
* | ||
* ```ts | ||
* const red = new Color(false, 255, 0, 0); | ||
* console.log(protanopiaColor(red).components); // [144.58..., 142.29, 0] | ||
* ``` | ||
*/ | ||
export function protanopiaColor(color: Color): Color { | ||
// deno-fmt-ignore | ||
return matrixColor(color, [ | ||
0.567, 0.433, 0, | ||
0.558, 0.442, 0, | ||
0, 0.242, 0.758, | ||
]) | ||
} |
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,21 @@ | ||
// Copyright 2023 mineejo. All rights reserved. MIT license. | ||
|
||
import { Color } from "../../color.ts"; | ||
import { matrixColor } from "../matrix_color.ts"; | ||
|
||
/** | ||
* ### Example | ||
* | ||
* ```ts | ||
* const red = new Color(false, 255, 0, 0); | ||
* console.log(tritanomalyColor(red).components); // [246.58..., 0, 0] | ||
* ``` | ||
*/ | ||
export function tritanomalyColor(color: Color): Color { | ||
// deno-fmt-ignore | ||
return matrixColor(color, [ | ||
0.967, 0.033, 0, | ||
0, 0.733, 0.267, | ||
0, 0.183, 0.817, | ||
]) | ||
} |
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,21 @@ | ||
// Copyright 2023 mineejo. All rights reserved. MIT license. | ||
|
||
import { Color } from "../../color.ts"; | ||
import { matrixColor } from "../matrix_color.ts"; | ||
|
||
/** | ||
* ### Example | ||
* | ||
* ```ts | ||
* const red = new Color(false, 255, 0, 0); | ||
* console.log(tritanopiaColor(red).components); // [242.25, 0, 0] | ||
* ``` | ||
*/ | ||
export function tritanopiaColor(color: Color): Color { | ||
// deno-fmt-ignore | ||
return matrixColor(color, [ | ||
0.95, 0.05, 0, | ||
0, 0.433, 0.567, | ||
0, 0.475, 0.525, | ||
]) | ||
} |
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