Current section
Files
Jump to
Current section
Files
src/colorhash.erl
-module(colorhash).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-define(FILEPATH, "src/colorhash.gleam").
-export([new/0, with_saturations/2, with_lightnesses/2, with_hue_ranges/2, to_color/2]).
-export_type([color_hash/0]).
-type color_hash() :: {color_hash,
gleam@dict:dict(integer(), float()),
gleam@dict:dict(integer(), float()),
gleam@dict:dict(integer(), {float(), float()})}.
-file("src/colorhash.gleam", 16).
-spec new() -> color_hash().
new() ->
{color_hash,
begin
_pipe = [0.35, 0.5, 0.65],
_pipe@1 = gleam@list:index_map(_pipe, fun(X, I) -> {I, X} end),
maps:from_list(_pipe@1)
end,
begin
_pipe@2 = [0.35, 0.5, 0.65],
_pipe@3 = gleam@list:index_map(
_pipe@2,
fun(X@1, I@1) -> {I@1, X@1} end
),
maps:from_list(_pipe@3)
end,
begin
_pipe@4 = [{+0.0, 1.0}],
_pipe@5 = gleam@list:index_map(
_pipe@4,
fun(X@2, I@2) -> {I@2, X@2} end
),
maps:from_list(_pipe@5)
end}.
-file("src/colorhash.gleam", 30).
-spec with_saturations(color_hash(), list(float())) -> color_hash().
with_saturations(Color_hash, Saturations) ->
_record = Color_hash,
{color_hash,
begin
_pipe = Saturations,
_pipe@1 = gleam@list:index_map(_pipe, fun(X, I) -> {I, X} end),
maps:from_list(_pipe@1)
end,
erlang:element(3, _record),
erlang:element(4, _record)}.
-file("src/colorhash.gleam", 42).
-spec with_lightnesses(color_hash(), list(float())) -> color_hash().
with_lightnesses(Color_hash, Lightnesses) ->
_record = Color_hash,
{color_hash,
erlang:element(2, _record),
begin
_pipe = Lightnesses,
_pipe@1 = gleam@list:index_map(_pipe, fun(X, I) -> {I, X} end),
maps:from_list(_pipe@1)
end,
erlang:element(4, _record)}.
-file("src/colorhash.gleam", 54).
-spec with_hue_ranges(color_hash(), list({float(), float()})) -> color_hash().
with_hue_ranges(Color_hash, Hue_ranges) ->
_record = Color_hash,
{color_hash,
erlang:element(2, _record),
erlang:element(3, _record),
begin
_pipe = Hue_ranges,
_pipe@1 = gleam@list:index_map(_pipe, fun(X, I) -> {I, X} end),
maps:from_list(_pipe@1)
end}.
-file("src/colorhash.gleam", 66).
-spec to_color(color_hash(), binary()) -> gleam_community@colour:colour().
to_color(Color_hash, Input) ->
Default_color_hash = new(),
Hue_ranges = case maps:size(erlang:element(4, Color_hash)) of
0 ->
erlang:element(4, Default_color_hash);
_ ->
erlang:element(4, Color_hash)
end,
Saturations = case maps:size(erlang:element(2, Color_hash)) of
0 ->
erlang:element(2, Default_color_hash);
_ ->
erlang:element(2, Color_hash)
end,
Lightnesses = case maps:size(erlang:element(3, Color_hash)) of
0 ->
erlang:element(3, Default_color_hash);
_ ->
erlang:element(3, Color_hash)
end,
Hash@1 = case gleam@crypto:hash(sha256, gleam_stdlib:identity(Input)) of
<<Hash:32, _/bitstring>> -> Hash;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"colorhash"/utf8>>,
function => <<"to_color"/utf8>>,
line => 81,
value => _assert_fail,
start => 1881,
'end' => 1974,
pattern_start => 1892,
pattern_end => 1911})
end,
Hue_resolution = 727,
{Hue_range_start@1, Hue_range_end@1} = case gleam_stdlib:map_get(
Hue_ranges,
case maps:size(Hue_ranges) of
0 -> 0;
Gleam@denominator -> Hash@1 rem Gleam@denominator
end
) of
{ok, {Hue_range_start, Hue_range_end}} -> {
Hue_range_start,
Hue_range_end};
_assert_fail@1 ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"colorhash"/utf8>>,
function => <<"to_color"/utf8>>,
line => 85,
value => _assert_fail@1,
start => 2005,
'end' => 2110,
pattern_start => 2016,
pattern_end => 2053})
end,
H = (case erlang:float(Hue_resolution) of
+0.0 -> +0.0;
-0.0 -> -0.0;
Gleam@denominator@3 -> erlang:float(case Hue_resolution of
0 -> 0;
Gleam@denominator@2 -> (case maps:size(Hue_ranges) of
0 -> 0;
Gleam@denominator@1 -> Hash@1 div Gleam@denominator@1
end) rem Gleam@denominator@2
end) * (Hue_range_end@1 - Hue_range_start@1) / Gleam@denominator@3
end) + Hue_range_start@1,
S@1 = case gleam_stdlib:map_get(Saturations, case maps:size(Saturations) of
0 -> 0;
Gleam@denominator@4 -> (Hash@1 div 360) rem Gleam@denominator@4
end) of
{ok, S} -> S;
_assert_fail@2 ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"colorhash"/utf8>>,
function => <<"to_color"/utf8>>,
line => 93,
value => _assert_fail@2,
start => 2295,
'end' => 2380,
pattern_start => 2306,
pattern_end => 2311})
end,
L@1 = case gleam_stdlib:map_get(Lightnesses, case maps:size(Saturations) of
0 -> 0;
Gleam@denominator@6 -> (case maps:size(Saturations) of
0 -> 0;
Gleam@denominator@5 -> Hash@1 div 360 div Gleam@denominator@5
end) rem Gleam@denominator@6
end) of
{ok, L} -> L;
_assert_fail@3 ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"colorhash"/utf8>>,
function => <<"to_color"/utf8>>,
line => 96,
value => _assert_fail@3,
start => 2384,
'end' => 2513,
pattern_start => 2395,
pattern_end => 2400})
end,
C@1 = case gleam_community@colour:from_hsl(H, S@1, L@1) of
{ok, C} -> C;
_assert_fail@4 ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"colorhash"/utf8>>,
function => <<"to_color"/utf8>>,
line => 102,
value => _assert_fail@4,
start => 2517,
'end' => 2560,
pattern_start => 2528,
pattern_end => 2533})
end,
C@1.