I want to check if an animated circle element collides (overlaps) with an animated Path Element in a set of Path Elements.
To make the example easier to understand I animated circles and want you to show me, how you can make the green circle appear red, as soon one of the black circles collides with it:
The Code from the Fiddle:
JS
var paper = Raphael("canvas", 800, 800);
var cx = 400;
var cy = 400;
// Helpers
function rand(min, max) {
return Math.random() * (max - min) + min;
}
var bigCircle = paper.circle(cx, cy, 500);
function flyMeteor(){
var ptOnCircle = bigCircle.getPointAtLength(rand(1,bigCircle.getTotalLength()));
var anim = Raphael.animation({
fill: 'black',
opacity: 0,
cx: ptOnCircle.x,
cy: ptOnCircle.y,
stroke: 0,
r: 0
},1200,function(){
this.remove();
});
var circle = paper.circle(cx, cy, 4).attr({
fill:'black',
stroke: 0
}).animate(anim);
};
setInterval(function(){
flyMeteor();
},200);
var circle = paper.circle(250, 250, 80).attr({
fill:'green',
stroke: 0
});
HTML
<div id="canvas"></div>
Thank you very much for your help!