-
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.
feat(Color): further segmentation of Color
- Loading branch information
Showing
6 changed files
with
133 additions
and
125 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
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,8 @@ | ||
export FULL_CHANNEL = 0xff | ||
//ESC[48;2;⟨r⟩;⟨g⟩;⟨b⟩ m Select RGB background color | ||
export ANSI_BACKGROUND = 48 | ||
//ESC[38;2;⟨r⟩;⟨g⟩;⟨b⟩ m Select RGB foreground color | ||
export ANSI_FOREGROUND = 38 | ||
|
||
|
||
export HALF_CHANNEL = 0x7f |
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,33 @@ | ||
import Math from "Math" | ||
|
||
import { FULL_CHANNEL } from "@/Color/Constants" | ||
|
||
|
||
|
||
toAnsi256 :: (Bits a, Comparable a, Number a) => a -> a -> a -> Float | ||
export toAnsi256 = (r, g, b) => { | ||
r4 = r >> 4 | ||
g4 = g >> 4 | ||
b4 = b >> 4 | ||
return if (r4 == g4 && g4 == b4) { | ||
if (r < 8) { | ||
16 | ||
} else if (r > 248) { | ||
231 | ||
} else { | ||
Math.round(((r - 8) / 247) * 24) + 232 | ||
} | ||
} else { | ||
16 + (36 * Math.round(r / 255 * 5)) + (6 * Math.round(g / 255 * 5)) + Math.round(b / 255 * 5) | ||
} | ||
} | ||
|
||
|
||
channelR :: Integer -> Integer | ||
export channelR = (raw) => (raw >> 16) & 0xff | ||
|
||
channelG :: Integer -> Integer | ||
export channelG = (raw) => (raw >> 8) & 0xff | ||
|
||
channelB :: Integer -> Integer | ||
export channelB = (raw) => raw & 0xff |
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,37 @@ | ||
import type { Random } from "Random" | ||
|
||
import { generateFromSeed } from "Random" | ||
import Random from "Random" | ||
|
||
import { ANSI_BACKGROUND, ANSI_FOREGROUND, FULL_CHANNEL } from "@/Color/Constants" | ||
|
||
|
||
|
||
colorFromSeed :: Random -> #[Integer, Integer, Integer] | ||
export colorFromSeed = (seed) => { | ||
pull = Random.integer(0, FULL_CHANNEL) | ||
r = pull(seed) | ||
g = pull(seed) | ||
b = pull(seed) | ||
return #[r, g, b] | ||
} | ||
|
||
export seededSeq = (before, str) => pipe( | ||
Random.generateFromString, | ||
colorFromSeed, | ||
where { | ||
#[r, g, b] => | ||
pipe( | ||
mappend([before, 2]), | ||
map(show), | ||
)([r, g, b]) | ||
}, | ||
)(str) | ||
|
||
export rgbInvert = where { | ||
#[r, g, b] => | ||
#[FULL_CHANNEL - r, FULL_CHANNEL - g, FULL_CHANNEL - b] | ||
} | ||
|
||
export seededSeqBg = seededSeq(ANSI_BACKGROUND) | ||
export seededSeqFg = seededSeq(ANSI_FOREGROUND) |
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