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
|
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script src="https://cdn.jsdelivr.net/npm/dat.gui@0.7.6/build/dat.gui.js"></script>
<script src="../dist/zrender.js"></script>
<script src="lib/config.js"></script>
</head>
<body>
<style>
html, body, #main {
width: 100%;
height: 100%;
margin: 0;
}
</style>
<div id="main"></div>
<script type="text/javascript">
const zr = zrender.init(document.getElementById('main'), {
renderer: window.__ZRENDER__DEFAULT__RENDERER__
});
var points = [];
for (var i = 0; i < 10; i++) {
points.push([Math.random() * 300 + 100, Math.random() * 300 + 100]);
}
var polygon = new zrender.Polygon({
x: 100,
y: 100,
style: {
fill: 'rgba(220, 20, 60, 0.4)'
},
shape: {
points: [[50, 50], [200, 10], [100, 200], [50, 150], [10, 70]],
smooth: 0.5
}
});
var polygonOutline = new zrender.Polyline({
x: 100,
y: 100,
style: {
stroke: 'rgba(220, 20, 60, 1)',
lineWidth: 10
},
shape: polygon.shape
});
zr.add(polygon);
zr.add(polygonOutline);
function update() {
polygon.setShape({
smooth: config.smooth
});
polygonOutline.setShape({
smooth: config.smooth
});
polygonOutline.setStyle({
strokePercent: config.percent
});
}
const config = {
smooth: 0.5,
percent: 0,
animatePercent: true
};
const gui = new dat.GUI();
gui.add(config, 'smooth', 0, 1).onChange(update);
gui.add(config, 'percent', 0, 1).onChange(update);
gui.add(config, 'animatePercent');
setInterval(function () {
if (config.animatePercent) {
config.percent = (config.percent + 0.01) % 1;
gui.updateDisplay();
update();
}
}, 20);
update();
</script>
</body>
</html>
|