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 library clock; | 5 library clock; |
6 | 6 |
7 import 'dart:html'; | 7 import 'dart:html'; |
8 import 'dart:math'; | 8 import 'dart:math'; |
9 | 9 |
10 part 'balls.dart'; | 10 part 'balls.dart'; |
11 part 'numbers.dart'; | 11 part 'numbers.dart'; |
12 | 12 |
13 void main() { | 13 void main() { |
14 new CountDownClock(); | 14 new CountDownClock(); |
15 } | 15 } |
16 | 16 |
17 double fpsAverage; | 17 double fpsAverage; |
18 | 18 |
19 /** | 19 /** |
20 * Display the animation's FPS in a div. | 20 * Display the animation's FPS in a div. |
21 */ | 21 */ |
22 void showFps(num fps) { | 22 void showFps(num fps) { |
23 if (fpsAverage == null) { | 23 if (fpsAverage == null) { |
24 fpsAverage = fps; | 24 fpsAverage = fps; |
25 } else { | 25 } else { |
26 fpsAverage = fps * 0.05 + fpsAverage * 0.95; | 26 fpsAverage = fps * 0.05 + fpsAverage * 0.95; |
27 | 27 |
28 query("#notes").text = "${fpsAverage.round().toInt()} fps"; | 28 query("#notes").text = "${fpsAverage.round()} fps"; |
29 } | 29 } |
30 } | 30 } |
31 | 31 |
32 class CountDownClock { | 32 class CountDownClock { |
33 static const int NUMBER_SPACING = 19; | 33 static const int NUMBER_SPACING = 19; |
34 static const double BALL_WIDTH = 19.0; | 34 static const double BALL_WIDTH = 19.0; |
35 static const double BALL_HEIGHT = 19.0; | 35 static const double BALL_HEIGHT = 19.0; |
36 | 36 |
37 List<ClockNumber> hours = new List<ClockNumber>.fixedLength(2); | 37 List<ClockNumber> hours = new List<ClockNumber>.fixedLength(2); |
38 List<ClockNumber> minutes = new List<ClockNumber>.fixedLength(2); | 38 List<ClockNumber> minutes = new List<ClockNumber>.fixedLength(2); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 void setElementPosition(Element elem, double x, double y) { | 154 void setElementPosition(Element elem, double x, double y) { |
155 elem.style.left = "${x}px"; | 155 elem.style.left = "${x}px"; |
156 elem.style.top = "${y}px"; | 156 elem.style.top = "${y}px"; |
157 } | 157 } |
158 | 158 |
159 void setElementSize(Element elem, double l, double t, double r, double b) { | 159 void setElementSize(Element elem, double l, double t, double r, double b) { |
160 setElementPosition(elem, l, t); | 160 setElementPosition(elem, l, t); |
161 elem.style.right = "${r}px"; | 161 elem.style.right = "${r}px"; |
162 elem.style.bottom = "${b}px"; | 162 elem.style.bottom = "${b}px"; |
163 } | 163 } |
OLD | NEW |