Requires

Provides

Flower.js

Ever wanted a flower button? Here you go

License:
Public domain (http://unlicense.org).
Authors:
Yaroslaff Fedin
  1. 21
  2. 22
  3. 23
  4. 24
  5. 25
  6. 26
  7. 27
  8. 28
  9. 29
  10. 30
  11. 31
  12. 32
  13. 33
  14. 34
  15. 35
  16. 36
  17. 37
  18. 38
  19. 39
  20. 40
  21. 41
  22. 42
  23. 43
  24. 44
  25. 45
  26. 46
  27. 47
  28. 48
  29. 49
  30. 50
  31. 51
  32. 52
  33. 53
  34. 54
  35. 55
  36. 56
  37. 57
  38. 58
  39. 59
ART.Shape.Flower = new Class({ Extends: ART.Shape, properties: ['width', 'height', 'leaves', 'radius'], draw: function(width, height, leaves, radius){ var path = new ART.Path, outside = width / 2, cx = width / 2, cy = cx, inside = outside * (radius || 0.5); leaves = Math.max(leaves || 0, 5); path.move(0, inside); var points = ["M", cx, cy + rin, "Q"], R; for (var i = 1; i < leaves * 2 + 1; i++) { R = i % 2 ? rout : rin; points = points.concat([+(cx + R * Math.sin(i * Math.PI / n)).toFixed(3), +(cy + R * Math.cos(i * Math.PI / n)).toFixed(3)]); } points.push("z"); return this.path(points); return this.parent(path.close()); }, getOffset: function(styles, offset) { var stroke = (styles.strokeWidth || 0); return { left: ((styles.width == 'auto') ? Math.max(stroke - offset.left, 0) : stroke), top: 0, right: ((styles.width == 'auto') ? Math.max(stroke - offset.right, 0) : stroke), bottom: stroke } } });

Raphael.fn.flower = function (cx, cy, rout, rin, n) {

rin = rin || rout * .5;
      n = +n < 3 || !n ? 5 : n;
      var points = ["M", cx, cy + rin, "Q"],
          R;
      for (var i = 1; i < n * 2 + 1; i++) {
          R = i % 2 ? rout : rin;
          points = points.concat([+(cx + R * Math.sin(i * Math.PI / n)).toFixed(3), +(cy + R * Math.cos(i * Math.PI / n)).toFixed(3)]);
      }
      points.push("z");
      return this.path(points);
      

};