Skip to content

Commit a12b58c

Browse files
committed
Convert Particle and subclasses to use JS class syntax.
1 parent 1ea2c46 commit a12b58c

17 files changed

+275
-258
lines changed

MotionMark/tests/bouncing-particles/resources/bouncing-canvas-images.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@
2323
* THE POSSIBILITY OF SUCH DAMAGE.
2424
*/
2525

26-
BouncingCanvasImage = Utilities.createSubclass(BouncingCanvasParticle,
27-
function(stage)
26+
class BouncingCanvasImage extends BouncingCanvasParticle {
27+
constructor(stage)
2828
{
29-
BouncingCanvasParticle.call(this, stage, "image");
29+
super(stage, "image");
3030
this._imageElement = stage.imageElement;
31-
}, {
31+
}
3232

33-
_draw: function()
33+
_draw()
3434
{
3535
this.context.save();
3636
this.applyRotation();
3737
this.context.drawImage(this._imageElement, 0, 0, this.size.x, this.size.y);
3838
this.context.restore();
3939
}
40-
});
40+
}
4141

4242
class BouncingCanvasImagesStage extends BouncingCanvasParticlesStage {
4343
constructor()

MotionMark/tests/bouncing-particles/resources/bouncing-canvas-particles.js

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,43 @@
2222
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
2323
* THE POSSIBILITY OF SUCH DAMAGE.
2424
*/
25-
BouncingCanvasParticle = Utilities.createSubclass(BouncingParticle,
26-
function(stage, shape)
25+
26+
class BouncingCanvasParticle extends BouncingParticle {
27+
static clips;
28+
constructor(stage, shape)
2729
{
28-
BouncingParticle.call(this, stage);
30+
BouncingCanvasParticle.clips = {
31+
star: [
32+
new Point(0.50, 0.00),
33+
new Point(0.38, 0.38),
34+
new Point(0.00, 0.38),
35+
new Point(0.30, 0.60),
36+
new Point(0.18, 1.00),
37+
new Point(0.50, 0.75),
38+
new Point(0.82, 1.00),
39+
new Point(0.70, 0.60),
40+
new Point(1.00, 0.38),
41+
new Point(0.62, 0.38)
42+
]
43+
};
44+
45+
super(stage);
2946
this.context = stage.context;
3047
this._shape = shape;
3148
this._clip = stage.clip;
32-
}, {
49+
}
3350

34-
applyRotation: function()
51+
applyRotation()
3552
{
3653
if (this._shape == "circle")
3754
return;
3855

3956
this.context.translate(this.size.x / 2, this.size.y / 2);
4057
this.context.rotate(this.rotater.degree() * Math.PI / 180);
4158
this.context.translate(-this.size.x / 2, -this.size.y / 2);
42-
},
59+
}
4360

44-
applyClipping: function()
61+
applyClipping()
4562
{
4663
var clipPoints = BouncingCanvasParticle.clips[this._clip];
4764
if (!clipPoints)
@@ -58,37 +75,22 @@ BouncingCanvasParticle = Utilities.createSubclass(BouncingParticle,
5875

5976
this.context.closePath();
6077
this.context.clip();
61-
},
78+
}
6279

63-
_draw: function()
80+
_draw()
6481
{
6582
throw "Not implemented";
66-
},
83+
}
6784

68-
animate: function(timeDelta)
85+
animate(timeDelta)
6986
{
70-
BouncingParticle.prototype.animate.call(this, timeDelta);
87+
super.animate(timeDelta);
7188
this.context.save();
7289
this.context.translate(this.position.x, this.position.y);
7390
this._draw();
7491
this.context.restore();
7592
}
76-
});
77-
78-
BouncingCanvasParticle.clips = {
79-
star: [
80-
new Point(0.50, 0.00),
81-
new Point(0.38, 0.38),
82-
new Point(0.00, 0.38),
83-
new Point(0.30, 0.60),
84-
new Point(0.18, 1.00),
85-
new Point(0.50, 0.75),
86-
new Point(0.82, 1.00),
87-
new Point(0.70, 0.60),
88-
new Point(1.00, 0.38),
89-
new Point(0.62, 0.38)
90-
]
91-
};
93+
}
9294

9395
class BouncingCanvasParticlesStage extends BouncingParticlesStage {
9496
constructor()

MotionMark/tests/bouncing-particles/resources/bouncing-canvas-shapes.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@
2323
* THE POSSIBILITY OF SUCH DAMAGE.
2424
*/
2525

26-
BouncingCanvasShape = Utilities.createSubclass(BouncingCanvasParticle,
27-
function(stage)
26+
class BouncingCanvasShape extends BouncingCanvasParticle {
27+
constructor(stage)
2828
{
29-
BouncingCanvasParticle.call(this, stage, stage.shape);
29+
super(stage, stage.shape);
3030
this._fill = stage.fill;
3131
this._color0 = Stage.randomColor();
3232
this._color1 = Stage.randomColor();
33-
}, {
33+
}
3434

35-
_applyFill: function()
35+
_applyFill()
3636
{
3737
switch (this._fill) {
3838
case "gradient":
@@ -47,9 +47,9 @@ BouncingCanvasShape = Utilities.createSubclass(BouncingCanvasParticle,
4747
this.context.fillStyle = this._color0;
4848
break;
4949
}
50-
},
50+
}
5151

52-
_drawShape: function()
52+
_drawShape()
5353
{
5454
this.context.beginPath();
5555

@@ -67,9 +67,9 @@ BouncingCanvasShape = Utilities.createSubclass(BouncingCanvasParticle,
6767
}
6868

6969
this.context.fill();
70-
},
70+
}
7171

72-
_draw: function()
72+
_draw()
7373
{
7474
this.context.save();
7575
this._applyFill();
@@ -78,7 +78,7 @@ BouncingCanvasShape = Utilities.createSubclass(BouncingCanvasParticle,
7878
this._drawShape();
7979
this.context.restore();
8080
}
81-
});
81+
}
8282

8383
class BouncingCanvasShapesStage extends BouncingCanvasParticlesStage {
8484
constructor ()

MotionMark/tests/bouncing-particles/resources/bouncing-css-images.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
* THE POSSIBILITY OF SUCH DAMAGE.
2424
*/
2525

26-
BouncingCssImage = Utilities.createSubclass(BouncingParticle,
27-
function(stage)
26+
class BouncingCssImage extends BouncingParticle {
27+
constructor(stage)
2828
{
29-
BouncingParticle.call(this, stage);
29+
super(stage);
3030

3131
this.element = document.createElement("img");
3232
this.element.style.width = this.size.x + "px";
@@ -35,19 +35,19 @@ BouncingCssImage = Utilities.createSubclass(BouncingParticle,
3535

3636
stage.element.appendChild(this.element);
3737
this._move();
38-
}, {
38+
}
3939

40-
_move: function()
40+
_move()
4141
{
4242
this.element.style.transform = "translate(" + this.position.x + "px," + this.position.y + "px) " + this.rotater.rotateZ();
43-
},
43+
}
4444

45-
animate: function(timeDelta)
45+
animate(timeDelta)
4646
{
47-
BouncingParticle.prototype.animate.call(this, timeDelta);
47+
super.animate(timeDelta);
4848
this._move();
4949
}
50-
});
50+
}
5151

5252
class BouncingCssImagesStage extends BouncingParticlesStage {
5353
constructor()

MotionMark/tests/bouncing-particles/resources/bouncing-css-shapes.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
* THE POSSIBILITY OF SUCH DAMAGE.
2424
*/
2525

26-
BouncingCssShape = Utilities.createSubclass(BouncingParticle,
27-
function(stage)
26+
class BouncingCssShape extends BouncingParticle {
27+
constructor(stage)
2828
{
29-
BouncingParticle.call(this, stage);
29+
super(stage);
3030

3131
this.element = this._createSpan(stage);
3232

@@ -49,30 +49,30 @@ BouncingCssShape = Utilities.createSubclass(BouncingParticle,
4949
Utilities.setElementPrefixedProperty(this.element, "filter", Stage.randomStyleFilter());
5050

5151
this._move();
52-
}, {
52+
}
5353

54-
_createSpan: function(stage)
54+
_createSpan(stage)
5555
{
5656
var span = document.createElement("span");
5757
span.className = stage.shape + " " + stage.clip;
5858
span.style.width = this.size.x + "px";
5959
span.style.height = this.size.y + "px";
6060
stage.element.appendChild(span);
6161
return span;
62-
},
62+
}
6363

64-
_move: function()
64+
_move()
6565
{
6666
this.element.style.transform = "translate(" + this.position.x + "px," + this.position.y + "px)" + this.rotater.rotateZ();
67-
},
67+
}
6868

69-
animate: function(timeDelta)
69+
animate(timeDelta)
7070
{
71-
BouncingParticle.prototype.animate.call(this, timeDelta);
71+
super.animate(timeDelta);
7272
this.rotater.next(timeDelta);
7373
this._move();
7474
}
75-
});
75+
}
7676

7777
class BouncingCssShapesStage extends BouncingParticlesStage {
7878
constructor()

MotionMark/tests/bouncing-particles/resources/bouncing-particles.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,24 @@
2323
* THE POSSIBILITY OF SUCH DAMAGE.
2424
*/
2525

26-
function BouncingParticle(stage)
27-
{
28-
this._stageSize = stage.size;
29-
this.size = stage.particleSize;
30-
31-
this.position = Stage.randomPosition(stage.size.subtract(stage.particleSize));
32-
this._angle = Stage.randomAngle();
33-
this._velocity = Stage.randomVelocity(stage.maxVelocity);
34-
this.rotater = Stage.randomRotater();
35-
}
26+
class BouncingParticle {
27+
constructor(stage)
28+
{
29+
this._stageSize = stage.size;
30+
this.size = stage.particleSize;
31+
32+
this.position = Stage.randomPosition(stage.size.subtract(stage.particleSize));
33+
this._angle = Stage.randomAngle();
34+
this._velocity = Stage.randomVelocity(stage.maxVelocity);
35+
this.rotater = Stage.randomRotater();
36+
}
3637

37-
BouncingParticle.prototype =
38-
{
3938
get center()
4039
{
4140
return this.position.add(this.size.center);
42-
},
41+
}
4342

44-
animate: function(timeDelta)
43+
animate(timeDelta)
4544
{
4645
this.position = this.position.move(this._angle, this._velocity, timeDelta);
4746
this.rotater.next(timeDelta);

MotionMark/tests/bouncing-particles/resources/bouncing-svg-images.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@
2323
* THE POSSIBILITY OF SUCH DAMAGE.
2424
*/
2525

26-
BouncingSvgImage = Utilities.createSubclass(BouncingSvgParticle,
27-
function(stage)
26+
class BouncingSvgImage extends BouncingSvgParticle {
27+
constructor(stage)
2828
{
29-
BouncingSvgParticle.call(this, stage, "image");
29+
super(stage, "image");
3030

3131
var attrs = { x: 0, y: 0, width: this.size.x, height: this.size.y };
3232
var xlinkAttrs = { href: stage.imageSrc };
3333
this.element = Utilities.createSVGElement("image", attrs, xlinkAttrs, stage.element);
3434
this._move();
3535
}
36-
);
36+
)
3737

3838
class BouncingSvgImagesStage extends BouncingSvgParticlesStage {
3939
constructor()

MotionMark/tests/bouncing-particles/resources/bouncing-svg-particles.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,36 +22,37 @@
2222
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
2323
* THE POSSIBILITY OF SUCH DAMAGE.
2424
*/
25-
BouncingSvgParticle = Utilities.createSubclass(BouncingParticle,
26-
function(stage, shape)
25+
26+
class BouncingSvgParticle extends BouncingParticle {
27+
constructor(stage, shape)
2728
{
28-
BouncingParticle.call(this, stage);
29+
super(stage);
2930
this._shape = shape;
30-
}, {
31+
}
3132

32-
_applyClipping: function(stage)
33+
_applyClipping(stage)
3334
{
3435
if (stage.clip != "star")
3536
return;
3637

3738
stage.ensureClipStarIsCreated();
3839
this.element.setAttribute("clip-path", "url(#star-clip)");
39-
},
40+
}
4041

41-
_move: function()
42+
_move()
4243
{
4344
var transform = "translate(" + this.position.x + ", " + this.position.y + ")";
4445
if (this._shape != "circle")
4546
transform += this.rotater.rotate(this.size.center);
4647
this.element.setAttribute("transform", transform);
47-
},
48+
}
4849

49-
animate: function(timeDelta)
50+
animate(timeDelta)
5051
{
51-
BouncingParticle.prototype.animate.call(this, timeDelta);
52+
super.animate(timeDelta);
5253
this._move();
5354
}
54-
});
55+
}
5556

5657
class BouncingSvgParticlesStage extends BouncingParticlesStage {
5758
constructor()

0 commit comments

Comments
 (0)