Debian Codegraph @

closure-library/closure/goog/demos/graphics/tiger.html

raw
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 Copyright 2007 The Closure Library Authors. All Rights Reserved.
5
6 Use of this source code is governed by the Apache License, Version 2.0.
7 See the COPYING file for details.
8 -->
9 <head>
10 <title>The SVG tiger drawn with goog.graphics</title>
11 <script type="text/javascript" src="../../base.js"></script>
12 <script type="text/javascript">
13
14 goog.require('goog.dom');
15 goog.require('goog.graphics');
16
17 </script>
18 <script src="tigerdata.js"></script>
19 <script type="text/javascript">
20
21 function drawTiger() {
22 var graphics = goog.graphics.createGraphics(600, 600);
23
24 var fills = {};
25 var strokes = {};
26
27 var segmentFunctions = {
28 'z': goog.graphics.Path.prototype.close,
29 'M': goog.graphics.Path.prototype.moveTo,
30 'L': goog.graphics.Path.prototype.lineTo,
31 'C': goog.graphics.Path.prototype.curveTo
32 };
33
34 function createPath(stroke, fill, paths) {
35
36 var fillObject;
37
38 if (fill == null) {
39 fillObject = null;
40 } else if (fill in fills) {
41 fillObject = fills[fill];
42 } else {
43 fillObject = new goog.graphics.SolidFill(fill);
44 fills[fill] = fillObject;
45 }
46
47 var strokeObject;
48 if (stroke == null) {
49 strokeObject = null;
50 } else {
51 var strokeKey;
52 if (typeof stroke == 'string') {
53 strokeKey = stroke;
54 } else {
55 strokeKey = stroke.c + stroke.w;
56 }
57 if (strokeKey in strokes) {
58 strokeObject = strokes[strokeKey];
59 } else if (typeof stroke == 'string') {
60 strokeObject = null;
61 } else {
62 strokeObject = new goog.graphics.Stroke(stroke.w, stroke.c);
63 }
64 }
65 strokes[strokeKey] = strokeObject;
66
67 var pathObject = graphics.createPath();
68 for (var i = 0, path; path = paths[i]; i++) {
69 segmentFunctions[path.t].apply(pathObject, path.p);
70 }
71
72 graphics.drawPath(pathObject, strokeObject, fillObject);
73 }
74
75 var d0 = new Date;
76 for (var i = 0; i < tigerData.length; i++) {
77 var d = tigerData[i];
78 createPath(d.s, d.f, d.p);
79 }
80
81 graphics.render(goog.dom.getElement('tiger-container'));
82 var d1 = new Date;
83
84 goog.dom.setTextContent(goog.dom.getElement('out'),
85 'Creating took: ' + (d1 - d0));
86 window.setTimeout(function() {
87 var d2 = new Date;
88 goog.dom.setTextContent(goog.dom.getElement('out-2'),
89 'Drawing took: ' + (d2 - d1));
90 }, 1);
91 }
92
93
94 </script>
95 </head>
96 <body>
97
98 <div id="tiger-container" style='border:1px solid black;width:600px;height:600px'></div>
99 <div id="out"></div>
100 <div id="out-2"></div>
101 <script>
102 drawTiger();
103 </script>
104 </body>
105 </html>