DIR : /home/kozerus/public_html/go/konva2.html
/home/kozerus/public_html/go
Konva Drag and Drop Stress Test with 10,000 Shapes Demo
view raw
<!DOCTYPE html>
<html>
<head>
<!-- <script src="https://unpkg.com/konva@8.3.0/konva.min.js"></script> -->
<script id=script_konva_js src="/go/js/konva_min.js" ></script>
<meta charset="utf-8" />
<title>Konva Drag and Drop Stress Test with 10,000 Shapes Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body bgcolor=linen>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;
function addCircle(layer) {
var color = colors[colorIndex++];
if (colorIndex >= colors.length) {
colorIndex = 0;
}
var randX = Math.random() * stage.width();
var randY = Math.random() * stage.height();
var circle = new Konva.Circle({
x: randX,
y: randY,
radius: 6,
fill: color,
});
layer.add(circle);
}
var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});
var dragLayer = new Konva.Layer();
var colors = [
'red',
'orange',
'yellow',
'green',
'blue',
'cyan',
'purple',
];
var colorIndex = 0;
var layersArr = [];
/*
* create 10 layers each containing 1000 shapes to create
* 10,000 shapes. This greatly improves performance because
* only 1,000 shapes will have to be drawn at a time when a
* circle is removed from a layer rather than all 10,000 shapes.
* Keep in mind that having too many layers can also slow down performance.
* I found that using 10 layers each made up of 1,000 shapes performs better
* than 20 layers with 500 shapes or 5 layers with 2,000 shapes
*/
for (var i = 0; i < 10; i++) {
var layer = new Konva.Layer();
layersArr.push(layer);
for (var n = 0; n < 1000; n++) {
addCircle(layer);
}
stage.add(layer);
}
stage.add(dragLayer);
stage.on('mousedown', function (evt) {
var circle = evt.target;
var layer = circle.getLayer();
circle.moveTo(dragLayer);
circle.startDrag();
});
</script>
</body>
</html>
//
koh5_pano
Drag mouse to navigate.
Navigation
- Left/Right Mouse drag: Changes camera heading.
- Up/Sown Mouse drag: Changes camera pitch.
- Scroll wheel: Changes camera field of view.
- I-Key: Displays Info panel with canvas size, image size and FPS.
17.Aug.2010, Martin Wengenmayer