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 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 SolarSystem(this.canvas) { | 62 SolarSystem(this.canvas) { |
63 | 63 |
64 } | 64 } |
65 | 65 |
66 num get width => _width; | 66 num get width => _width; |
67 | 67 |
68 num get height => _height; | 68 num get height => _height; |
69 | 69 |
70 start() { | 70 start() { |
71 // Measure the canvas element. | 71 // Measure the canvas element. |
72 canvas.parent.rect.then((ElementRect rect) { | 72 window.requestLayoutFrame(() { |
73 _width = rect.client.width; | 73 _width = canvas.parent.clientWidth; |
74 _height = rect.client.height; | 74 _height = canvas.parent.clientHeight; |
75 | 75 |
76 canvas.width = _width; | 76 canvas.width = _width; |
77 | 77 |
78 // Initialize the planets and start the simulation. | 78 // Initialize the planets and start the simulation. |
79 _start(); | 79 _start(); |
80 }); | 80 }); |
81 } | 81 } |
82 | 82 |
83 _start() { | 83 _start() { |
84 // Create the Sun. | 84 // Create the Sun. |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 } else { | 270 } else { |
271 num angle = solarSystem.renderTime * orbitSpeed; | 271 num angle = solarSystem.renderTime * orbitSpeed; |
272 | 272 |
273 return new Point( | 273 return new Point( |
274 orbitRadius * cos(angle) + x, | 274 orbitRadius * cos(angle) + x, |
275 orbitRadius * sin(angle) + y); | 275 orbitRadius * sin(angle) + y); |
276 } | 276 } |
277 } | 277 } |
278 | 278 |
279 } | 279 } |
OLD | NEW |