| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 #library('sunflower'); | 5 #library('sunflower'); |
| 6 | 6 |
| 7 #import('dart:dom'); | 7 #import('dart:html'); |
| 8 | 8 |
| 9 #resource('sunflower.css'); | 9 #resource('sunflower.css'); |
| 10 | 10 |
| 11 main() { | 11 main() { |
| 12 new Sunflower(); | 12 new Sunflower(); |
| 13 } | 13 } |
| 14 | 14 |
| 15 class Sunflower { | 15 class Sunflower { |
| 16 | 16 |
| 17 Sunflower() { | 17 Sunflower() { |
| 18 PHI = (Math.sqrt(5) + 1) / 2; | 18 PHI = (Math.sqrt(5) + 1) / 2; |
| 19 var doc = window.document; | |
| 20 | 19 |
| 21 HTMLCanvasElement canvas = doc.getElementById("canvas"); | 20 CanvasElement canvas = document.query("#canvas"); |
| 22 xc = yc = MAX_D / 2; | 21 xc = yc = MAX_D / 2; |
| 23 ctx = canvas.getContext("2d"); | 22 ctx = canvas.getContext("2d"); |
| 24 | 23 |
| 25 HTMLInputElement slider = doc.getElementById("slider"); | 24 InputElement slider = document.query("#slider"); |
| 26 slider.addEventListener('change', (Event e) { | 25 slider.on.change.add((Event e) { |
| 27 seeds = Math.parseInt(slider.value); | 26 seeds = Math.parseInt(slider.value); |
| 28 drawFrame(); | 27 drawFrame(); |
| 29 }, true); | 28 }, true); |
| 30 | 29 |
| 31 seeds = Math.parseInt(slider.value); | 30 seeds = Math.parseInt(slider.value); |
| 32 | 31 |
| 33 drawFrame(); | 32 drawFrame(); |
| 34 } | 33 } |
| 35 | 34 |
| 36 // Draw the complete figure for the current number of seeds. | 35 // Draw the complete figure for the current number of seeds. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 62 num seeds = 0; | 61 num seeds = 0; |
| 63 | 62 |
| 64 static final SEED_RADIUS = 2; | 63 static final SEED_RADIUS = 2; |
| 65 static final SCALE_FACTOR = 4; | 64 static final SCALE_FACTOR = 4; |
| 66 static final TAU = Math.PI * 2; | 65 static final TAU = Math.PI * 2; |
| 67 var PHI; | 66 var PHI; |
| 68 static final MAX_D = 300; | 67 static final MAX_D = 300; |
| 69 static final String ORANGE = "orange"; | 68 static final String ORANGE = "orange"; |
| 70 | 69 |
| 71 } | 70 } |
| OLD | NEW |