Thanks Helen.. u rule!

The part which still amazes me is how u made the cut out. So u're saying that by going in reverse over the larger radius circle, using the smaller radius, the drawing would actually behave like the IDE drawing tool and cut out the shape below. I never realized that. It opens up new drawing ideas. Flash is getting too big to keep up with every aspect of it :)

Thanks a lot for this.

Regards,
Navneet



----- Original Message ----- From: "Helen Triolo" <[EMAIL PROTECTED]>
To: "Flashcoders mailing list" <[email protected]>
Sent: Saturday, October 29, 2005 7:56 PM
Subject: Re: [Flashcoders] How to make a doughnut?


Here's one I just made (and tested) from a draw circle prototype that then draws another circle in reverse (before the endfill is applied -- necessary to get a cutout):

// r1 = radius of outer circle
// r2 = radius of inner circle (cutout)
// x, y = center of donut
MovieClip.prototype.drawDonut = function (r1, r2, x, y) {
  var TO_RADIANS:Number = Math.PI/180;
  this.moveTo(0, 0);
  this.lineTo(r1, 0);

  // draw the 30-degree segments
  var a:Number = 0.268;  // tan(15)
  for (var i=0; i < 12; i++) {
     var endx = r1*Math.cos((i+1)*30*TO_RADIANS);
     var endy = r1*Math.sin((i+1)*30*TO_RADIANS);
     var ax = endx+r1*a*Math.cos(((i+1)*30-90)*TO_RADIANS);
     var ay = endy+r1*a*Math.sin(((i+1)*30-90)*TO_RADIANS);
     this.curveTo(ax, ay, endx, endy);   }

  // cut out middle (go in reverse)
  this.moveTo(0, 0);
  this.lineTo(r2, 0);

  for (var i=12; i > 0; i--) {
     var endx = r2*Math.cos((i-1)*30*TO_RADIANS);
     var endy = r2*Math.sin((i-1)*30*TO_RADIANS);
     var ax = endx+r2*(0-a)*Math.cos(((i-1)*30-90)*TO_RADIANS);
     var ay = endy+r2*(0-a)*Math.sin(((i-1)*30-90)*TO_RADIANS);
     this.curveTo(ax, ay, endx, endy);   }

  this._x = x;
  this._y = y;
}

// example usage:
createEmptyMovieClip("d", 1);
d.beginFill(0xaa0000, 60);
d.drawDonut(100, 50, 200, 200);
d.endFill();

Helen

_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to