Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import or require. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link rel="stylesheet" type="text/css" href="css/main.css">
  </head>
  <body>
    <div class="diamond-l">
      <canvas id="myCanvas" class="precious-canvas-e"></canvas>
      <div class="top-e">	Do not hover me	</div>
      <div class="bottom-e">	Just a trash</div>
    </div>
    <div class="font-holder-e">&nbsp;</div>
    <script type="text/javascript" src="js/lib/jquery-2.0.1.js"></script>
    <script type="text/javascript" src="js/tween.min.js"></script>
    <script type="text/javascript" src="js/paper.js"></script>
    <script type="text/paperscript" src="js/main.js" canvas="myCanvas"></script>
  </body>
</html>
            
          
!
            
              * {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}
body,
html {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  font-family: monospace;
}
.diamond-l {
  display: block;
  margin: 100px auto;
  width: 200px;
  height: 200px;
  height: 240px;
  padding: 20px 0;
  position: relative;
}
.precious-canvas-e {
  cursor: pointer;
  float: left;
}
.precious-canvas-e:hover ~ div {
  display: none;
}

.top-e,
.bottom-e {
  text-align: center;
  text-decoration: none;
  position: absolute;
  width: 100%;
  font-weight: bold;
  font-size: 20px;
}
.top-e {
  top: 0;
}
.bottom-e {
  bottom: 0;
}

            
          
!
            
              paper.install(window)          
paper.setup('myCanvas')

// Generated by CoffeeScript 1.6.2
var $can, Precious, h, onFrame, precious,
  _this = this;

Path.prototype.setWidth = function(width) {
  this.segments[3].point.x = this.segments[0].point.x + width;
  return this.segments[2].point.x = this.segments[1].point.x + width;
};

Path.prototype.setHeight = function(height) {
  this.segments[1].point.y = this.segments[0].point.y + height;
  return this.segments[2].point.y = this.segments[3].point.y + height;
};

Path.prototype.reset = function() {
  this.setWidth(0);
  this.setHeight(0);
  return this.smooth();
};

h = {
  getRand: function(min, max) {
    return Math.floor((Math.random() * ((max + 1) - min)) + min);
  }
};

view.setViewSize(200, 200);

Precious = (function() {
  function Precious() {
    this.updCnt = 0;
    this.twns = [];
    this.sections = [];
    this.chars = [];
    this.colors = ['red', 'green', 'blue', 'purple', 'pink', 'black', 'orange', 'yellow'];
    this.baseShape = [new Point(60, 60), new Point(50, 80), new Point(95, 140), new Point(140, 80), new Point(130, 60), new Point(58, 60)];
    this.diamondShape = [
      {
        x: 130,
        y: 59
      }, {
        x: 140,
        y: 80
      }, {
        x: 95,
        y: 140
      }, {
        x: 50,
        y: 80
      }, {
        x: 60,
        y: 60
      }, {
        x: 127,
        y: 60
      }, {
        x: 115,
        y: 80
      }, {
        x: 95,
        y: 62
      }, {
        x: 75,
        y: 80
      }, {
        x: 60,
        y: 62
      }, {
        x: 52,
        y: 80
      }, {
        x: 140,
        y: 80
      }, {
        x: 115,
        y: 80
      }, {
        x: 95,
        y: 137
      }, {
        x: 75,
        y: 80
      }
    ];
    this.makeAnimations();
  }

  Precious.prototype.makeBase = function() {
    this.base = new Path(this.baseShape);
    this.base.strokeColor = 'black';
    return this.base.strokeWidth = 6;
  };

  Precious.prototype.makeAnimations = function() {
    var center, points, radius1, radius2,
      _this = this;

    this.createSections();
    if (!this.uPath) {
      this.uPath = this.createPath({
        points: [
          {
            x: 15,
            y: 15
          }, {
            x: 105,
            y: 85
          }, {
            x: 190,
            y: 5
          }, {
            x: 15,
            y: 85
          }, {
            x: 145,
            y: 105
          }, {
            x: 95,
            y: 25
          }, {
            x: 65,
            y: 165
          }, {
            x: 135,
            y: 65
          }, {
            x: 5,
            y: 55
          }, {
            x: 155,
            y: 155
          }, {
            x: 170,
            y: 50
          }, {
            x: 10,
            y: 160
          }, {
            x: 70,
            y: 10
          }, {
            x: 180,
            y: 100
          }, {
            x: 10,
            y: 180
          }
        ]
      });
    }
    this.reflection = new Path([
      {
        x: -30,
        y: 50
      }, {
        x: 0,
        y: 50
      }, {
        x: 100,
        y: 190
      }, {
        x: 70,
        y: 190
      }
    ]);
    this.sections.push(this.reflection);
    center = new Point(115, 80);
    points = 5;
    radius1 = 3;
    radius2 = 7;
    this.glare = new Path.Star(center, points, radius1, radius2);
    this.glare.fillColor = 'white';
    this.glare.opacity = 0;
    center = new Point(130, 60);
    points = 5;
    radius1 = 3;
    radius2 = 7;
    this.glare2 = new Path.Star(center, points, radius1, radius2);
    this.glare2.fillColor = 'white';
    this.glare2.opacity = 0;
    this.sections.push(this.glare);
    this.sections.push(this.glare2);
    this.write({
      text: 'CURIOSITY',
      point: {
        x: 25,
        y: 20
      }
    });
    this.write({
      text: 'AWARD!',
      point: {
        x: 50,
        y: 190
      }
    });
    return this.translatePath({
      path: this.uPath,
      dest: this.diamondShape,
      easing: TWEEN.Easing.Bounce.Out,
      duration: 1200
    }).then(function() {
      _this.fadeInSections({
        sections: _this.sections,
        delay: 200
      });
      _this.reflection.fillColor = 'white';
      _this.reflection.opacity = .6;
      setTimeout(function() {
        _this.glare.opacity = 1;
        _this.popCircle({
          path: _this.glare,
          from: {
            r: 0
          },
          to: {
            r: 18
          },
          center: new Point(115, 80),
          duration: 300,
          easing: TWEEN.Easing.Cubic.In
        }).then(function() {
          return _this.popCircle({
            path: _this.glare,
            from: {
              r: 18
            },
            to: {
              r: 0
            },
            center: new Point(115, 80),
            duration: 200,
            easing: TWEEN.Easing.Cubic.Out
          });
        });
        return setTimeout(function() {
          _this.glare2.opacity = 1;
          return _this.popCircle({
            path: _this.glare2,
            from: {
              r: 0
            },
            to: {
              r: 10
            },
            center: new Point(130, 60),
            duration: 300,
            easing: TWEEN.Easing.Cubic.In
          }).then(function() {
            return _this.popCircle({
              path: _this.glare2,
              from: {
                r: 10
              },
              to: {
                r: 0
              },
              center: new Point(130, 60),
              duration: 200,
              easing: TWEEN.Easing.Cubic.Out
            });
          });
        }, 100);
      }, 600);
      return _this.translateObj({
        obj: _this.reflection,
        to: {
          x: 200,
          y: _this.reflection.position.y
        },
        duration: 1000
      });
    });
  };

  Precious.prototype.write = function(o) {
    var char, i, _i, _ref, _ref1, _results;

    if ((_ref = o.fSize) == null) {
      o.fSize = .1;
    }
    _results = [];
    for (i = _i = 0, _ref1 = o.text.length; 0 <= _ref1 ? _i < _ref1 : _i > _ref1; i = 0 <= _ref1 ? ++_i : --_i) {
      char = this.createChar({
        content: o.text[i],
        center: [o.point.x + (i * 18), o.point.y],
        fSize: o.fSize,
        color: "black"
      });
      _results.push(this.chars.push(char));
    }
    return _results;
  };

  Precious.prototype.createChar = function(o) {
    var Char, that;

    that = this;
    Char = (function() {
      function Char(o) {
        this.char = new PointText(new Point(o.center));
        this.char.characterStyle = {
          fontSize: o.fSize,
          fillColor: o.color
        };
        this.char.content = o.content;
        this.i = h.getRand(0, 1);
        this.rotationAmount = h.getRand(4, 8);
        that.popChar({
          char: this.char,
          from: {
            r: 1
          },
          to: {
            r: 8
          }
        });
      }

      Char.prototype.animate = function() {
        if (this.i === 0) {
          this.char.rotate(this.rotationAmount);
          return this.i = 1;
        } else {
          this.i = 0;
          return this.char.rotate(-this.rotationAmount);
        }
      };

      return Char;

    })();
    return new Char(o);
  };

  Precious.prototype.translateObj = function(o) {
    var dfr, mTW, that, _ref,
      _this = this;

    dfr = new $.Deferred;
    if ((_ref = o.from) == null) {
      o.from = o.obj.position;
    }
    mTW = new TWEEN.Tween(new Point(o.from)).to(new Point(o.to), o.duration || 800);
    this.twns.push(mTW);
    mTW.easing(o.easing || TWEEN.Easing.Quartic.In);
    that = this;
    mTW.onUpdate(o.onUpdate || function(a) {
      o.obj.position.x = this.x;
      return o.obj.position.y = this.y;
    });
    mTW.onComplete(function() {
      return dfr.resolve(mTW);
    });
    return dfr.promise();
  };

  Precious.prototype.createSection = function(o) {
    var section, _ref;

    if ((_ref = o.opacity) == null) {
      o.opacity = 0;
    }
    section = this.createPath({
      fill: o.fill,
      closed: true,
      width: 0,
      color: 'transparent',
      opacity: o.opacity,
      points: o.points
    });
    return this.sections.push(section);
  };

  Precious.prototype.createSections = function() {
    this.createSection({
      fill: '#ff4cae',
      points: [
        {
          x: 50,
          y: 80
        }, {
          x: 75,
          y: 80
        }, {
          x: 95,
          y: 140
        }
      ]
    });
    this.createSection({
      fill: '#e053db',
      points: [
        {
          x: 75,
          y: 80
        }, {
          x: 115,
          y: 80
        }, {
          x: 94,
          y: 140
        }
      ]
    });
    this.createSection({
      fill: '#b153db',
      points: [
        {
          x: 115,
          y: 80
        }, {
          x: 140,
          y: 80
        }, {
          x: 95,
          y: 140
        }
      ]
    });
    this.createSection({
      fill: '#ff4cae',
      points: [
        {
          x: 50,
          y: 80
        }, {
          x: 60,
          y: 60
        }, {
          x: 75,
          y: 80
        }
      ]
    });
    this.createSection({
      fill: '#ff4cae',
      points: [
        {
          x: 60,
          y: 60
        }, {
          x: 75,
          y: 80
        }, {
          x: 95,
          y: 60
        }
      ]
    });
    this.createSection({
      fill: '#ed4ef2',
      points: [
        {
          x: 75,
          y: 80
        }, {
          x: 95,
          y: 60
        }, {
          x: 115,
          y: 80
        }
      ]
    });
    this.createSection({
      fill: '#ce4adb',
      points: [
        {
          x: 95,
          y: 60
        }, {
          x: 115,
          y: 80
        }, {
          x: 130,
          y: 60
        }
      ]
    });
    return this.createSection({
      fill: '#b153db',
      points: [
        {
          x: 115,
          y: 80
        }, {
          x: 130,
          y: 60
        }, {
          x: 140,
          y: 80
        }
      ]
    });
  };

  Precious.prototype.translatePath = function(o) {
    var dfr, i, _i, _ref,
      _this = this;

    dfr = new $.Deferred;
    for (i = _i = 0, _ref = o.path.segments.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
      this.translatePoint({
        point: o.path.segments[i].point,
        to: o.dest[i],
        easing: o.easing,
        duration: o.duration
      }).then(function() {
        return dfr.resolve();
      });
    }
    return dfr.promise();
  };

  Precious.prototype.translatePoint = function(o) {
    var dfr, mTW, that,
      _this = this;

    dfr = new $.Deferred;
    mTW = new TWEEN.Tween(new Point(o.point)).to(new Point(o.to), o.duration || 800);
    this.twns.push(mTW);
    mTW.easing(o.easing || TWEEN.Easing.Quartic.In);
    that = this;
    mTW.onUpdate(o.onUpdate || function(a) {
      o.point.x = this.x;
      return o.point.y = this.y;
    });
    mTW.onComplete(function() {
      return dfr.resolve(mTW);
    });
    return dfr.promise();
  };

  Precious.prototype.drawLongLine = function(o) {
    var _ref,
      _this = this;

    if ((_ref = o.cnt) == null) {
      o.cnt = -1;
    }
    o.cnt++;
    if (o.points[o.cnt] && o.points[o.cnt + 1]) {
      o.path.add(o.points[o.cnt]);
      if (o.cnt === 0) {
        o.path.add(o.points[o.cnt]);
      }
      return this.drawLine({
        from: o.points[o.cnt],
        to: o.points[o.cnt + 1],
        pointUpdate: o.path.segments[o.cnt + 1].point,
        duration: o.duration / (o.points.length - 1)
      }).then(function() {
        o.then && o.path[o.then]();
        return _this.drawLongLine(o);
      });
    }
  };

  Precious.prototype.fade = function(o) {
    var dfr, mTW, _ref, _ref1, _ref2, _ref3,
      _this = this;

    if (o.obj == null) {
      return;
    }
    if ((_ref = o.direction) == null) {
      o.direction = 'in';
    }
    if ((_ref1 = o.duration) == null) {
      o.duration = 800;
    }
    switch (o.direction) {
      case 'in':
        if ((_ref2 = o.to) == null) {
          o.to = 1;
        }
        break;
      case 'out':
        if ((_ref3 = o.to) == null) {
          o.to = 0;
        }
    }
    dfr = new $.Deferred;
    mTW = new TWEEN.Tween({
      opacity: o.obj.opacity
    }).to({
      opacity: o.to
    }, o.duration);
    mTW.easing(o.easing || TWEEN.Easing.Quartic.Out);
    mTW.onUpdate(o.onUpdate || function(a) {
      return o.obj.opacity = this.opacity;
    });
    mTW.onComplete(function() {
      return dfr.resolve(mTW);
    });
    this.twns.push(mTW);
    return dfr.promise();
  };

  Precious.prototype.fadeInSections = function(o) {
    var _this = this;

    this.fade({
      obj: this.sections[0]
    });
    this.fade({
      obj: this.sections[3]
    });
    setTimeout(function() {
      _this.fade({
        obj: _this.sections[4]
      });
      return setTimeout(function() {
        _this.fade({
          obj: _this.sections[5]
        });
        return setTimeout(function() {
          _this.fade({
            obj: _this.sections[6]
          });
          return setTimeout(function() {
            return _this.fade({
              obj: _this.sections[7]
            });
          }, o.delay / 2);
        }, o.delay / 2);
      }, o.delay / 2);
    }, o.delay / 2);
    return setTimeout(function() {
      _this.fade({
        obj: _this.sections[1]
      });
      return setTimeout(function() {
        return _this.fade({
          obj: _this.sections[2]
        });
      }, o.delay);
    }, o.delay);
  };

  Precious.prototype.createPath = function(o) {
    var path, _ref, _ref1;

    path = (o != null ? o.points : void 0) ? new Path(o != null ? o.points : void 0) : new Path;
    if (o != null) {
      if ((_ref = o.width) == null) {
        o.width = 6;
      }
    }
    path.strokeWidth = o != null ? o.width : void 0;
    path.strokeColor = (o != null ? o.color : void 0) || '#222';
    if (o.fill) {
      path.fillColor = o.fill;
    }
    o.closed && (path.closed = true);
    if ((_ref1 = o.opacity) == null) {
      o.opacity = 1;
    }
    path.opacity = o.opacity;
    return path;
  };

  Precious.prototype.drawLine = function(o) {
    var dfr, mTW, that,
      _this = this;

    dfr = new $.Deferred;
    mTW = new TWEEN.Tween(new Point(o.from)).to(new Point(o.to), o.duration || 800);
    mTW.chained = o.chained;
    this.twns.push(mTW);
    mTW.easing(o.easing || TWEEN.Easing.Quartic.In);
    that = this;
    mTW.onUpdate(o.onUpdate || function(a) {
      o.pointUpdate.x = this.x;
      return o.pointUpdate.y = this.y;
    });
    mTW.onComplete(function() {
      return dfr.resolve(mTW);
    });
    return dfr.promise();
  };

  Precious.prototype.popCircle = function(o) {
    var dfr, mTW, that,
      _this = this;

    dfr = new $.Deferred;
    mTW = new TWEEN.Tween(o.from).to(o.to, o.duration || 2000);
    mTW.chained = o.chained;
    this.twns.push(mTW);
    mTW.easing(o.easing || TWEEN.Easing.Cubic.Out);
    that = this;
    this.i = 0;
    mTW.onUpdate(o.onUpdate || function(a) {
      o.path.fitBounds(this.r, this.r);
      o.path.position.x = o.center.x;
      return o.path.position.y = o.center.y;
    });
    mTW.onComplete(function() {
      return dfr.resolve(mTW);
    });
    return dfr.promise();
  };

  Precious.prototype.popChar = function(o) {
    var dfr, mTW, that,
      _this = this;

    dfr = new $.Deferred;
    mTW = new TWEEN.Tween(o.from).to(o.to, o.duration || 800);
    mTW.delay(2500);
    this.twns.push(mTW);
    mTW.easing(o.easing || TWEEN.Easing.Elastic.Out);
    that = this;
    this.i = 0;
    mTW.onUpdate(o.onUpdate || function(a) {
      var _ref;

      return (_ref = o.char) != null ? _ref.fontSize = this.r : void 0;
    });
    mTW.onComplete(function() {
      return dfr.resolve(mTW);
    });
    return dfr.promise();
  };

  Precious.prototype.reset = function() {
    var _ref, _ref1, _ref2;

    if ((_ref = this.uPath) != null) {
      _ref.remove();
    }
    if ((_ref1 = this.glare) != null) {
      _ref1.remove();
    }
    if ((_ref2 = this.glare2) != null) {
      _ref2.remove();
    }
    delete this.uPath;
    delete this.glare;
    delete this.glare2;
    TWEEN.removeAll();
    this.clearStack(this.twns);
    this.clearChars();
    this.clearSections();
    return this.makeAnimations();
  };

  Precious.prototype.clearStack = function(stack) {
    var i, _i, _ref, _ref1, _ref2;

    for (i = _i = 0, _ref = stack.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
      if ((_ref1 = stack[i]) != null) {
        if (typeof _ref1.stop === "function") {
          _ref1.stop();
        }
      }
      if ((_ref2 = stack[i]) != null) {
        if (typeof _ref2.remove === "function") {
          _ref2.remove();
        }
      }
      delete stack[i];
    }
    return stack = [];
  };

  Precious.prototype.clearChars = function() {
    var i, _base, _base1, _i, _ref, _ref1, _ref2;

    for (i = _i = 0, _ref = this.chars.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
      if ((_ref1 = this.chars[i]) != null) {
        if (typeof (_base = _ref1.char).stop === "function") {
          _base.stop();
        }
      }
      if ((_ref2 = this.chars[i]) != null) {
        if (typeof (_base1 = _ref2.char).remove === "function") {
          _base1.remove();
        }
      }
      delete this.chars[i].char;
    }
    return this.chars = [];
  };

  Precious.prototype.clearSections = function() {
    var i, _i, _ref, _ref1;

    for (i = _i = 0, _ref = this.sections.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
      if ((_ref1 = this.sections[i]) != null) {
        _ref1.remove();
      }
      delete this.sections[i];
    }
    return this.sections = [];
  };

  Precious.prototype.startTweens = function() {
    var i, _i, _ref, _ref1, _ref2, _ref3, _ref4, _results;

    _results = [];
    for (i = _i = 0, _ref = this.twns.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
      if (!((_ref1 = this.twns[i]) != null ? _ref1.started : void 0) && !((_ref2 = this.twns[i]) != null ? _ref2.chained : void 0)) {
        if ((_ref3 = this.twns[i]) != null) {
          _ref3.start();
        }
        _results.push((_ref4 = this.twns[i]) != null ? _ref4.started = true : void 0);
      } else {
        _results.push(void 0);
      }
    }
    return _results;
  };

  Precious.prototype.animateChars = function() {
    var i, _i, _ref, _ref1, _results;

    _results = [];
    for (i = _i = 0, _ref = this.chars.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
      _results.push((_ref1 = this.chars[i]) != null ? _ref1.animate() : void 0);
    }
    return _results;
  };

  Precious.prototype.update = function(e) {
    if (!this.allowAnimation) {
      return;
    }
    this.startTweens();
    return TWEEN.update();
  };

  return Precious;

})();

precious = new Precious;

view.onFrame = function(e) {
  return precious.update();
};

$can = $('#myCanvas');

$can.on('mouseover', function() {
  return precious.allowAnimation = true;
});

$can.on('mouseleave', function() {
  precious.reset();
  return precious.allowAnimation = false;
});

            
          
!
999px

Console