| 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 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 PlanetaryBody sun; | 42 PlanetaryBody sun; |
| 43 | 43 |
| 44 num renderTime; | 44 num renderTime; |
| 45 | 45 |
| 46 SolarSystem(this.canvas); | 46 SolarSystem(this.canvas); |
| 47 | 47 |
| 48 // Initialize the planets and start the simulation. | 48 // Initialize the planets and start the simulation. |
| 49 start() { | 49 start() { |
| 50 // Measure the canvas element. | 50 // Measure the canvas element. |
| 51 Rect rect = canvas.parent.client; | 51 Rectangle rect = canvas.parent.client; |
| 52 width = rect.width; | 52 width = rect.width; |
| 53 height = rect.height; | 53 height = rect.height; |
| 54 canvas.width = width; | 54 canvas.width = width; |
| 55 | 55 |
| 56 // Create sun. | 56 // Create sun. |
| 57 final mercury = new PlanetaryBody(this, "orange", 0.382, 0.387, 0.241); | 57 final mercury = new PlanetaryBody(this, "orange", 0.382, 0.387, 0.241); |
| 58 final venus = new PlanetaryBody(this, "green", 0.949, 0.723, 0.615); | 58 final venus = new PlanetaryBody(this, "green", 0.949, 0.723, 0.615); |
| 59 sun = new PlanetaryBody(this, "#ff2", 14.0)..addPlanet(mercury) | 59 sun = new PlanetaryBody(this, "#ff2", 14.0)..addPlanet(mercury) |
| 60 ..addPlanet(venus); | 60 ..addPlanet(venus); |
| 61 | 61 |
| 62 final earth = new PlanetaryBody(this, "#33f", 1.0, 1.0, 1.0); | 62 final earth = new PlanetaryBody(this, "#33f", 1.0, 1.0, 1.0); |
| 63 final moon = new PlanetaryBody(this, "gray", 0.2, 0.14, 0.075); | 63 final moon = new PlanetaryBody(this, "gray", 0.2, 0.14, 0.075); |
| 64 final mars = new PlanetaryBody(this, "red", 0.532, 1.524, 1.88); | 64 final mars = new PlanetaryBody(this, "red", 0.532, 1.524, 1.88); |
| 65 sun.addPlanet(earth..addPlanet(moon) | 65 sun.addPlanet(earth..addPlanet(moon) |
| 66 ..addPlanet(mars)); | 66 ..addPlanet(mars)); |
| 67 | 67 |
| 68 addAsteroidBelt(sun, 150); | 68 addAsteroidBelt(sun, 150); |
| 69 | 69 |
| 70 final f = 0.1; | 70 final f = 0.1; |
| 71 final h = 1 / 1500.0; | 71 final h = 1 / 1500.0; |
| 72 final g = 1 / 72.0; | 72 final g = 1 / 72.0; |
| 73 | 73 |
| 74 final jupiter = new PlanetaryBody(this, "gray", 4.0, 5.203, 11.86); | 74 final jupiter = new PlanetaryBody(this, "gray", 4.0, 5.203, 11.86); |
| 75 final io = new PlanetaryBody(this, "gray", 3.6*f, 421*h, 1.769*g); | 75 final io = new PlanetaryBody(this, "gray", 3.6*f, 421*h, 1.769*g); |
| 76 final europa = new PlanetaryBody(this, "gray", 3.1*f, 671*h, 3.551*g); | 76 final europa = new PlanetaryBody(this, "gray", 3.1*f, 671*h, 3.551*g); |
| 77 final ganymede = new PlanetaryBody(this, "gray", 5.3*f, 1070*h, 7.154*g); | 77 final ganymede = new PlanetaryBody(this, "gray", 5.3*f, 1070*h, 7.154*g); |
| 78 final callisto = new PlanetaryBody(this, "gray", 4.8*f, 1882*h, 16.689*g); | 78 final callisto = new PlanetaryBody(this, "gray", 4.8*f, 1882*h, 16.689*g); |
| 79 sun.addPlanet(jupiter..addPlanet(io) | 79 sun.addPlanet(jupiter..addPlanet(io) |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 num calculateSpeed(num period) => | 196 num calculateSpeed(num period) => |
| 197 period == 0.0 ? 0.0 : 1 / (60.0 * 24.0 * 2 * period); | 197 period == 0.0 ? 0.0 : 1 / (60.0 * 24.0 * 2 * period); |
| 198 | 198 |
| 199 Point calculatePos(Point p) { | 199 Point calculatePos(Point p) { |
| 200 if (orbitSpeed == 0.0) return p; | 200 if (orbitSpeed == 0.0) return p; |
| 201 num angle = solarSystem.renderTime * orbitSpeed; | 201 num angle = solarSystem.renderTime * orbitSpeed; |
| 202 return new Point(orbitRadius * cos(angle) + p.x, | 202 return new Point(orbitRadius * cos(angle) + p.x, |
| 203 orbitRadius * sin(angle) + p.y); | 203 orbitRadius * sin(angle) + p.y); |
| 204 } | 204 } |
| 205 } | 205 } |
| OLD | NEW |