| 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 /** | 5 /** |
| 6 * A solar system visualization. | 6 * A solar system visualization. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 library solar; | 9 library solar; |
| 10 | 10 |
| 11 import 'dart:async'; |
| 11 import 'dart:html'; | 12 import 'dart:html'; |
| 12 import 'dart:math'; | 13 import 'dart:math'; |
| 13 | 14 |
| 14 void main() { | 15 void main() { |
| 15 CanvasElement canvas = query("#area"); | 16 CanvasElement canvas = query("#area"); |
| 16 window.setImmediate(new SolarSystem(canvas).start); | 17 scheduleMicrotask(new SolarSystem(canvas).start); |
| 17 } | 18 } |
| 18 | 19 |
| 19 Element notes = query("#fps"); | 20 Element notes = query("#fps"); |
| 20 num fpsAverage; | 21 num fpsAverage; |
| 21 | 22 |
| 22 /// Display the animation's FPS in a div. | 23 /// Display the animation's FPS in a div. |
| 23 void showFps(num fps) { | 24 void showFps(num fps) { |
| 24 if (fpsAverage == null) fpsAverage = fps; | 25 if (fpsAverage == null) fpsAverage = fps; |
| 25 fpsAverage = fps * 0.05 + fpsAverage * 0.95; | 26 fpsAverage = fps * 0.05 + fpsAverage * 0.95; |
| 26 notes.text = "${fpsAverage.round()} fps"; | 27 notes.text = "${fpsAverage.round()} fps"; |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 num calculateSpeed(num period) => | 197 num calculateSpeed(num period) => |
| 197 period == 0.0 ? 0.0 : 1 / (60.0 * 24.0 * 2 * period); | 198 period == 0.0 ? 0.0 : 1 / (60.0 * 24.0 * 2 * period); |
| 198 | 199 |
| 199 Point calculatePos(Point p) { | 200 Point calculatePos(Point p) { |
| 200 if (orbitSpeed == 0.0) return p; | 201 if (orbitSpeed == 0.0) return p; |
| 201 num angle = solarSystem.renderTime * orbitSpeed; | 202 num angle = solarSystem.renderTime * orbitSpeed; |
| 202 return new Point(orbitRadius * cos(angle) + p.x, | 203 return new Point(orbitRadius * cos(angle) + p.x, |
| 203 orbitRadius * sin(angle) + p.y); | 204 orbitRadius * sin(angle) + p.y); |
| 204 } | 205 } |
| 205 } | 206 } |
| OLD | NEW |