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 int clientWidth() => window.innerWidth; | 5 int clientWidth() => window.innerWidth; |
6 | 6 |
7 int clientHeight() => window.innerHeight; | 7 int clientHeight() => window.innerHeight; |
8 | 8 |
9 class Balls { | 9 class Balls { |
10 static final double RADIUS2 = Ball.RADIUS * Ball.RADIUS; | 10 static final double RADIUS2 = Ball.RADIUS * Ball.RADIUS; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 } | 111 } |
112 | 112 |
113 class Ball { | 113 class Ball { |
114 static final double GRAVITY = 400.0; | 114 static final double GRAVITY = 400.0; |
115 static final double RESTITUTION = 0.8; | 115 static final double RESTITUTION = 0.8; |
116 static final double MIN_VELOCITY = 100.0; | 116 static final double MIN_VELOCITY = 100.0; |
117 static final double INIT_VELOCITY = 800.0; | 117 static final double INIT_VELOCITY = 800.0; |
118 static final double RADIUS = 14.0; | 118 static final double RADIUS = 14.0; |
119 | 119 |
120 static double randomVelocity() { | 120 static double randomVelocity() { |
121 return (Math.random() - 0.5) * INIT_VELOCITY; | 121 return (new Math.Random().nextDouble() - 0.5) * INIT_VELOCITY; |
122 } | 122 } |
123 | 123 |
124 Element root; | 124 Element root; |
125 ImageElement elem; | 125 ImageElement elem; |
126 double x, y; | 126 double x, y; |
127 double vx, vy; | 127 double vx, vy; |
128 double ax, ay; | 128 double ax, ay; |
129 double age; | 129 double age; |
130 | 130 |
131 Ball(this.root, this.x, this.y, int color) { | 131 Ball(this.root, this.x, this.y, int color) { |
(...skipping 29 matching lines...) Expand all Loading... |
161 y = clientHeight().toDouble(); | 161 y = clientHeight().toDouble(); |
162 vy *= -RESTITUTION; | 162 vy *= -RESTITUTION; |
163 } | 163 } |
164 | 164 |
165 // Position the element. | 165 // Position the element. |
166 setElementPosition(elem, x - RADIUS, y - RADIUS); | 166 setElementPosition(elem, x - RADIUS, y - RADIUS); |
167 | 167 |
168 return true; | 168 return true; |
169 } | 169 } |
170 } | 170 } |
OLD | NEW |