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

Side by Side Diff: samples/openglui/src/openglui_canvas_tests.dart

Issue 13548002: Add Iterable.fold (and Stream.fold) which replace `reduce`. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « runtime/lib/typeddata.dart ('k') | samples/swarm/swarm_ui_lib/observable/observable.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // Canvas API tests. Some of these are adapted from: 5 // Canvas API tests. Some of these are adapted from:
6 // 6 //
7 // http://www.html5canvastutorials.com/ 7 // http://www.html5canvastutorials.com/
8 8
9 library openglui_canvas_tests; 9 library openglui_canvas_tests;
10 10
(...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 : Color.defaultColor; 1015 : Color.defaultColor;
1016 var specular = Vector.dot(livec, Vector.norm(rd)); 1016 var specular = Vector.dot(livec, Vector.norm(rd));
1017 var scolor = (specular > 0) 1017 var scolor = (specular > 0)
1018 ? Color.scale(Math.pow(specular, thing.surface.roughness), 1018 ? Color.scale(Math.pow(specular, thing.surface.roughness),
1019 light.color) 1019 light.color)
1020 : Color.defaultColor; 1020 : Color.defaultColor;
1021 return col + (thing.surface.diffuse(pos) * lcolor) 1021 return col + (thing.surface.diffuse(pos) * lcolor)
1022 + (thing.surface.specular(pos) * scolor); 1022 + (thing.surface.specular(pos) * scolor);
1023 } 1023 }
1024 }; 1024 };
1025 return scene.lights.reduce(Color.defaultColor, addLight); 1025 return scene.lights.fold(Color.defaultColor, addLight);
1026 } 1026 }
1027 1027
1028 render(Scene scene, CanvasRenderingContext2D ctx, num screenWidth, 1028 render(Scene scene, CanvasRenderingContext2D ctx, num screenWidth,
1029 num screenHeight) { 1029 num screenHeight) {
1030 var getPoint = (x, y, camera) { 1030 var getPoint = (x, y, camera) {
1031 var recenterX = (x) => (x - (screenWidth / 2.0)) / 2.0 / screenWidth; 1031 var recenterX = (x) => (x - (screenWidth / 2.0)) / 2.0 / screenWidth;
1032 var recenterY = (y) => - (y - (screenHeight / 2.0)) / 2.0 / screenHeight; 1032 var recenterY = (y) => - (y - (screenHeight / 2.0)) / 2.0 / screenHeight;
1033 return Vector.norm(camera.forward 1033 return Vector.norm(camera.forward
1034 + Vector.times(recenterX(x), camera.right) 1034 + Vector.times(recenterX(x), camera.right)
1035 + Vector.times(recenterY(y), camera.up)); 1035 + Vector.times(recenterY(y), camera.up));
1036 }; 1036 };
1037 for (int y = 0; y < screenHeight; y++) { 1037 for (int y = 0; y < screenHeight; y++) {
1038 for (int x = 0; x < screenWidth; x++) { 1038 for (int x = 0; x < screenWidth; x++) {
1039 var color = _traceRay(new Ray(scene.camera.pos, 1039 var color = _traceRay(new Ray(scene.camera.pos,
1040 getPoint(x, y, scene.camera) ), scene, 0); 1040 getPoint(x, y, scene.camera) ), scene, 0);
1041 ctx.fillStyle = Color.toDrawingRGB(color); 1041 ctx.fillStyle = Color.toDrawingRGB(color);
1042 ctx.fillRect(x, y, x + 1, y + 1); 1042 ctx.fillRect(x, y, x + 1, y + 1);
1043 } 1043 }
1044 } 1044 }
1045 } 1045 }
1046 } 1046 }
1047 1047
OLDNEW
« no previous file with comments | « runtime/lib/typeddata.dart ('k') | samples/swarm/swarm_ui_lib/observable/observable.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698