on master help sign in
Get the color library in order. Remove the silly lifty functions from Automaton.
cb609eaevancz
core/Automaton.elm+10−13
@@ -4,8 +4,6 @@ module Automaton where
4data Automaton a b = Automaton (a -> (b, Automaton a b))
4data Automaton a b = Automaton (a -> (b, Automaton a b))
5
5
6{--- API possibilies: All names and types are up for debate!
6{--- API possibilies: All names and types are up for debate!
7−(>>>) :: Automaton a b -> Automaton b c -> Automaton a c
8−(<<<) :: Automaton b c -> Automaton a b -> Automaton a c
9(^>>) :: (a -> b) -> Automaton b c -> Automaton a c
7(^>>) :: (a -> b) -> Automaton b c -> Automaton a c
10(>>^) :: Automaton a b -> (b -> c) -> Automaton a c
8(>>^) :: Automaton a b -> (b -> c) -> Automaton a c
11(^<<) :: (b -> c) -> Automaton a b -> Automaton a c
9(^<<) :: (b -> c) -> Automaton a b -> Automaton a c
@@ -21,6 +19,7 @@ step : Automaton a b -> a -> (b, Automaton a b)
21step (Automaton m) a = m a
19step (Automaton m) a = m a
22
20
23
21
22+(>>>) : Automaton a b -> Automaton b c -> Automaton a c
24a1 >>> a2 =
23a1 >>> a2 =
25 let Automaton m1 = a1
24 let Automaton m1 = a1
26 Automaton m2 = a2
25 Automaton m2 = a2
@@ -28,11 +27,8 @@ a1 >>> a2 =
28 (c,m2') = m2 b
27 (c,m2') = m2 b
29 in (c, m1' >>> m2'))
28 in (c, m1' >>> m2'))
30
29
30+(<<<) : Automaton b c -> Automaton a b -> Automaton a c
31a2 <<< a1 = a1 >>> a2
31a2 <<< a1 = a1 >>> a2
32−f ^>> a = pure f >>> a
33−a >>^ f = a >>> pure f
34−f ^<< a = a >>> pure f
35−a <<^ f = pure f >>> a
36
32
37combine : [Automaton a b] -> Automaton a [b]
33combine : [Automaton a b] -> Automaton a [b]
38combine autos =
34combine autos =
@@ -59,13 +55,14 @@ vecSub (x1,y1) (x2,y2) = (x1-x2,y1-y2)
59stepDrag (press,pos) (ds,form) =
55stepDrag (press,pos) (ds,form) =
60 let wrap ds' = (form, (ds',form)) in
56 let wrap ds' = (form, (ds',form)) in
61 case ds of
57 case ds of
62− { Listen -> wrap (if not press then Listen else
58+ Listen -> wrap (if | not press -> Listen
63− if pos `isWithin` form then DragFrom pos else Ignore)
59+ | pos `isWithin` form -> DragFrom pos
60+ | otherwise -> Ignore)
64− ; Ignore -> wrap (if press then Ignore else Listen)
61+ Ignore -> wrap (if press then Ignore else Listen)
62+ DragFrom p0 ->
65− ; DragFrom p0 -> if press then (uncurry move (vecSub pos p0) form, (DragFrom p0, form))
63+ if press then (uncurry move (vecSub pos p0) form, (DragFrom p0, form))
66− else (let form' = uncurry move (vecSub pos p0) form in
64+ else (let form' = uncurry move (vecSub pos p0) form in
67− (form', (Listen,form')))
65+ (form', (Listen,form')))
68− }
69
66
70draggable : Form -> Automaton (Bool,(Int,Int)) Form
67draggable : Form -> Automaton (Bool,(Int,Int)) Form
71draggable form = init' (Listen,form) stepDrag
68draggable form = init' (Listen,form) stepDrag
core/Color.elm+28−6
@@ -1,9 +1,14 @@
1
1
2−module Graphics.Color
2+module Graphics.Color (rgba,rgb,hsva,hsv,
3− (rgba,rgb
3+ complement,
4− ,red,green,blue
4+ red,lime,blue,
5− ,yellow,cyan,magenta
5+ yellow,cyan,magenta,
6+ maroon,navy,green,
7+ teal,purple,
8+ violet,forestGreen,
6− ,black,white,gray,grey) where
9+ black,white,gray,grey) where
10+
11+import Native.Color as Native
7
12
8data Color = Color Int Int Int Float
13data Color = Color Int Int Int Float
9
14
@@ -11,12 +16,29 @@ rgba = Color
11rgb r g b = Color r g b 1
16rgb r g b = Color r g b 1
12
17
13red = Color 255 0 0 1
18red = Color 255 0 0 1
14−green = Color 0 255 0 1
19+lime = Color 0 255 0 1
15blue = Color 0 0 255 1
20blue = Color 0 0 255 1
21+
16yellow = Color 255 255 0 1
22yellow = Color 255 255 0 1
17cyan = Color 0 255 255 1
23cyan = Color 0 255 255 1
18magenta = Color 255 0 255 1
24magenta = Color 255 0 255 1
25+
19black = Color 0 0 0 1
26black = Color 0 0 0 1
20white = Color 255 255 255 1
27white = Color 255 255 255 1
28+
21gray = Color 128 128 128 1
29gray = Color 128 128 128 1
22grey = Color 128 128 128 1
30grey = Color 128 128 128 1
31+
32+maroon = Color 128 0 0 1
33+navy = Color 0 0 128 1
34+green = Color 0 128 0 1
35+
36+teal = Color 0 128 128 1
37+purple = Color 128 0 128 1
38+
39+forestGreen = Color 34 139 34 1
40+violet = Color 238 130 238 1
41+
42+complement = Native.complement
43+hsva = Native.hsva
44+hsv = Native.hsv
core/Native/Color.jsnew file+64
@@ -0,0 +1,64 @@
1+function nativeColor(elm) {
2+
3+function extract(c) {
4+ if (c[4] === 1) { return 'rgb(' + c[1] + ',' + c[2] + ',' + c[3] + ')'; }
5+ return 'rgba(' + c[1] + ',' + c[2] + ',' + c[3] + ',' + c[4] + ')';
6+}
7+function complement(rgb) {
8+ var hsv = toHSV(rgb);
9+ hsv.hue = (hsv.hue + 180) % 360;
10+ return toRGB(hsv);
11+}
12+
13+function hsva(h) { return function(s) { return function(v) { return function(a) {
14+ var clr = toRGB({hue:h, saturation:s, value:v});
15+ clr[4] = a;
16+ return clr;
17+ }; }; };
18+}
19+
20+function hsv(h) { return function(s) { return function(v) {
21+ return toRGB({hue:h, saturation:s, value:v}); }; }; }
22+
23+function toHSV(rgb) {
24+ var hsv = {};
25+ var r = rgb[1] / 255.0, g = rgb[2] / 255.0, b = rgb[3] / 255.0;
26+ var M = Math.max(r,g,b);
27+ var m = Math.min(r,g,b);
28+ var c = M - m;
29+
30+ var h = 0;
31+ if (c === 0) { h = 0; }
32+ else if (M === r) { h = ((g - b) / c) % 6; }
33+ else if (M === g) { h = ((b - r) / c) + 2; }
34+ else if (M === b) { h = ((r - g) / c) + 4; }
35+ h *= 60;
36+
37+ return { value : M, hue : h, saturation : (M === 0 ? 0 : c / M) };
38+}
39+
40+function between(lo,hi,x) { return lo <= x && x < hi; }
41+function norm(n) { return Math.round(n*255); }
42+
43+function toRGB(hsv) {
44+ var c = hsv.value * hsv.saturation;
45+ var hue = hsv.hue / 60;
46+ var x = c * (1 - Math.abs((hue % 2) - 1));
47+ var r = 0, g = 0, b = 0;
48+ if (between(0,1,hue)) { r = c; g = x; b = 0; }
49+ else if (between(1,2,hue)) { r = x; g = c; b = 0; }
50+ else if (between(2,3,hue)) { r = 0; g = c; b = x; }
51+ else if (between(3,4,hue)) { r = 0; g = x; b = c; }
52+ else if (between(4,5,hue)) { r = x; g = 0; b = c; }
53+ else if (between(5,6,hue)) { r = c; g = 0; b = x; }
54+
55+ var m = hsv.value - c;
56+ return [ "Color", norm(r+m), norm(g+m), norm(b+m), 1 ];
57+}
58+
59+elm.Native.Color = {
60+ hsva:hsva,
61+ hsv:hsv,
62+ complement:complement,
63+ extract:extract};
64+}