This repository has been archived by the owner on Aug 7, 2024. It is now read-only.
-
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
jwcub
committed
May 12, 2024
1 parent
b83f36d
commit e38f5e4
Showing
10 changed files
with
703 additions
and
713 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,10 @@ | ||
import { expect, it } from "vitest"; | ||
|
||
import { Palette } from "./palette"; | ||
|
||
it("creates a palette", () => { | ||
const palette = Palette.colors(20); | ||
|
||
expect(palette).toHaveLength(21); | ||
expect(palette[0]).toBe(0x808080); | ||
}); |
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,28 @@ | ||
import generateColors from "iwanthue"; | ||
|
||
/** | ||
* A palette consisting of different standard colors. | ||
*/ | ||
export class Palette extends Array<number> { | ||
/** | ||
* Not meant to be called directly. | ||
*/ | ||
constructor(...args: ConstructorParameters<typeof Array<number>>) { | ||
super(...args); | ||
} | ||
|
||
/** | ||
* Creates a Palette with (n + 1) standard colors. | ||
* | ||
* The first color is fixed to grey. | ||
*/ | ||
static colors(n: number) { | ||
return new Palette( | ||
0x808080, | ||
...generateColors(n, { | ||
colorSpace: [0, 360, 25, 85, 45, 70], | ||
clustering: "force-vector" | ||
}).map(color => parseInt(color.substring(1), 16)) | ||
); | ||
} | ||
} |
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
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
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
Oops, something went wrong.