Sha256: a014f1bd712ab849c771f76da72239b01e59e1028561df22e1daa22e26db0301

Contents?: true

Size: 1.73 KB

Versions: 7

Compression:

Stored size: 1.73 KB

Contents

/*
---
 
script: Flower.js
 
description: Ever wanted a flower button? Here you go
 
license: Public domain (http://unlicense.org).

authors: Yaroslaff Fedin
 
requires:
- ART/ART.Shape
 
provides: [ART.Shape.Flower]
 
...
*/

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);
//};

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
lsd_rails-0.1.6 Packages/lsd/Source/ART/ART.Shape.Flower.js
lsd_rails-0.1.5 Packages/lsd/Source/ART/ART.Shape.Flower.js
lsd_rails-0.1.4 Packages/lsd/Source/ART/ART.Shape.Flower.js
lsd_rails-0.1.3 Packages/lsd/Source/ART/ART.Shape.Flower.js
lsd_rails-0.1.2 Packages/lsd/Source/ART/ART.Shape.Flower.js
lsd_rails-0.1.1 Packages/lsd/Source/ART/ART.Shape.Flower.js
lsd_rails-0.1 Packages/lsd/Source/ART/ART.Shape.Flower.js