OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import 'dart:html'; | 5 import 'dart:html'; |
6 import 'dart:svg'; | 6 import 'dart:svg'; |
7 import 'dart:math' as Math; | 7 import 'dart:math' as Math; |
8 | 8 |
9 class Color { | 9 class Color { |
10 int hue; | 10 int hue; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 } | 44 } |
45 | 45 |
46 return new Color((h.round() % 360).toInt(), s, l); | 46 return new Color((h.round() % 360).toInt(), s, l); |
47 } | 47 } |
48 | 48 |
49 factory Color.fromHex(String hex) => new Color.rgb( | 49 factory Color.fromHex(String hex) => new Color.rgb( |
50 _parseHex(hex.substring(1, 3))/255, | 50 _parseHex(hex.substring(1, 3))/255, |
51 _parseHex(hex.substring(3, 5))/255, | 51 _parseHex(hex.substring(3, 5))/255, |
52 _parseHex(hex.substring(5, 7))/255); | 52 _parseHex(hex.substring(5, 7))/255); |
53 | 53 |
54 // This should be in the core library. Issue #233 | |
55 static int _parseHex(String hex) { | 54 static int _parseHex(String hex) { |
56 final codes = hex.charCodes; | 55 return int.parse(hex, radix: 16); |
57 var number = 0; | |
58 for (var i = 0; i < codes.length; i++) { | |
59 final code = codes[i]; | |
60 var digit; | |
61 if (code >= 48 && code <= 57) { // 0-9 | |
62 digit = code - 48; | |
63 } else if (code >= 97 && code <= 102) { // a-f | |
64 digit = code - 97 + 10; | |
65 } else { | |
66 throw "Invalid hex string: '$hex'"; | |
67 } | |
68 number *= 16; // shift previous digits left one place | |
69 number += digit; | |
70 } | |
71 return number; | |
72 } | 56 } |
73 | 57 |
74 String get hex { | 58 String get hex { |
75 final h = (hue % 360) / 360; | 59 final h = (hue % 360) / 360; |
76 final s = saturation; | 60 final s = saturation; |
77 final l = lightness; | 61 final l = lightness; |
78 | 62 |
79 // HSL to RGB algorithm from the CSS spec | 63 // HSL to RGB algorithm from the CSS spec |
80 // http://www.w3.org/TR/css3-color/#hsl-color | 64 // http://www.w3.org/TR/css3-color/#hsl-color |
81 final m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s; | 65 final m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s; |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 | 174 |
191 document.query("input[name=invert]").onChange.listen((Event e) { | 175 document.query("input[name=invert]").onChange.listen((Event e) { |
192 InputElement invert = e.target; | 176 InputElement invert = e.target; |
193 if (invert.checked) { | 177 if (invert.checked) { |
194 logo.classes = ['inverse']; | 178 logo.classes = ['inverse']; |
195 } else { | 179 } else { |
196 logo.classes = []; | 180 logo.classes = []; |
197 } | 181 } |
198 }); | 182 }); |
199 } | 183 } |
OLD | NEW |