| OLD | NEW |
| 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 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 ctx.setLineDash([]); | 493 ctx.setLineDash([]); |
| 494 ctx.strokeStyle = "#0000FF"; | 494 ctx.strokeStyle = "#0000FF"; |
| 495 ctx.strokeStyle = "rgba(128,128,128, 0.5)"; | 495 ctx.strokeStyle = "rgba(128,128,128, 0.5)"; |
| 496 ctx.strokeRect(width / 5, height / 10, width / 2, height / 8); | 496 ctx.strokeRect(width / 5, height / 10, width / 2, height / 8); |
| 497 log("Width = $width"); | 497 log("Width = $width"); |
| 498 } | 498 } |
| 499 | 499 |
| 500 void loadImage() { | 500 void loadImage() { |
| 501 initTest("Image loading"); | 501 initTest("Image loading"); |
| 502 var imageObj = new ImageElement(); | 502 var imageObj = new ImageElement(); |
| 503 // TODO(Gram): Change gl.dart to handle to onLoad.listen. | 503 var sub; |
| 504 imageObj.on.load.add((e) { | 504 sub = imageObj.onLoad.listen((e) { |
| 505 ctx.drawImage(e, 69, 50); | 505 ctx.drawImage(e.target, 69, 50); |
| 506 sub.cancel(); |
| 506 }); | 507 }); |
| 507 imageObj.src = 'chrome.png'; | 508 imageObj.src = 'chrome.png'; |
| 508 } | 509 } |
| 509 | 510 |
| 510 void clip() { | 511 void clip() { |
| 511 initTest("Clipping"); | 512 initTest("Clipping"); |
| 512 var x = width / 2; | 513 var x = width / 2; |
| 513 var y = height / 2; | 514 var y = height / 2; |
| 514 var radius = height / 4; | 515 var radius = height / 4; |
| 515 var offset = 2 * radius / 3; | 516 var offset = 2 * radius / 3; |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 case 23: | 735 case 23: |
| 735 var rayTracer = new RayTracer(); | 736 var rayTracer = new RayTracer(); |
| 736 rayTracer.render(defaultScene(), ctx, width, height); | 737 rayTracer.render(defaultScene(), ctx, width, height); |
| 737 break; | 738 break; |
| 738 default: | 739 default: |
| 739 if (testnum < 0) { | 740 if (testnum < 0) { |
| 740 testnum = 23; | 741 testnum = 23; |
| 741 } else { | 742 } else { |
| 742 testnum = 0; | 743 testnum = 0; |
| 743 } | 744 } |
| 744 update(); | 745 return; |
| 745 break; | |
| 746 } | 746 } |
| 747 isDirty = false; | 747 isDirty = false; |
| 748 } | 748 } |
| 749 | 749 |
| 750 // Raytracer adapted from https://gist.github.com/mythz/3817303. | 750 // Raytracer adapted from https://gist.github.com/mythz/3817303. |
| 751 | 751 |
| 752 Scene defaultScene() => | 752 Scene defaultScene() => |
| 753 new Scene( | 753 new Scene( |
| 754 [new Plane(new Vector(0.0, 1.0, 0.0), 0.0, Surfaces.checkerboard), | 754 [new Plane(new Vector(0.0, 1.0, 0.0), 0.0, Surfaces.checkerboard), |
| 755 new Sphere(new Vector(0.0, 1.0, -0.25), 1.0, Surfaces.shiny), | 755 new Sphere(new Vector(0.0, 1.0, -0.25), 1.0, Surfaces.shiny), |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 999 for (int x = 0; x < screenWidth; x++) { | 999 for (int x = 0; x < screenWidth; x++) { |
| 1000 var color = _traceRay(new Ray(scene.camera.pos, | 1000 var color = _traceRay(new Ray(scene.camera.pos, |
| 1001 getPoint(x, y, scene.camera) ), scene, 0); | 1001 getPoint(x, y, scene.camera) ), scene, 0); |
| 1002 ctx.fillStyle = Color.toDrawingRGB(color); | 1002 ctx.fillStyle = Color.toDrawingRGB(color); |
| 1003 ctx.fillRect(x, y, x + 1, y + 1); | 1003 ctx.fillRect(x, y, x + 1, y + 1); |
| 1004 } | 1004 } |
| 1005 } | 1005 } |
| 1006 } | 1006 } |
| 1007 } | 1007 } |
| 1008 | 1008 |
| OLD | NEW |