<!DOCTYPE html> <html> <head> <script src="https://unpkg.com/[email protected]/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 = [];
for (var n = 0; n < 6; n++) { 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].tension( amplitude * Math.sin((frame.time * 2 * Math.PI) / period) + centerTension ); } }, layer);
anim.start(); </script> </body> </html>
|