Advertisement
Fhernd

index.js

Sep 21st, 2017
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var stage = new Konva.Stage({
  2.     container: 'dibujo',
  3.     width: 556,
  4.     height: 316
  5. });
  6.  
  7. function crearAnimacion(star){
  8.     var anim = new Konva.Animation(function(frame) {
  9.         var scale = Math.sin(frame.time * 2.5 * Math.PI / 2000) + 0.001;
  10.         star.scale({ x :scale, y : scale});
  11.         var angleDiff = frame.timeDiff * 90/ 1000;
  12.         star.rotate(angleDiff);
  13.     }, layer);
  14.     anim.start();
  15. }
  16.  
  17. function crearEstrella(){
  18.     var sX, sY;
  19.     sX = sY = Math.random();
  20.  
  21.     return new Konva.Star({
  22.         x: Math.floor(Math.random() * 556),
  23.         y: Math.floor(Math.random() * 316),
  24.         numPoints: 5,
  25.         innerRadius: 40,
  26.         outerRadius: 80,
  27.         rotation: Math.floor(Math.random() * 360),
  28.         scaleX: sX,
  29.         scaleY: sY,
  30.         fill: 'yellow',
  31.         stroke: 'black',
  32.         strokeWidth: 1,
  33.         opacity: 0.8,
  34.         draggable: true
  35.     });
  36. }
  37.  
  38. var layer = new Konva.Layer();
  39.  
  40. for(var i = 1; i <= 5; ++i){
  41.  
  42.     var star = crearEstrella();
  43.  
  44.     layer.add(star);
  45.  
  46.     crearAnimacion(star);
  47. }
  48.  
  49. stage.add(layer);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement