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

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

Issue 968273002: Fixing layout in js output (use full paths rather than just the library name) (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: 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
(Empty)
1 var sunflower;
2 (function(sunflower) {
3 'use strict';
4 let ORANGE = "orange";
5 let SEED_RADIUS = 2;
6 let SCALE_FACTOR = 4;
7 let TAU = math.PI * 2;
8 let MAX_D = 300;
9 let centerX = MAX_D / 2;
10 let centerY = centerX;
11 // Function querySelector: (String) → Element
12 function querySelector(selector) {
13 return dom.document.querySelector(selector);
14 }
15 sunflower.seeds = 0;
16 dart.defineLazyProperties(sunflower, {
17 get slider() {
18 return dart.as(querySelector("#slider"), dom.InputElement);
19 },
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 }
29 });
30 class Circle extends dart.Object {
31 Circle(x, y, radius) {
32 this.x = x;
33 this.y = y;
34 this.radius = radius;
35 }
36 }
37 class CirclePainter extends dart.Object {
38 CirclePainter() {
39 this.color = ORANGE;
40 }
41 draw() {
42 sunflower.context.beginPath();
43 sunflower.context.lineWidth = 2;
44 sunflower.context.fillStyle = this.color;
45 sunflower.context.strokeStyle = this.color;
46 sunflower.context.arc(this.x, this.y, this.radius, 0, TAU, false);
47 sunflower.context.fill();
48 sunflower.context.closePath();
49 sunflower.context.stroke();
50 }
51 }
52 class SunflowerSeed extends dart.mixin(Circle, CirclePainter) {
53 SunflowerSeed(x, y, radius, color) {
54 if (color === void 0)
55 color = null;
56 super.Circle(x, y, radius);
57 if (color !== null)
58 this.color = color;
59 }
60 }
61 // Function main: () → void
62 function main() {
63 sunflower.slider.addEventListener('change', (e) => draw());
64 draw();
65 }
66 // Function draw: () → void
67 function draw() {
68 sunflower.seeds = core.int.parse(sunflower.slider.value);
69 sunflower.context.clearRect(0, 0, MAX_D, MAX_D);
70 for (let i = 0; i < sunflower.seeds; i++) {
71 let theta = dart.notNull(i * dart.notNull(TAU)) / dart.notNull(sunflower.P HI);
72 let r = math.sqrt(i) * SCALE_FACTOR;
73 let x = dart.notNull(centerX) + dart.notNull(dart.notNull(r) * math.cos(th eta));
74 let y = dart.notNull(centerY) - dart.notNull(dart.notNull(r) * math.sin(th eta));
75 new SunflowerSeed(x, y, SEED_RADIUS).draw();
76 }
77 sunflower.notes.textContent = `${sunflower.seeds} seeds`;
78 }
79 // Exports:
80 sunflower.ORANGE = ORANGE;
81 sunflower.SEED_RADIUS = SEED_RADIUS;
82 sunflower.SCALE_FACTOR = SCALE_FACTOR;
83 sunflower.TAU = TAU;
84 sunflower.MAX_D = MAX_D;
85 sunflower.centerX = centerX;
86 sunflower.centerY = centerY;
87 sunflower.querySelector = querySelector;
88 sunflower.Circle = Circle;
89 sunflower.CirclePainter = CirclePainter;
90 sunflower.SunflowerSeed = SunflowerSeed;
91 sunflower.main = main;
92 sunflower.draw = draw;
93 })(sunflower || (sunflower = {}));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698