forked from processing-js/processing-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPShape.js
More file actions
executable file
·661 lines (656 loc) · 27.2 KB
/
Copy pathPShape.js
File metadata and controls
executable file
·661 lines (656 loc) · 27.2 KB
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
module.exports = function(options) {
var PConstants = options.PConstants,
PMatrix2D = options.PMatrix2D,
PMatrix3D = options.PMatrix3D;
/**
* Datatype for storing shapes. Processing can currently load and display SVG (Scalable Vector Graphics) shapes.
* Before a shape is used, it must be loaded with the <b>loadShape()</b> function. The <b>shape()</b> function is used to draw the shape to the display window.
* The <b>PShape</b> object contain a group of methods, linked below, that can operate on the shape data.
* <br><br>The <b>loadShape()</b> method supports SVG files created with Inkscape and Adobe Illustrator.
* It is not a full SVG implementation, but offers some straightforward support for handling vector data.
*
* @param {int} family the shape type, one of GROUP, PRIMITIVE, PATH, or GEOMETRY
*
* @see #shape()
* @see #loadShape()
* @see #shapeMode()
*/
var PShape = function(family) {
this.family = family || PConstants.GROUP;
this.visible = true;
this.style = true;
this.children = [];
this.nameTable = [];
this.params = [];
this.name = "";
this.image = null; //type PImage
this.matrix = null;
this.kind = null;
this.close = null;
this.width = null;
this.height = null;
this.parent = null;
};
/**
* PShape methods
* missing: findChild(), apply(), contains(), findChild(), getPrimitive(), getParams(), getVertex() , getVertexCount(),
* getVertexCode() , getVertexCodes() , getVertexCodeCount(), getVertexX(), getVertexY(), getVertexZ()
*/
PShape.prototype = {
/**
* @member PShape
* The isVisible() function returns a boolean value "true" if the image is set to be visible, "false" if not. This is modified with the <b>setVisible()</b> parameter.
* <br><br>The visibility of a shape is usually controlled by whatever program created the SVG file.
* For instance, this parameter is controlled by showing or hiding the shape in the layers palette in Adobe Illustrator.
*
* @return {boolean} returns "true" if the image is set to be visible, "false" if not
*/
isVisible: function(){
return this.visible;
},
/**
* @member PShape
* The setVisible() function sets the shape to be visible or invisible. This is determined by the value of the <b>visible</b> parameter.
* <br><br>The visibility of a shape is usually controlled by whatever program created the SVG file.
* For instance, this parameter is controlled by showing or hiding the shape in the layers palette in Adobe Illustrator.
*
* @param {boolean} visible "false" makes the shape invisible and "true" makes it visible
*/
setVisible: function (visible){
this.visible = visible;
},
/**
* @member PShape
* The disableStyle() function disables the shape's style data and uses Processing's current styles. Styles include attributes such as colors, stroke weight, and stroke joints.
* Overrides this shape's style information and uses PGraphics styles and colors. Identical to ignoreStyles(true). Also disables styles for all child shapes.
*/
disableStyle: function(){
this.style = false;
for(var i = 0, j=this.children.length; i<j; i++) {
this.children[i].disableStyle();
}
},
/**
* @member PShape
* The enableStyle() function enables the shape's style data and ignores Processing's current styles. Styles include attributes such as colors, stroke weight, and stroke joints.
*/
enableStyle: function(){
this.style = true;
for(var i = 0, j=this.children.length; i<j; i++) {
this.children[i].enableStyle();
}
},
/**
* @member PShape
* The getFamily function returns the shape type
*
* @return {int} the shape type, one of GROUP, PRIMITIVE, PATH, or GEOMETRY
*/
getFamily: function(){
return this.family;
},
/**
* @member PShape
* The getWidth() function gets the width of the drawing area (not necessarily the shape boundary).
*/
getWidth: function(){
return this.width;
},
/**
* @member PShape
* The getHeight() function gets the height of the drawing area (not necessarily the shape boundary).
*/
getHeight: function(){
return this.height;
},
/**
* @member PShape
* The setName() function sets the name of the shape
*
* @param {String} name the name of the shape
*/
setName: function(name){
this.name = name;
},
/**
* @member PShape
* The getName() function returns the name of the shape
*
* @return {String} the name of the shape
*/
getName: function(){
return this.name;
},
/**
* @member PShape
* Called by the following (the shape() command adds the g)
* PShape s = loadShapes("blah.svg");
* shape(s);
*/
draw: function(renderContext) {
if(!renderContext) {
throw "render context missing for draw() in PShape";
}
if (this.visible) {
this.pre(renderContext);
this.drawImpl(renderContext);
this.post(renderContext);
}
},
/**
* @member PShape
* the drawImpl() function draws the SVG document.
*/
drawImpl: function(renderContext) {
if (this.family === PConstants.GROUP) {
this.drawGroup(renderContext);
} else if (this.family === PConstants.PRIMITIVE) {
this.drawPrimitive(renderContext);
} else if (this.family === PConstants.GEOMETRY) {
this.drawGeometry(renderContext);
} else if (this.family === PConstants.PATH) {
this.drawPath(renderContext);
}
},
/**
* @member PShape
* The drawPath() function draws the <path> part of the SVG document.
*/
drawPath: function(renderContext) {
var i, j;
if (this.vertices.length === 0) { return; }
renderContext.beginShape();
if (this.vertexCodes.length === 0) { // each point is a simple vertex
if (this.vertices[0].length === 2) { // drawing 2D vertices
for (i = 0, j = this.vertices.length; i < j; i++) {
renderContext.vertex(this.vertices[i][0], this.vertices[i][1]);
}
} else { // drawing 3D vertices
for (i = 0, j = this.vertices.length; i < j; i++) {
renderContext.vertex(this.vertices[i][0],
this.vertices[i][1],
this.vertices[i][2]);
}
}
} else { // coded set of vertices
var index = 0;
if (this.vertices[0].length === 2) { // drawing a 2D path
for (i = 0, j = this.vertexCodes.length; i < j; i++) {
if (this.vertexCodes[i] === PConstants.VERTEX) {
renderContext.vertex(this.vertices[index][0], this.vertices[index][1], this.vertices[index].moveTo);
renderContext.breakShape = false;
index++;
} else if (this.vertexCodes[i] === PConstants.BEZIER_VERTEX) {
renderContext.bezierVertex(this.vertices[index+0][0],
this.vertices[index+0][1],
this.vertices[index+1][0],
this.vertices[index+1][1],
this.vertices[index+2][0],
this.vertices[index+2][1]);
index += 3;
} else if (this.vertexCodes[i] === PConstants.CURVE_VERTEX) {
renderContext.curveVertex(this.vertices[index][0],
this.vertices[index][1]);
index++;
} else if (this.vertexCodes[i] === PConstants.BREAK) {
renderContext.breakShape = true;
}
}
} else { // drawing a 3D path
for (i = 0, j = this.vertexCodes.length; i < j; i++) {
if (this.vertexCodes[i] === PConstants.VERTEX) {
renderContext.vertex(this.vertices[index][0],
this.vertices[index][1],
this.vertices[index][2]);
if (this.vertices[index].moveTo === true) {
vertArray[vertArray.length-1].moveTo = true;
} else if (this.vertices[index].moveTo === false) {
vertArray[vertArray.length-1].moveTo = false;
}
renderContext.breakShape = false;
} else if (this.vertexCodes[i] === PConstants.BEZIER_VERTEX) {
renderContext.bezierVertex(this.vertices[index+0][0],
this.vertices[index+0][1],
this.vertices[index+0][2],
this.vertices[index+1][0],
this.vertices[index+1][1],
this.vertices[index+1][2],
this.vertices[index+2][0],
this.vertices[index+2][1],
this.vertices[index+2][2]);
index += 3;
} else if (this.vertexCodes[i] === PConstants.CURVE_VERTEX) {
renderContext.curveVertex(this.vertices[index][0],
this.vertices[index][1],
this.vertices[index][2]);
index++;
} else if (this.vertexCodes[i] === PConstants.BREAK) {
renderContext.breakShape = true;
}
}
}
}
renderContext.endShape(this.close ? PConstants.CLOSE : PConstants.OPEN);
},
/**
* @member PShape
* The drawGeometry() function draws the geometry part of the SVG document.
*/
drawGeometry: function(renderContext) {
var i, j;
renderContext.beginShape(this.kind);
if (this.style) {
for (i = 0, j = this.vertices.length; i < j; i++) {
renderContext.vertex(this.vertices[i]);
}
} else {
for (i = 0, j = this.vertices.length; i < j; i++) {
var vert = this.vertices[i];
if (vert[2] === 0) {
renderContext.vertex(vert[0], vert[1]);
} else {
renderContext.vertex(vert[0], vert[1], vert[2]);
}
}
}
renderContext.endShape();
},
/**
* @member PShape
* The drawGroup() function draws the <g> part of the SVG document.
*/
drawGroup: function(renderContext) {
for (var i = 0, j = this.children.length; i < j; i++) {
this.children[i].draw(renderContext);
}
},
/**
* @member PShape
* The drawPrimitive() function draws SVG document shape elements. These can be point, line, triangle, quad, rect, ellipse, arc, box, or sphere.
*/
drawPrimitive: function(renderContext) {
if (this.kind === PConstants.POINT) {
renderContext.point(this.params[0], this.params[1]);
} else if (this.kind === PConstants.LINE) {
if (this.params.length === 4) { // 2D
renderContext.line(this.params[0], this.params[1],
this.params[2], this.params[3]);
} else { // 3D
renderContext.line(this.params[0], this.params[1], this.params[2],
this.params[3], this.params[4], this.params[5]);
}
} else if (this.kind === PConstants.TRIANGLE) {
renderContext.triangle(this.params[0], this.params[1],
this.params[2], this.params[3],
this.params[4], this.params[5]);
} else if (this.kind === PConstants.QUAD) {
renderContext.quad(this.params[0], this.params[1],
this.params[2], this.params[3],
this.params[4], this.params[5],
this.params[6], this.params[7]);
} else if (this.kind === PConstants.RECT) {
if (this.image !== null) {
var imMode = imageModeConvert;
renderContext.imageMode(PConstants.CORNER);
renderContext.image(this.image,
this.params[0],
this.params[1],
this.params[2],
this.params[3]);
imageModeConvert = imMode;
} else {
var rcMode = renderContext.curRectMode;
renderContext.rectMode(PConstants.CORNER);
renderContext.rect(this.params[0],
this.params[1],
this.params[2],
this.params[3]);
renderContext.curRectMode = rcMode;
}
} else if (this.kind === PConstants.ELLIPSE) {
var elMode = renderContext.curEllipseMode;
renderContext.ellipseMode(PConstants.CORNER);
renderContext.ellipse(this.params[0],
this.params[1],
this.params[2],
this.params[3]);
renderContext.curEllipseMode = elMode;
} else if (this.kind === PConstants.ARC) {
var eMode = curEllipseMode;
renderContext.ellipseMode(PConstants.CORNER);
renderContext.arc(this.params[0],
this.params[1],
this.params[2],
this.params[3],
this.params[4],
this.params[5]);
curEllipseMode = eMode;
} else if (this.kind === PConstants.BOX) {
if (this.params.length === 1) {
renderContext.box(this.params[0]);
} else {
renderContext.box(this.params[0], this.params[1], this.params[2]);
}
} else if (this.kind === PConstants.SPHERE) {
renderContext.sphere(this.params[0]);
}
},
/**
* @member PShape
* The pre() function performs the preparations before the SVG is drawn. This includes doing transformations and storing previous styles.
*/
pre: function(renderContext) {
if (this.matrix) {
renderContext.pushMatrix();
renderContext.transform(this.matrix);
}
if (this.style) {
renderContext.pushStyle();
this.styles(renderContext);
}
},
/**
* @member PShape
* The post() function performs the necessary actions after the SVG is drawn. This includes removing transformations and removing added styles.
*/
post: function(renderContext) {
if (this.matrix) {
renderContext.popMatrix();
}
if (this.style) {
renderContext.popStyle();
}
},
/**
* @member PShape
* The styles() function changes the Processing's current styles
*/
styles: function(renderContext) {
if (this.stroke) {
renderContext.stroke(this.strokeColor);
renderContext.strokeWeight(this.strokeWeight);
renderContext.strokeCap(this.strokeCap);
renderContext.strokeJoin(this.strokeJoin);
} else {
renderContext.noStroke();
}
if (this.fill) {
renderContext.fill(this.fillColor);
} else {
renderContext.noFill();
}
},
/**
* @member PShape
* The getChild() function extracts a child shape from a parent shape. Specify the name of the shape with the <b>target</b> parameter or the
* layer position of the shape to get with the <b>index</b> parameter.
* The shape is returned as a <b>PShape</b> object, or <b>null</b> is returned if there is an error.
*
* @param {String} target the name of the shape to get
* @param {int} index the layer position of the shape to get
*
* @return {PShape} returns a child element of a shape as a PShape object or null if there is an error
*/
getChild: function(child) {
var i, j;
if (typeof child === 'number') {
return this.children[child];
}
var found;
if(child === "" || this.name === child){
return this;
}
if(this.nameTable.length > 0) {
for(i = 0, j = this.nameTable.length; i < j || found; i++) {
if(this.nameTable[i].getName === child) {
found = this.nameTable[i];
break;
}
}
if (found) { return found; }
}
for(i = 0, j = this.children.length; i < j; i++) {
found = this.children[i].getChild(child);
if(found) { return found; }
}
return null;
},
/**
* @member PShape
* The getChildCount() returns the number of children
*
* @return {int} returns a count of children
*/
getChildCount: function () {
return this.children.length;
},
/**
* @member PShape
* The addChild() adds a child to the PShape.
*
* @param {PShape} child the child to add
*/
addChild: function( child ) {
this.children.push(child);
child.parent = this;
if (child.getName() !== null) {
this.addName(child.getName(), child);
}
},
/**
* @member PShape
* The addName() functions adds a shape to the name lookup table.
*
* @param {String} name the name to be added
* @param {PShape} shape the shape
*/
addName: function(name, shape) {
if (this.parent !== null) {
this.parent.addName( name, shape );
} else {
this.nameTable.push( [name, shape] );
}
},
/**
* @member PShape
* The translate() function specifies an amount to displace the shape. The <b>x</b> parameter specifies left/right translation, the <b>y</b> parameter specifies up/down translation, and the <b>z</b> parameter specifies translations toward/away from the screen.
* Subsequent calls to the method accumulates the effect. For example, calling <b>translate(50, 0)</b> and then <b>translate(20, 0)</b> is the same as <b>translate(70, 0)</b>.
* This transformation is applied directly to the shape, it's not refreshed each time <b>draw()</b> is run.
* <br><br>Using this method with the <b>z</b> parameter requires using the P3D or OPENGL parameter in combination with size.
*
* @param {int|float} x left/right translation
* @param {int|float} y up/down translation
* @param {int|float} z forward/back translation
*
* @see PMatrix2D#translate
* @see PMatrix3D#translate
*/
translate: function() {
if(arguments.length === 2)
{
this.checkMatrix(2);
this.matrix.translate(arguments[0], arguments[1]);
} else {
this.checkMatrix(3);
this.matrix.translate(arguments[0], arguments[1], 0);
}
},
/**
* @member PShape
* The checkMatrix() function makes sure that the shape's matrix is 1) not null, and 2) has a matrix
* that can handle <em>at least</em> the specified number of dimensions.
*
* @param {int} dimensions the specified number of dimensions
*/
checkMatrix: function(dimensions) {
if(this.matrix === null) {
if(dimensions === 2) {
this.matrix = new PMatrix2D();
} else {
this.matrix = new PMatrix3D();
}
}else if(dimensions === 3 && this.matrix instanceof PMatrix2D) {
this.matrix = new PMatrix3D();
}
},
/**
* @member PShape
* The rotateX() function rotates a shape around the x-axis the amount specified by the <b>angle</b> parameter. Angles should be specified in radians (values from 0 to TWO_PI) or converted to radians with the <b>radians()</b> method.
* <br><br>Shapes are always rotated around the upper-left corner of their bounding box. Positive numbers rotate objects in a clockwise direction.
* Subsequent calls to the method accumulates the effect. For example, calling <b>rotateX(HALF_PI)</b> and then <b>rotateX(HALF_PI)</b> is the same as <b>rotateX(PI)</b>.
* This transformation is applied directly to the shape, it's not refreshed each time <b>draw()</b> is run.
* <br><br>This method requires a 3D renderer. You need to pass P3D or OPENGL as a third parameter into the <b>size()</b> method as shown in the example above.
*
* @param {float}angle angle of rotation specified in radians
*
* @see PMatrix3D#rotateX
*/
rotateX: function(angle) {
this.rotate(angle, 1, 0, 0);
},
/**
* @member PShape
* The rotateY() function rotates a shape around the y-axis the amount specified by the <b>angle</b> parameter. Angles should be specified in radians (values from 0 to TWO_PI) or converted to radians with the <b>radians()</b> method.
* <br><br>Shapes are always rotated around the upper-left corner of their bounding box. Positive numbers rotate objects in a clockwise direction.
* Subsequent calls to the method accumulates the effect. For example, calling <b>rotateY(HALF_PI)</b> and then <b>rotateY(HALF_PI)</b> is the same as <b>rotateY(PI)</b>.
* This transformation is applied directly to the shape, it's not refreshed each time <b>draw()</b> is run.
* <br><br>This method requires a 3D renderer. You need to pass P3D or OPENGL as a third parameter into the <b>size()</b> method as shown in the example above.
*
* @param {float}angle angle of rotation specified in radians
*
* @see PMatrix3D#rotateY
*/
rotateY: function(angle) {
this.rotate(angle, 0, 1, 0);
},
/**
* @member PShape
* The rotateZ() function rotates a shape around the z-axis the amount specified by the <b>angle</b> parameter. Angles should be specified in radians (values from 0 to TWO_PI) or converted to radians with the <b>radians()</b> method.
* <br><br>Shapes are always rotated around the upper-left corner of their bounding box. Positive numbers rotate objects in a clockwise direction.
* Subsequent calls to the method accumulates the effect. For example, calling <b>rotateZ(HALF_PI)</b> and then <b>rotateZ(HALF_PI)</b> is the same as <b>rotateZ(PI)</b>.
* This transformation is applied directly to the shape, it's not refreshed each time <b>draw()</b> is run.
* <br><br>This method requires a 3D renderer. You need to pass P3D or OPENGL as a third parameter into the <b>size()</b> method as shown in the example above.
*
* @param {float}angle angle of rotation specified in radians
*
* @see PMatrix3D#rotateZ
*/
rotateZ: function(angle) {
this.rotate(angle, 0, 0, 1);
},
/**
* @member PShape
* The rotate() function rotates a shape the amount specified by the <b>angle</b> parameter. Angles should be specified in radians (values from 0 to TWO_PI) or converted to radians with the <b>radians()</b> method.
* <br><br>Shapes are always rotated around the upper-left corner of their bounding box. Positive numbers rotate objects in a clockwise direction.
* Transformations apply to everything that happens after and subsequent calls to the method accumulates the effect.
* For example, calling <b>rotate(HALF_PI)</b> and then <b>rotate(HALF_PI)</b> is the same as <b>rotate(PI)</b>.
* This transformation is applied directly to the shape, it's not refreshed each time <b>draw()</b> is run.
* If optional parameters x,y,z are supplied, the rotate is about the point (x, y, z).
*
* @param {float}angle angle of rotation specified in radians
* @param {float}x x-coordinate of the point
* @param {float}y y-coordinate of the point
* @param {float}z z-coordinate of the point
* @see PMatrix2D#rotate
* @see PMatrix3D#rotate
*/
rotate: function() {
if(arguments.length === 1){
this.checkMatrix(2);
this.matrix.rotate(arguments[0]);
} else {
this.checkMatrix(3);
this.matrix.rotate(arguments[0],
arguments[1],
arguments[2],
arguments[3]);
}
},
/**
* @member PShape
* The scale() function increases or decreases the size of a shape by expanding and contracting vertices. Shapes always scale from the relative origin of their bounding box.
* Scale values are specified as decimal percentages. For example, the method call <b>scale(2.0)</b> increases the dimension of a shape by 200%.
* Subsequent calls to the method multiply the effect. For example, calling <b>scale(2.0)</b> and then <b>scale(1.5)</b> is the same as <b>scale(3.0)</b>.
* This transformation is applied directly to the shape, it's not refreshed each time <b>draw()</b> is run.
* <br><br>Using this fuction with the <b>z</b> parameter requires passing P3D or OPENGL into the size() parameter.
*
* @param {float}s percentage to scale the object
* @param {float}x percentage to scale the object in the x-axis
* @param {float}y percentage to scale the object in the y-axis
* @param {float}z percentage to scale the object in the z-axis
*
* @see PMatrix2D#scale
* @see PMatrix3D#scale
*/
scale: function() {
if(arguments.length === 2) {
this.checkMatrix(2);
this.matrix.scale(arguments[0], arguments[1]);
} else if (arguments.length === 3) {
this.checkMatrix(2);
this.matrix.scale(arguments[0], arguments[1], arguments[2]);
} else {
this.checkMatrix(2);
this.matrix.scale(arguments[0]);
}
},
/**
* @member PShape
* The resetMatrix() function resets the matrix
*
* @see PMatrix2D#reset
* @see PMatrix3D#reset
*/
resetMatrix: function() {
this.checkMatrix(2);
this.matrix.reset();
},
/**
* @member PShape
* The applyMatrix() function multiplies this matrix by another matrix of type PMatrix3D or PMatrix2D.
* Individual elements can also be provided
*
* @param {PMatrix3D|PMatrix2D} matrix the matrix to multiply by
*
* @see PMatrix2D#apply
* @see PMatrix3D#apply
*/
applyMatrix: function(matrix) {
if (arguments.length === 1) {
this.applyMatrix(matrix.elements[0],
matrix.elements[1], 0,
matrix.elements[2],
matrix.elements[3],
matrix.elements[4], 0,
matrix.elements[5],
0, 0, 1, 0,
0, 0, 0, 1);
} else if (arguments.length === 6) {
this.checkMatrix(2);
this.matrix.apply(arguments[0], arguments[1], arguments[2], 0,
arguments[3], arguments[4], arguments[5], 0,
0, 0, 1, 0,
0, 0, 0, 1);
} else if (arguments.length === 16) {
this.checkMatrix(3);
this.matrix.apply(arguments[0],
arguments[1],
arguments[2],
arguments[3],
arguments[4],
arguments[5],
arguments[6],
arguments[7],
arguments[8],
arguments[9],
arguments[10],
arguments[11],
arguments[12],
arguments[13],
arguments[14],
arguments[15]);
}
}
};
return PShape;
};