Oscillating Blobs

Instructions: Refresh the page to generate new blobs. You can also drag and drop the blobs as they animate.

Konva Quantum Squiggle Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.rawgit.com/konvajs/konva/1.6.2/konva.min.js"></script>
<meta charset="utf-8">
<title>Konva Quantum Squiggle Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #F0F0F0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;
var stage = new Konva.Stage({
container: 'container',
width: width,
height: height
});
var layer = new Konva.Layer();
var colors = ['red', 'orange', 'yellow', 'green', 'blue', 'purple'];
var blobs = [];
// create 6 blobs
for(var n = 0; n < 6; n++) {
// build array of random points
var points = [];
for(var i = 0; i < 5; i++) {
points.push(stage.width() * Math.random());
points.push(height * Math.random());
}
var blob = new Konva.Line({
points: points,
fill: colors[n],
stroke: 'black',
strokeWidth: 2,
tension: 0,
opacity: Math.random(),
draggable: true,
closed : true
});
layer.add(blob);
blobs.push(blob);
}
stage.add(layer);
var period = 2000;
var centerTension = 0;
var amplitude = 1;
var anim = new Konva.Animation(function(frame) {
for(var n = 0; n < blobs.length; n++) {
blobs[n].setTension(amplitude * Math.sin(frame.time * 2 * Math.PI / period) + centerTension);
}
}, layer);
anim.start();
</script>
</body>
</html>