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
|
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Incremental Rendering</title>
<script src="../dist/zrender.js"></script>
</head>
<body style="margin:0px;">
<canvas id="main" width="1000px" height="600px" style="width:1000px;height:600px;"></canvas>
<script type="text/javascript">
var zr = zrender.init(document.getElementById('main'));
zr.add(new zrender.Rect({
shape: {
x: 0,
y: 0,
width: zr.getWidth(),
height: zr.getHeight()
},
style: {
fill: 'red'
}
}));
var incrementalDisplayable = new zrender.IncrementalDisplayable();
zr.add(incrementalDisplayable);
var countText = new zrender.Text({
style: {
text: 0,
x: 10,
y: 10,
textFont: '40px sans-serif',
textFill: '#fff',
textStroke: '#000',
textStrokeWidth: 2
}
});
zr.add(countText);
zr.animation.on('frame', function () {
for (var i = 0; i < 2000; i++) {
var circleShape = new zrender.Circle({
shape: {
r: 1 + Math.random() * 1
},
style: {
fill: '#121',
blend: 'lighter'
},
position: [Math.random() * zr.getWidth(), Math.random() * zr.getHeight()]
});
incrementalDisplayable.addDisplayable(circleShape, true);
}
countText.style.text += 2000;
countText.dirty();
});
setInterval(function () {
incrementalDisplayable.clearDisplaybles();
}, 5000);
</script>
</body>
</html>
|