Last active
October 31, 2016 03:15
-
-
Save r00k/70575039793934f0f4c5f268409a9618 to your computer and use it in GitHub Desktop.
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
-- Goal: add/substract a small random amount from each component (r, g, b, a) | |
-- of the passed-in color. | |
maybeMutateColor : Color -> Generator Color | |
maybeMutateColor color = | |
let | |
floatGenerator = | |
Random.float -maximumAlphaChange maximumAlphaChange | |
intGenerator = | |
Random.int -maximumRGBChange maximumRGBChange | |
colorGenerator = | |
intGenerator `Random.andThen` \dr -> | |
intGenerator `Random.andThen` \dg -> | |
intGenerator `Random.andThen` \db -> | |
floatGenerator `Random.andThen` \da -> | |
Random.Extra.constant | |
(Color.rgba | |
(color.r + dr) | |
(color.g + dg) | |
(color.b + db) | |
(color.a + da)) | |
in | |
Random.Extra.frequency | |
[ ( 50.0, Random.Extra.constant color ) | |
, ( 50.0, colorGenerator ) | |
] | |
Here's the current madness--I mean version:
adjustColor : Color -> Generator Int -> Generator Int -> Generator Int -> Generator Float -> Generator Color
adjustColor color dr dg db da =
Color.rgba
(dr `Random.andThen` \x -> Random.Extra.constant (color.r + x))
(dg `Random.andThen` \x -> Random.Extra.constant (color.g + x))
(db `Random.andThen` \x -> Random.Extra.constant (color.b + x))
(da `Random.andThen` \x -> Random.Extra.constant (color.a + x))
maybeMutateColor : Color -> Generator Color
maybeMutateColor color =
let
floatGenerator =
Random.float -maximumAlphaChange maximumAlphaChange
intGenerator =
Random.int -maximumRGBChange maximumRGBChange
colorGenerator =
Random.map4
(adjustColor color)
intGenerator
intGenerator
intGenerator
floatGenerator
in
Random.Extra.frequency
[ ( 50.0, Random.Extra.constant color )
, ( 50.0, colorGenerator )
]
adjustColor : Color -> Int -> Int -> Int -> Float -> Color
adjustColor color dr dg db da =
Color.rgba
(color.r + dr)
(color.g + dg)
(color.b + db)
(color.a + da)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Currently failing thusly: