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

Side by Side Diff: test/codegen/expect/sunflower/sunflower.js

Issue 949383003: use js_ast instead of strings to generate JS (Closed) Base URL: git@github.com:dart-lang/dart-dev-compiler.git@master
Patch Set: add redirecting ctor test Created 5 years, 10 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
« no previous file with comments | « test/codegen/expect/methods/methods.js ('k') | test/codegen/expect/typed_data/typed_data.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 var sunflower; 1 var sunflower;
2 (function (sunflower) { 2 (function(sunflower) {
3 'use strict'; 3 'use strict';
4 let ORANGE = "orange"; 4 let ORANGE = "orange";
5 let SEED_RADIUS = 2; 5 let SEED_RADIUS = 2;
6 let SCALE_FACTOR = 4; 6 let SCALE_FACTOR = 4;
7 let TAU = math.PI * 2; 7 let TAU = math.PI * 2;
8 let MAX_D = 300; 8 let MAX_D = 300;
9 let centerX = MAX_D / 2; 9 let centerX = MAX_D / 2;
10 let centerY = centerX; 10 let centerY = centerX;
11 // Function querySelector: (String) → Element 11 // Function querySelector: (String) → Element
12 function querySelector(selector) { return dom.document.querySelector(selector) ; } 12 function querySelector(selector) {
13 13 return dom.document.querySelector(selector);
14 }
14 sunflower.seeds = 0; 15 sunflower.seeds = 0;
15 dart.defineLazyProperties(sunflower, { 16 dart.defineLazyProperties(sunflower, {
16 get slider() { return dart.as(querySelector("#slider"), dom.InputElement) }, 17 get slider() {
17 get notes() { return querySelector("#notes") }, 18 return dart.as(querySelector("#slider"), dom.InputElement);
18 get PHI() { return (math.sqrt(5) + 1) / 2 }, 19 },
19 get context() { return dart.as((dart.as(querySelector("#canvas"), dom.Canvas Element)).getContext('2d'), dom.CanvasRenderingContext2D) }, 20 get notes() {
21 return querySelector("#notes");
22 },
23 get PHI() {
24 return (math.sqrt(5) + 1) / 2;
25 },
26 get context() {
27 return dart.as(dart.as(querySelector("#canvas"), dom.CanvasElement).getCon text('2d'), dom.CanvasRenderingContext2D);
28 }
20 }); 29 });
21
22 class Circle extends dart.Object { 30 class Circle extends dart.Object {
23 Circle(x, y, radius) { 31 Circle(x, y, radius) {
24 this.x = x; 32 this.x = x;
25 this.y = y; 33 this.y = y;
26 this.radius = radius; 34 this.radius = radius;
27 } 35 }
28 } 36 }
29
30 class CirclePainter extends dart.Object { 37 class CirclePainter extends dart.Object {
31 CirclePainter() { 38 CirclePainter() {
32 this.color = ORANGE; 39 this.color = ORANGE;
33 } 40 }
34 draw() { 41 draw() {
35 sunflower.context.beginPath(); 42 sunflower.context.beginPath();
36 sunflower.context.lineWidth = 2; 43 sunflower.context.lineWidth = 2;
37 sunflower.context.fillStyle = this.color; 44 sunflower.context.fillStyle = this.color;
38 sunflower.context.strokeStyle = this.color; 45 sunflower.context.strokeStyle = this.color;
39 sunflower.context.arc(this.x, this.y, this.radius, 0, TAU, false); 46 sunflower.context.arc(this.x, this.y, this.radius, 0, TAU, false);
40 sunflower.context.fill(); 47 sunflower.context.fill();
41 sunflower.context.closePath(); 48 sunflower.context.closePath();
42 sunflower.context.stroke(); 49 sunflower.context.stroke();
43 } 50 }
44 } 51 }
45
46 class SunflowerSeed extends dart.mixin(Circle, CirclePainter) { 52 class SunflowerSeed extends dart.mixin(Circle, CirclePainter) {
47 SunflowerSeed(x, y, radius, color) { 53 SunflowerSeed(x, y, radius, color) {
48 if (color === undefined) color = null; 54 if (color === void 0)
55 color = null;
49 super.Circle(x, y, radius); 56 super.Circle(x, y, radius);
50 if (color !== null) this.color = color; 57 if (color !== null)
58 this.color = color;
51 } 59 }
52 } 60 }
53
54 // Function main: () → void 61 // Function main: () → void
55 function main() { 62 function main() {
56 sunflower.slider.addEventListener('change', (e) => draw()); 63 sunflower.slider.addEventListener('change', (e) => draw());
57 draw(); 64 draw();
58 } 65 }
59
60 // Function draw: () → void 66 // Function draw: () → void
61 function draw() { 67 function draw() {
62 sunflower.seeds = core.int.parse(sunflower.slider.value); 68 sunflower.seeds = core.int.parse(sunflower.slider.value);
63 sunflower.context.clearRect(0, 0, MAX_D, MAX_D); 69 sunflower.context.clearRect(0, 0, MAX_D, MAX_D);
64 for (let i = 0; i < sunflower.seeds; i++) { 70 for (let i = 0; i < sunflower.seeds; i++) {
65 let theta = dart.notNull(i * dart.notNull(TAU)) / dart.notNull(sunflower.P HI); 71 let theta = dart.notNull(i * dart.notNull(TAU)) / dart.notNull(sunflower.P HI);
66 let r = math.sqrt(i) * SCALE_FACTOR; 72 let r = math.sqrt(i) * SCALE_FACTOR;
67 let x = dart.notNull(centerX) + dart.notNull(dart.notNull(r) * math.cos(th eta)); 73 let x = dart.notNull(centerX) + dart.notNull(dart.notNull(r) * math.cos(th eta));
68 let y = dart.notNull(centerY) - dart.notNull(dart.notNull(r) * math.sin(th eta)); 74 let y = dart.notNull(centerY) - dart.notNull(dart.notNull(r) * math.sin(th eta));
69 new SunflowerSeed(x, y, SEED_RADIUS).draw(); 75 new SunflowerSeed(x, y, SEED_RADIUS).draw();
70 } 76 }
71 sunflower.notes.textContent = `${sunflower.seeds} seeds`; 77 sunflower.notes.textContent = `${sunflower.seeds} seeds`;
72 } 78 }
73
74 // Exports: 79 // Exports:
75 sunflower.ORANGE = ORANGE; 80 sunflower.ORANGE = ORANGE;
76 sunflower.SEED_RADIUS = SEED_RADIUS; 81 sunflower.SEED_RADIUS = SEED_RADIUS;
77 sunflower.SCALE_FACTOR = SCALE_FACTOR; 82 sunflower.SCALE_FACTOR = SCALE_FACTOR;
78 sunflower.TAU = TAU; 83 sunflower.TAU = TAU;
79 sunflower.MAX_D = MAX_D; 84 sunflower.MAX_D = MAX_D;
80 sunflower.centerX = centerX; 85 sunflower.centerX = centerX;
81 sunflower.centerY = centerY; 86 sunflower.centerY = centerY;
82 sunflower.querySelector = querySelector; 87 sunflower.querySelector = querySelector;
83 sunflower.Circle = Circle; 88 sunflower.Circle = Circle;
84 sunflower.CirclePainter = CirclePainter; 89 sunflower.CirclePainter = CirclePainter;
85 sunflower.SunflowerSeed = SunflowerSeed; 90 sunflower.SunflowerSeed = SunflowerSeed;
86 sunflower.main = main; 91 sunflower.main = main;
87 sunflower.draw = draw; 92 sunflower.draw = draw;
88 })(sunflower || (sunflower = {})); 93 })(sunflower || (sunflower = {}));
OLDNEW
« no previous file with comments | « test/codegen/expect/methods/methods.js ('k') | test/codegen/expect/typed_data/typed_data.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698