Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: test/codegen/sunflower/sunflower.dart

Issue 1028793002: Transitive inference using SCC (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: cl comments Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 library sunflower; 5 library sunflower;
6 6
7 import 'dart:math'; 7 import 'dart:math';
8 import 'dom.dart'; 8 import 'dom.dart';
9 9
10 const String ORANGE = "orange"; 10 const ORANGE = "orange";
11 const int SEED_RADIUS = 2; 11 const SEED_RADIUS = 2;
12 const int SCALE_FACTOR = 4; 12 const SCALE_FACTOR = 4;
13 const num TAU = PI * 2; 13 const TAU = PI * 2;
14 const int MAX_D = 300; 14 const MAX_D = 300;
15 // TODO(sigmund): remove `num` here, this is to workaround dartbug.com/22937
15 const num centerX = MAX_D / 2; 16 const num centerX = MAX_D / 2;
16 const num centerY = centerX; 17 const num centerY = centerX;
17 18
18 Element querySelector(String selector) => document.querySelector(selector); 19 Element querySelector(String selector) => document.querySelector(selector);
19 20
20 final InputElement slider = querySelector("#slider"); 21 final InputElement slider = querySelector("#slider");
21 final Element notes = querySelector("#notes"); 22 final notes = querySelector("#notes");
22 final num PHI = (sqrt(5) + 1) / 2; 23 final PHI = (sqrt(5) + 1) / 2;
23 int seeds = 0; 24 int seeds = 0;
24 final CanvasRenderingContext2D context = 25 final CanvasRenderingContext2D context =
25 (querySelector("#canvas") as CanvasElement).getContext('2d'); 26 (querySelector("#canvas") as CanvasElement).getContext('2d');
26 27
27 void main() { 28 void main() {
28 slider.addEventListener('change', (e) => draw()); 29 slider.addEventListener('change', (e) => draw());
29 draw(); 30 draw();
30 } 31 }
31 32
32 /// Draw the complete figure for the current number of seeds. 33 /// Draw the complete figure for the current number of seeds.
33 void draw() { 34 void draw() {
34 seeds = int.parse(slider.value); 35 seeds = int.parse(slider.value);
35 context.clearRect(0, 0, MAX_D, MAX_D); 36 context.clearRect(0, 0, MAX_D, MAX_D);
36 for (var i = 0; i < seeds; i++) { 37 for (var i = 0; i < seeds; i++) {
37 final num theta = i * TAU / PHI; 38 final theta = i * TAU / PHI;
38 final num r = sqrt(i) * SCALE_FACTOR; 39 final r = sqrt(i) * SCALE_FACTOR;
39 final num x = centerX + r * cos(theta); 40 final x = centerX + r * cos(theta);
40 final num y = centerY - r * sin(theta); 41 final y = centerY - r * sin(theta);
41 new SunflowerSeed(x, y, SEED_RADIUS).draw(); 42 new SunflowerSeed(x, y, SEED_RADIUS).draw();
42 } 43 }
43 notes.textContent = "$seeds seeds"; 44 notes.textContent = "$seeds seeds";
44 } 45 }
45 46
46 // This example was modified to use classes and mixins. 47 // This example was modified to use classes and mixins.
47 class SunflowerSeed extends Circle with CirclePainter { 48 class SunflowerSeed extends Circle with CirclePainter {
48 SunflowerSeed(num x, num y, num radius, [String color]) 49 SunflowerSeed(num x, num y, num radius, [String color])
49 : super(x, y, radius) { 50 : super(x, y, radius) {
50 if (color != null) this.color = color; 51 if (color != null) this.color = color;
(...skipping 16 matching lines...) Expand all
67 ..closePath() 68 ..closePath()
68 ..stroke(); 69 ..stroke();
69 } 70 }
70 } 71 }
71 72
72 class Circle { 73 class Circle {
73 final num x, y, radius; 74 final num x, y, radius;
74 75
75 Circle(this.x, this.y, this.radius); 76 Circle(this.x, this.y, this.radius);
76 } 77 }
OLDNEW
« no previous file with comments | « test/codegen/expect/sunflower/sunflower.txt ('k') | test/dart_codegen/expect/async/stream_pipe.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698