Sapendo che:
1. iniziando un riempimento e disegnando una forma, per poi disegnarne un'altra prima di chiudere il riempimento, la seconda forma viene sottratta alla prima
2. sapendo che perchè possa funzionare come maschera, la seconda forma deve essere disegnata in senso opposto
creiamo agevolmente il metodo drawTorus:
codice:
MovieClip.prototype.drawTorus = function(x, y, outerRadius, innerRadius, startAngle, endAngle, segments)
{
var rad = Math.PI / 180;
var segm = (endAngle - startAngle) / segments;
this.moveTo(x + outerRadius * Math.cos(startAngle * rad), y + outerRadius * Math.sin(startAngle * rad));
this.beginFill(0xff0000, 100);
for (var s = startAngle + segm; s <= endAngle + 1; s += segm) {
var c_x = outerRadius * Math.cos(s * rad);
var c_y = outerRadius * Math.sin(s * rad);
var a_x = c_x + outerRadius * Math.tan(segm / 2 * rad) * Math.cos((s - 90) * rad);
var a_y = c_y + outerRadius * Math.tan(segm / 2 * rad) * Math.sin((s - 90) * rad);
this.curveTo(a_x + x, a_y + y, c_x + x, c_y + y);
}
this.moveTo(x + innerRadius * Math.cos(startAngle * rad), y + innerRadius * Math.sin(startAngle * rad));
for (var s = endAngle; s >= 0; s -= segm) {
var c_x = innerRadius * Math.cos(s * rad);
var c_y = innerRadius * Math.sin(s * rad);
var a_x = c_x + innerRadius * Math.tan(segm / 2 * rad) * Math.cos((s + 90) * rad);
var a_y = c_y + innerRadius * Math.tan(segm / 2 * rad) * Math.sin((s + 90) * rad);
this.curveTo(a_x + x, a_y + y, c_x + x, c_y + y);
}
this.endFill();
};
this.createEmptyMovieClip("mask", 1);
mask.drawTorus(220, 130, 100, 70, 0, 360, 8);
mc.setMask(mask)