| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 start() { | 50 start() { |
| 51 // Measure the canvas element. | 51 // Measure the canvas element. |
| 52 Rectangle rect = canvas.parent.client; | 52 Rectangle rect = canvas.parent.client; |
| 53 width = rect.width; | 53 width = rect.width; |
| 54 height = rect.height; | 54 height = rect.height; |
| 55 canvas.width = width; | 55 canvas.width = width; |
| 56 | 56 |
| 57 // Create sun. | 57 // Create sun. |
| 58 final mercury = new PlanetaryBody(this, "orange", 0.382, 0.387, 0.241); | 58 final mercury = new PlanetaryBody(this, "orange", 0.382, 0.387, 0.241); |
| 59 final venus = new PlanetaryBody(this, "green", 0.949, 0.723, 0.615); | 59 final venus = new PlanetaryBody(this, "green", 0.949, 0.723, 0.615); |
| 60 sun = new PlanetaryBody(this, "#ff2", 14.0)..addPlanet(mercury) | |
| 61 ..addPlanet(venus); | |
| 62 | |
| 63 final earth = new PlanetaryBody(this, "#33f", 1.0, 1.0, 1.0); | 60 final earth = new PlanetaryBody(this, "#33f", 1.0, 1.0, 1.0); |
| 64 final moon = new PlanetaryBody(this, "gray", 0.2, 0.14, 0.075); | 61 final moon = new PlanetaryBody(this, "gray", 0.2, 0.14, 0.075); |
| 62 earth.addPlanet(moon); |
| 63 |
| 65 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); |
| 66 sun.addPlanet(earth..addPlanet(moon) | |
| 67 ..addPlanet(mars)); | |
| 68 | |
| 69 addAsteroidBelt(sun, 150); | |
| 70 | 65 |
| 71 final f = 0.1; | 66 final f = 0.1; |
| 72 final h = 1 / 1500.0; | 67 final h = 1 / 1500.0; |
| 73 final g = 1 / 72.0; | 68 final g = 1 / 72.0; |
| 74 | 69 |
| 75 final jupiter = new PlanetaryBody(this, "gray", 4.0, 5.203, 11.86); | 70 final jupiter = new PlanetaryBody(this, "gray", 4.0, 5.203, 11.86); |
| 76 final io = new PlanetaryBody(this, "gray", 3.6*f, 421*h, 1.769*g); | 71 final io = new PlanetaryBody(this, "gray", 3.6*f, 421*h, 1.769*g); |
| 77 final europa = new PlanetaryBody(this, "gray", 3.1*f, 671*h, 3.551*g); | 72 final europa = new PlanetaryBody(this, "gray", 3.1*f, 671*h, 3.551*g); |
| 78 final ganymede = new PlanetaryBody(this, "gray", 5.3*f, 1070*h, 7.154*g); | 73 final ganymede = new PlanetaryBody(this, "gray", 5.3*f, 1070*h, 7.154*g); |
| 79 final callisto = new PlanetaryBody(this, "gray", 4.8*f, 1882*h, 16.689*g); | 74 final callisto = new PlanetaryBody(this, "gray", 4.8*f, 1882*h, 16.689*g); |
| 80 sun.addPlanet(jupiter..addPlanet(io) | 75 jupiter..addPlanet(io) |
| 81 ..addPlanet(europa) | 76 ..addPlanet(europa) |
| 82 ..addPlanet(ganymede) | 77 ..addPlanet(ganymede) |
| 83 ..addPlanet(callisto)); | 78 ..addPlanet(callisto); |
| 84 requestRedraw(); | 79 |
| 80 sun = new PlanetaryBody(this, "#ff2", 14.0)..addPlanet(mercury) |
| 81 ..addPlanet(venus) |
| 82 ..addPlanet(earth) |
| 83 ..addPlanet(mars) |
| 84 ..addPlanet(jupiter); |
| 85 |
| 86 addAsteroidBelt(sun, 150); |
| 87 |
| 88 requestRedraw(); |
| 85 } | 89 } |
| 86 | 90 |
| 87 void draw(num _) { | 91 void draw(num _) { |
| 88 num time = new DateTime.now().millisecondsSinceEpoch; | 92 num time = new DateTime.now().millisecondsSinceEpoch; |
| 89 if (renderTime != null) showFps(1000 / (time - renderTime)); | 93 if (renderTime != null) showFps(1000 / (time - renderTime)); |
| 90 renderTime = time; | 94 renderTime = time; |
| 91 | 95 |
| 92 var context = canvas.context2D; | 96 var context = canvas.context2D; |
| 93 drawBackground(context); | 97 drawBackground(context); |
| 94 drawPlanets(context); | 98 drawPlanets(context); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 num calculateSpeed(num period) => | 201 num calculateSpeed(num period) => |
| 198 period == 0.0 ? 0.0 : 1 / (60.0 * 24.0 * 2 * period); | 202 period == 0.0 ? 0.0 : 1 / (60.0 * 24.0 * 2 * period); |
| 199 | 203 |
| 200 Point calculatePos(Point p) { | 204 Point calculatePos(Point p) { |
| 201 if (orbitSpeed == 0.0) return p; | 205 if (orbitSpeed == 0.0) return p; |
| 202 num angle = solarSystem.renderTime * orbitSpeed; | 206 num angle = solarSystem.renderTime * orbitSpeed; |
| 203 return new Point(orbitRadius * cos(angle) + p.x, | 207 return new Point(orbitRadius * cos(angle) + p.x, |
| 204 orbitRadius * sin(angle) + p.y); | 208 orbitRadius * sin(angle) + p.y); |
| 205 } | 209 } |
| 206 } | 210 } |
| OLD | NEW |