fabric.js/test/raphael_vs_fabric/simple_shapes.html

96 lines
2.6 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Simple shapes</title>
<style>
svg {
border: 1px solid #000;
}
.canvas_container {
border: 1px solid #000;
position: relative;
}
</style>
<script src="raphael-min.js"></script>
<script src="../../dist/all.js"></script>
<script>
function getRandomNum(min, max) {
return Math.random() * (max - min) + min;
}
var numObjects = 200,
radius = 20,
width = 500,
height = 500;
window.onload = function() {
var logEl = document.getElementById('log');
(function testRaphael() {
var paper = Raphael(550, 50, width, height),
startTime = new Date(),
circle;
var start = function () {
// storing original coordinates
this.ox = this.attr("cx");
this.oy = this.attr("cy");
this.attr({opacity: .5});
},
move = function (dx, dy) {
// move will be called with dx and dy
this.attr({cx: this.ox + dx, cy: this.oy + dy});
},
up = function () {
// restoring state
this.attr({opacity: 1});
};
for (var i = numObjects; i--; ) {
circle = paper.circle(getRandomNum(0, width), getRandomNum(0, height), radius);
circle.attr('fill', 'red');
circle.attr('stroke', 'blue');
circle.drag(move, start, up);
}
logEl.innerHTML = 'Raphael: ' + (new Date() - startTime) + 'ms<br>';
})();
(function testFabric() {
var canvas = window.__canvas = new fabric.Element('canvas', {
renderOnAddition: false,
stateful: false
}),
Circle = fabric.Circle,
startTime = new Date(),
circle;
for (var i = numObjects; i--; ) {
canvas.add(new Circle({
radius: radius,
left: getRandomNum(0, width),
top: getRandomNum(0, height),
fill: 'red',
stroke: 'blue'
}));
}
canvas.renderAll();
canvas.calcOffset();
logEl.innerHTML += 'fabric: ' + (new Date() - startTime) + 'ms';
})();
};
</script>
</head>
<body>
<p>Rendering a large number of simple shapes</p>
<canvas id="canvas" width="500" height="500"></canvas>
<p id="log"></p>
</body>
</html>