1

我正在尝试在所有圈子之间制作可点击的字段。任何想法?

我的代码:http: //jsfiddle.net/LKHSw/

    var bok = 700,
    width = bok,
    height = width,
    radius = bok / 5,
    stage = new Kinetic.Stage({
        container: 'container',
        width: width,
        height: height
    });
var layer = new Kinetic.Layer();

var a = new Kinetic.Circle({
    x: bok / 3,
    y: bok / 3,
    radius: radius,
    fill: 'red'
});
var b = new Kinetic.Circle({
    x: a.getX() + radius,
    y: a.getY(),
    radius: radius,
    fill: 'blue'
});
var c = new Kinetic.Circle({
    x: (b.getX() + a.getX()) / 2,
    y: a.getY() + radius,
    radius: radius,
    fill: 'green'
});


var clipper = function (ctx, clipped, clip, self) {
    ctx.beginPath();
    ctx.arc(clip.getX(), clip.getY(), clip.getRadius(), 0, 2 * Math.PI, false);
    ctx.clip();

    ctx.beginPath();
    ctx.arc(clipped.getX(), clipped.getY(), clipped.getRadius(), 0, 2 * Math.PI, false);

    ctx.fillStrokeShape(self);
};

var ab = new Kinetic.Shape({
    drawFunc: function (context) {
        clipper(context, a, b, this);
    },
    fill: 'yellow'
});
var bc = new Kinetic.Shape({
    drawFunc: function (context) {
        clipper(context, b, c, this);
    },
    fill: 'pink'
});
var ca = new Kinetic.Shape({
    drawFunc: function (context) {
        clipper(context, c, a, this);
    },
    fill: 'orange'
});

layer.add(a);
layer.add(b);
layer.add(c);
layer.add(ab);
layer.add(bc);
layer.add(ca);

var hover = function (shape) {
    var defaultColor;
    shape.on('mouseover', function () {
        defaultColor = shape.getFill();
        shape.setFill('black');
        layer.draw();
    }).on('mouseout', function () {
        shape.setFill(defaultColor);
        layer.draw();
    });
};

hover(a);
hover(b);
hover(c);
hover(ab);
hover(bc);
hover(ca);

stage.add(layer);
4

1 回答 1

1

这是使用您的裁剪器功能的粗略实现:(更新的小提琴

var clipper2 = function (ctx, clipped, clip1, clip2, self) {
    ctx.beginPath();
    ctx.arc(clip1.getX(), clip1.getY(), clip1.getRadius(), 0, 2 * Math.PI, false);
    ctx.clip();
    ctx.beginPath();
    ctx.arc(clip2.getX(), clip2.getY(), clip2.getRadius(), 0, 2 * Math.PI, false);
    ctx.clip();

    ctx.beginPath();
    ctx.arc(clipped.getX(), clipped.getY(), clipped.getRadius(), 0, 2 * Math.PI, false);

    ctx.fillStrokeShape(self);
};

并声明你的形状如下 -

var abc = new Kinetic.Shape({
    drawFunc: function (context) {
        clipper2(context, c, a, b, this);
    },
    fill: 'white'
});
于 2013-09-27T16:01:51.283 回答