Rank: Advanced Member
Groups: Guest
Joined: 1/31/2005(UTC) Posts: 458
Was thanked: 5 time(s) in 5 post(s)
|
Hello Ching-Yen, Here is simple snippet (no coords checks, be careful :)) for rectangle object with hole: Code:class HoledRectVObject: RectangleVObject
{
public HoledRectVObject(float x,
float y,
float w,
float h,
float holeX,
float holeY,
float holeRadius,
bool makeRoundHole)
: base(x, y, w, h)
{
if (makeRoundHole)
{
base.Path.AddEllipse(
x + holeX - holeRadius,
y + holeY - holeRadius, 2 * holeRadius, 2 * holeRadius);
}
else
{
System.Drawing.PointF[] vertexes = new System.Drawing.PointF[7];
Random rnd = new Random();
double angle = Math.PI * rnd.NextDouble();
double angleStep = 2 * Math.PI / vertexes.Length;
for (int i = 0; i < vertexes.Length; i++)
{
float r = holeRadius + rnd.Next((int)w / 10);
vertexes[i].X = (float)(x + holeX + Math.Cos(angle) * r);
vertexes[i].Y = (float)(y + holeY + Math.Sin(angle) * r);
angle += angleStep;
}
base.Path.AddPolygon(vertexes);
}
}
}
Usage almost the same as with RectangleVObject: Code:_mlv.CurrentLayer.VObjects.Add(
new HoledRectVObject(50, 300, 200, 200, 100, 100, 80, true));
_mlv.CurrentLayer.VObjects.Add(
new HoledRectVObject(200, 100, 200, 200, 100, 100, 80, false));
Best regards, Alex Kon |
1 user thanked Alex Kon for this useful post.
|
|