forked from CreateJS/EaselJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAPITest.html
executable file
·253 lines (212 loc) · 8.28 KB
/
APITest.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
<!DOCTYPE html>
<html lang="en">
<head>
<title>EaselJS: API Test</title>
<link href="../_assets/css/shared.css" rel="stylesheet" type="text/css"/>
<link href="../_assets/css/examples.css" rel="stylesheet" type="text/css"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="http://samaxesjs.googlecode.com/files/jquery.toc-1.1.4.min.js"></script>
<script src="../lib/easeljs-NEXT.combined.js"></script>
<!-- We also provide hosted minified versions of all CreateJS libraries.
http://code.createjs.com -->
<script src="../_assets/js/Slider.js"></script>
<script id="editable">
var canvasDiv;
var img;
var demos;
var STROKE_COLOR = 'red';
var FILL_COLOR = 'blue';
function init() {
img = new Image();
img.onload = layout;
img.src = "../_assets/art/daisy.png";
canvasDiv = document.getElementById("canvasDiv");
var Graphics = createjs.Graphics;
demos = [
{label: 'lineTo();', graphics: function () {
return new Graphics().beginStroke(STROKE_COLOR).moveTo(5, 35).lineTo(110, 75).endStroke();
}},
{label: 'arcTo();', graphics: function () {
return new Graphics().beginStroke(STROKE_COLOR).moveTo(50, 20).arcTo(150, 20, 150, 70, 50).endStroke();
}},
{label: 'quadraticCurveTo();', graphics: function () {
return new Graphics().beginStroke(STROKE_COLOR).moveTo(0, 25).quadraticCurveTo(45, 50, 35, 25).endStroke();
}},
{label: 'bezierCurveTo();', graphics: function () {
return new Graphics().beginStroke(STROKE_COLOR).moveTo(5, 75).bezierCurveTo(45, 90, 75, 75, -25, -25).endStroke();
}},
{label: 'beginLinearGradientStroke();', graphics: function () {
return new Graphics().beginLinearGradientStroke([STROKE_COLOR, FILL_COLOR], [0, 1], 5, 0, 110, 0).moveTo(5, 25).lineTo(110, 25);
}},
{label: 'drawRect();', graphics: function () {
return new Graphics().beginFill(FILL_COLOR).rect(5, 5, 80, 80);
}},
{label: 'drawRoundRect();', graphics: function () {
return new Graphics().beginFill(FILL_COLOR).drawRoundRect(0, 0, 120, 120, 5);
}},
{label: 'beginLinearGradientFill() with drawRoundRect();', graphics: function () {
return new Graphics().beginLinearGradientFill([FILL_COLOR, STROKE_COLOR], [0, 1], 0, 0, 0, 130).drawRoundRect(0, 0, 120, 120, 5);
}},
{label: 'drawCircle();', graphics: function () {
return new Graphics().beginFill(FILL_COLOR).drawCircle(40, 40, 40);
}},
{label: 'beginRadialGradientFill() with drawCircle();', graphics: function () {
return new Graphics().beginRadialGradientFill([FILL_COLOR, STROKE_COLOR], [0, 1], 40, 40, 0, 40, 40, 40).drawCircle(40, 40, 40);
}},
{label: 'drawEllipse();', graphics: function () {
return new Graphics().beginFill(FILL_COLOR).drawEllipse(5, 5, 60, 120);
}},
{label: 'Draw Hexagon using drawPolyStar();', graphics: function () {
return new Graphics().beginFill(FILL_COLOR).drawPolyStar(60, 60, 60, 6, 0, 45);
}},
{label: 'Draw a star using drawPolyStar();', graphics: function () {
return new Graphics().beginFill(FILL_COLOR).drawPolyStar(80, 80, 70, 5, 0.6, -90);
}},
{label: 'beginBitmapStroke() with drawRect();', graphics: function () {
return new Graphics().setStrokeStyle(25).beginBitmapStroke(img).rect(5, 5, 100, 100);
}},
{label: 'drawRoundRectComplex();', graphics: function () {
return new Graphics().beginFill(FILL_COLOR).drawRoundRectComplex(5, 5, 70, 70, 5, 10, 15, 25);
}},
{label: 'drawCircle(); with beginBitmapFill();', graphics: function () {
return new Graphics().beginStroke(STROKE_COLOR).beginBitmapFill(img).drawCircle(30, 30, 30).endStroke();
}},
{label: 'Text', code: textDemo },
{label: 'Sprite', code: spriteDemo },
{label: 'Blur Filter', code: blurFilter },
{label: 'Remove Red Color Filter', code: colorFilter },
{label: 'ColorMatrixFilter', code: colorMatrixFilter },
{label: 'Mouse Interaction ', code: mouseDemo},
{label: 'Mask', code: maskDemo }
];
}
function mouseDemo(stage) {
//Click one of the shapes.
var sprite = new createjs.Shape();
sprite.graphics.beginFill(FILL_COLOR).drawCircle(30, 30, 20).moveTo(50, 50).drawRect(50, 50, 25, 25);
sprite.addEventListener("click", function (event) {
alert('Click!');
});
stage.addChild(sprite);
}
function maskDemo(stage) {
var shape = new createjs.Shape();
shape.graphics = new createjs.Graphics().beginStroke(STROKE_COLOR).beginBitmapFill(img).drawCircle(35, 25, 20).endStroke();
var image = new createjs.Bitmap(img);
image.mask = shape;
stage.addChild(image);
}
function colorMatrixFilter(stage) {
var greyScaleFilter = new createjs.ColorMatrixFilter([
0.33, 0.33, 0.33, 0, 0, // red
0.33, 0.33, 0.33, 0, 0, // green
0.33, 0.33, 0.33, 0, 0, // blue
0, 0, 0, 1, 0 // alpha
]);
var image = new createjs.Bitmap(img);
image.filters = [greyScaleFilter];
image.cache(0, 0, img.width, img.height);
stage.addChild(image);
}
function blurFilter(stage) {
var blurFilter = new createjs.BlurFilter(5, 2, 2);
var margins = blurFilter.getBounds();
var image = new createjs.Bitmap(img);
image.filters = [blurFilter];
// filters are only displayed when the display object is cached
// later, you can call updateCache() to update changes to your filters
image.cache(margins.x, margins.y, img.width + margins.width, img.height + margins.height);
image.x += image.x + image.width;
stage.addChild(image);
}
function colorFilter(stage) {
var removeRedFilter = new createjs.ColorFilter(0, 1, 1, 1);
var image = new createjs.Bitmap(img);
image.filters = [removeRedFilter];
image.cache(0, 0, img.width, img.height);
stage.addChild(image);
}
function textDemo(stage) {
var txt = new createjs.Text("Hello CreateJS!", "24px Arial", FILL_COLOR);
txt.lineWidth = 150;
stage.addChild(txt);
}
function spriteDemo(stage) {
var ss = new createjs.SpriteSheet({ "animations": {
"run": [0, 25, "jump", 2],
"jump": [26, 63, "run"]},
"images": ["../_assets/art/spritesheet_grant.png"],
"frames": {
"regX": 0,
"regY": 0,
"height": 293,
"width": 166,
"count": 64
}
});
var sprite = new createjs.Sprite(ss, "run");
sprite.scaleY = sprite.scaleX = 0.4;
stage.addChild(sprite);
createjs.Ticker.addEventListener("tick", stage);
}
function layout() {
while (demos.length) {
var demo = demos.shift();
var demoWrap = $('<table width="100%"><tr><td width="50" valign="top"></td><td valign="top"></td></tr></table>');
var canvas = $('<canvas width="150" height="150" style="clear: left;" />');
demoWrap.prepend($('<h2 style="visibility: collapse; width: 1px; height: 1px;" id="' + demos.length + '">' + demo.label + '</h1>'))
var codeString;
if (demo.graphics) {
codeString = demo.graphics.toString();
codeString = codeString.substring(codeString.indexOf('return ') + 7, codeString.lastIndexOf('}'));
} else {
codeString = demo.code.toString();
codeString = codeString.substring(codeString.indexOf('{') + 1, codeString.lastIndexOf('}'));
}
codeString = codeString.split('STROKE_COLOR').join('"' + STROKE_COLOR + '"').split('FILL_COLOR').join('"' + FILL_COLOR + '"');
codeString = '//' + demo.label + '\n' + codeString;
var code = $('<div style="width:750px">' +
'<pre>' +
'<code data-language="javascript">' + codeString + '</code>' +
'</pre>' +
'</div>');
$(demoWrap.find('td')[0]).append(canvas);
$(demoWrap.find('td')[1]).append(code);
canvasDiv.appendChild(demoWrap.get(0));
drawToCanvas(canvas, demo);
}
$('#toc').toc();
}
function drawToCanvas(canvas, data) {
var stage = new createjs.Stage(canvas.get(0));
if (data.graphics) {
var shape = new createjs.Shape(data.graphics());
stage.addChild(shape);
} else {
data.code(stage, canvas.get(0));
}
stage.update();
}
$(init);
</script>
<style>
code {
background: none;
}
canvas {
border: 1px solid #DDD;
}
</style>
</head>
<body>
<header class="EaselJS">
<h1>API Test</h1>
<p>Demonstrates many of the visual APIs.</p>
</header>
<div style="overflow: scroll;" class="content" id="wrap">
<div id="toc"></div>
<div id="canvasDiv" style=" padding-left:25px; float: left; height: 150px">
</div>
</div>
</body>
</html>