如何使用paper.js绘制圆形段

时间:2012-02-25 17:41:23

标签: javascript html5-canvas paperjs

如何使用paper.js

绘制圆形线段

我想绘制圆形线段,如图所示。每个细分都是独立的,稍后将用于交互目的。

enter image description here

我试过像

这样的东西
//Temporary background circle
var keys = new Path.Circle(view.center, 130);
keys.fillColor = '#F1F1F1';

var home = new Path.Circle(view.center, 50);
home.fillColor = '#ee2a33';

var start = new Point(view.center.x, view.center.y-130);
var through = new Point(view.center.x-125, view.center.y-40);
var to = new Point(view.center.x-130, view.center.y);

var path = new Path.Arc(start, through, to);
path.strokeColor = 'black';
path.fillColor = 'green';

它呈现类似下面的内容

enter image description here

1 个答案:

答案 0 :(得分:6)

经过多次尝试,我想出了这个。如果有人出于某种原因需要相同的东西,也许这会有所帮助。

//Creating keys
var arcOne = createSegment('#f1f1f1');
var arcTwo = createSegment('#666666');
var arcThree = createSegment('#333333');
var arcFour = createSegment('#666666');
var arcFive = createSegment('#999999');
var arcSix = createSegment('#000000');

arcTwo.rotate(-60, view.center);
arcThree.rotate(-120, view.center);
arcFour.rotate(60, view.center);
arcFive.rotate(120, view.center);
arcSix.rotate(180, view.center);


//center white
var center = new Path.Circle(view.center, 50);
center.fillColor = '#F1F1F1';

//Create Each segment
function createSegment(fillcolor){
    //Segment One
    var start = new Point(view.center.x, view.center.y-130);
    var through = new Point(view.center.x-90, view.center.y-94);
    var to = new Point(view.center.x-113, view.center.y-64);
    var name = Path.Arc(start, through, to);

    name.add(new Point(view.center.x, view.center.y));
    name.add(new Point(view.center.x, view.center.y-130));
    name.fillColor = fillcolor;
    return name;
}