-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathGraphics_setStrokeDash.html
executable file
·63 lines (48 loc) · 1.86 KB
/
Graphics_setStrokeDash.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>EaselJS: Marching Ants</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="../_assets/js/examples.js"></script>
<script src="../lib/easeljs-NEXT.js"></script>
<!-- We also provide hosted minified versions of all CreateJS libraries.
http://code.createjs.com -->
<script id="editable">
var stage, dashCmd;
function init() {
stage = new createjs.Stage("myCanvas");
var shape = new createjs.Shape();
stage.addChild(shape);
// set a stroke dash, and save the command object:
dashCmd = shape.graphics.setStrokeDash([7,3]).command;
// draw a couple of rectangles with the stroke dash:
shape.graphics.setStrokeStyle(2).beginStroke("black").rect(20,20,100,100);
// this rectangle is drawn backwards, which will reverse the direction of the effect:
shape.graphics.setStrokeStyle(4).beginStroke("blue").rect(240,20,-100,100);
// reset the stroke dash, and draw a red rectangle:
shape.graphics.setStrokeDash();
shape.graphics.setStrokeStyle(4).beginStroke("red").rect(260,20,100,100);
// dotted dash:
shape.graphics.setStrokeDash([2,2]);
shape.graphics.setStrokeStyle(2).beginStroke("green").rect(380,20,100,100);
createjs.Ticker.timingMode = createjs.Ticker.RAF;
createjs.Ticker.on("tick", tick, this);
}
function tick(evt) {
// increment the offset to animate the marching ants:
dashCmd.offset++;
// update the stage:
stage.update(evt);
}
</script>
</head>
<body onload="init()">
<header class="EaselJS">
<h1>Marching Ants</h1>
<p>This example uses <code>Graphics.setStrokeDash()</code> and <code>Graphics.command</code> to create a marching ants effect.</p>
</header>
<canvas id="myCanvas" width="960" height="400"></canvas>
</body>
</html>