| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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:html'; |
| 7 import 'dart:math'; | 8 import 'dart:math'; |
| 8 | 9 |
| 9 import 'circle.dart'; | 10 import 'circle.dart'; |
| 10 import 'dom.dart'; | |
| 11 import 'painter.dart'; | 11 import 'painter.dart'; |
| 12 | 12 |
| 13 const SEED_RADIUS = 2; | 13 const SEED_RADIUS = 2; |
| 14 const SCALE_FACTOR = 4; | 14 const SCALE_FACTOR = 4; |
| 15 const MAX_D = 300; | 15 const MAX_D = 300; |
| 16 const centerX = MAX_D / 2; | 16 const centerX = MAX_D / 2; |
| 17 const centerY = centerX; | 17 const centerY = centerX; |
| 18 | 18 |
| 19 Element querySelector(String selector) => document.querySelector(selector); | 19 Element querySelector(String selector) => document.querySelector(selector); |
| 20 final canvas = querySelector("#canvas") as CanvasElement; | 20 final canvas = querySelector("#canvas") as CanvasElement; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 34 void draw() { | 34 void draw() { |
| 35 seeds = int.parse(slider.value); | 35 seeds = int.parse(slider.value); |
| 36 context.clearRect(0, 0, MAX_D, MAX_D); | 36 context.clearRect(0, 0, MAX_D, MAX_D); |
| 37 for (var i = 0; i < seeds; i++) { | 37 for (var i = 0; i < seeds; i++) { |
| 38 final theta = i * TAU / PHI; | 38 final theta = i * TAU / PHI; |
| 39 final r = sqrt(i) * SCALE_FACTOR; | 39 final r = sqrt(i) * SCALE_FACTOR; |
| 40 final x = centerX + r * cos(theta); | 40 final x = centerX + r * cos(theta); |
| 41 final y = centerY - r * sin(theta); | 41 final y = centerY - r * sin(theta); |
| 42 new SunflowerSeed(x, y, SEED_RADIUS).draw(context); | 42 new SunflowerSeed(x, y, SEED_RADIUS).draw(context); |
| 43 } | 43 } |
| 44 notes.textContent = "$seeds seeds"; | 44 notes.text = "$seeds seeds"; |
| 45 } | 45 } |
| 46 | 46 |
| 47 // This example was modified to use classes and mixins. | 47 // This example was modified to use classes and mixins. |
| 48 class SunflowerSeed extends Circle with CirclePainter { | 48 class SunflowerSeed extends Circle with CirclePainter { |
| 49 SunflowerSeed(num x, num y, num radius, [String color]) | 49 SunflowerSeed(num x, num y, num radius, [String color]) |
| 50 : super(x, y, radius) { | 50 : super(x, y, radius) { |
| 51 if (color != null) this.color = color; | 51 if (color != null) this.color = color; |
| 52 } | 52 } |
| 53 } | 53 } |
| 54 | |
| 55 | |
| OLD | NEW |