| 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 part of clock; | 5 part of clock; |
| 6 | 6 |
| 7 int get clientWidth => window.innerWidth; | 7 int get clientWidth => window.innerWidth; |
| 8 | 8 |
| 9 int get clientHeight => window.innerHeight; | 9 int get clientHeight => window.innerHeight; |
| 10 | 10 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 setElementSize(root, 0.0, 0.0, 0.0, 0.0); | 39 setElementSize(root, 0.0, 0.0, 0.0, 0.0); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void tick(num now) { | 42 void tick(num now) { |
| 43 showFps(1000.0 / (now - lastTime + 0.01)); | 43 showFps(1000.0 / (now - lastTime + 0.01)); |
| 44 | 44 |
| 45 double delta = min((now - lastTime) / 1000.0, 0.1); | 45 double delta = min((now - lastTime) / 1000.0, 0.1); |
| 46 lastTime = now; | 46 lastTime = now; |
| 47 | 47 |
| 48 // incrementally move each ball, removing balls that are offscreen | 48 // incrementally move each ball, removing balls that are offscreen |
| 49 balls = balls.where((ball) => ball.tick(delta)); | 49 balls = balls.where((ball) => ball.tick(delta)).toList(); |
| 50 collideBalls(delta); | 50 collideBalls(delta); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void collideBalls(double delta) { | 53 void collideBalls(double delta) { |
| 54 balls.forEach((b0) { | 54 balls.forEach((b0) { |
| 55 balls.forEach((b1) { | 55 balls.forEach((b1) { |
| 56 // See if the two balls are intersecting. | 56 // See if the two balls are intersecting. |
| 57 double dx = (b0.x - b1.x).abs(); | 57 double dx = (b0.x - b1.x).abs(); |
| 58 double dy = (b0.y - b1.y).abs(); | 58 double dy = (b0.y - b1.y).abs(); |
| 59 double d2 = dx * dx + dy * dy; | 59 double d2 = dx * dx + dy * dy; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 y = clientHeight.toDouble(); | 167 y = clientHeight.toDouble(); |
| 168 vy *= -RESTITUTION; | 168 vy *= -RESTITUTION; |
| 169 } | 169 } |
| 170 | 170 |
| 171 // Position the element. | 171 // Position the element. |
| 172 setElementPosition(elem, x - RADIUS, y - RADIUS); | 172 setElementPosition(elem, x - RADIUS, y - RADIUS); |
| 173 | 173 |
| 174 return true; | 174 return true; |
| 175 } | 175 } |
| 176 } | 176 } |
| OLD | NEW |