public override void Initialize(MandalaElement sourceElement, Random random) { // Convert source to correct type ME_Stripe source = (ME_Stripe)sourceElement; Colour = new SvgColourServer(Color.FromArgb(random.Next(256), random.Next(256), random.Next(256))); }
public override List <MandalaElement> Apply(MandalaElement sourceElement) { // Convert source to correct type ME_CircleSector source = (ME_CircleSector)sourceElement; float radiusStep = source.Width / NumStripes; List <MandalaElement> elements = new List <MandalaElement>(); for (int i = 0; i < NumStripes; i++) { float radius = source.InnerRadius + (i + 1) * radiusStep; PointF startPoint = FindLineCircleIntersections(source.Center, radius, source.InnerVertex, source.OuterVertex1)[0]; PointF endPoint = FindLineCircleIntersections(source.Center, radius, source.InnerVertex, source.OuterVertex2)[0]; if (i < NumStripes - 1) { DrawArc(source.SvgDocument, source.Center, radius, startPoint, endPoint); } float lastRadius = radius - radiusStep; PointF lastStartPoint = FindLineCircleIntersections(source.Center, lastRadius, source.InnerVertex, source.OuterVertex1)[0]; PointF lastEndPoint = FindLineCircleIntersections(source.Center, lastRadius, source.InnerVertex, source.OuterVertex2)[0]; // Add Stripe Elements if (i > 0) { int id = (Alternating && i % 2 == 1) ? StripeId2 : StripeId1; ME_Stripe stripe = new ME_Stripe(source.SvgDocument, source.Depth + 1, id, source.Center, lastRadius, radius, lastStartPoint, lastEndPoint, startPoint, endPoint); elements.Add(stripe); } } // Add Sector Element when only 2 stripes if (NumStripes == MinStripes) { float sectorRadius = source.InnerRadius + radiusStep; PointF outer1 = FindLineCircleIntersections(source.Center, sectorRadius, source.InnerVertex, source.OuterVertex1)[0]; PointF outer2 = FindLineCircleIntersections(source.Center, sectorRadius, source.InnerVertex, source.OuterVertex2)[0]; float angle = FindAngleBetweenTwoLineSegments(source.Center, outer1, outer2); float angleDiff = (source.EndAngle - source.StartAngle) - angle; float startPointAngle = source.StartAngle + angleDiff / 2; float endPointAngle = startPointAngle + angle; ME_CircleSector sector = new ME_CircleSector(source.SvgDocument, source.Depth + 1, SectorId, source.Center, source.InnerRadius, sectorRadius, startPointAngle, endPointAngle); elements.Add(sector); } return(elements); }
public override List <MandalaElement> Apply(MandalaElement sourceElement) { // Convert source to correct type ME_Ring source = (ME_Ring)sourceElement; List <MandalaElement> elements = new List <MandalaElement>(); // Create SvgElement and add it to SvgDocument float angleStep = 360f / NumStripes; PointF lastStartPoint = new PointF(0, 0), lastEndPoint = new PointF(0, 0); for (int i = 0; i < NumStripes; i++) { float angle = i * angleStep; float startX = source.Center.X + (float)(source.InnerRadius * Math.Sin(DegreeToRadian(angle))); float startY = source.Center.Y + (float)(source.InnerRadius * Math.Cos(DegreeToRadian(angle))); PointF startPoint = new PointF(startX, startY); float endX = source.Center.X + (float)(source.OuterRadius * Math.Sin(DegreeToRadian(angle))); float endY = source.Center.Y + (float)(source.OuterRadius * Math.Cos(DegreeToRadian(angle))); PointF endPoint = new PointF(endX, endY); DrawLine(source.SvgDocument, startPoint, endPoint); int id = (Alternating && i % 2 == 1) ? StripeId2 : StripeId1; if (i > 0) { ME_Stripe stripe = new ME_Stripe(source.SvgDocument, source.Depth + 1, id, source.Center, source.InnerRadius, source.OuterRadius, lastStartPoint, startPoint, lastEndPoint, endPoint); elements.Add(stripe); } else { float lastAngle = 360f - angleStep; lastStartPoint = new PointF(source.Center.X + (float)(source.InnerRadius * Math.Sin(DegreeToRadian(lastAngle))), source.Center.Y + (float)(source.InnerRadius * Math.Cos(DegreeToRadian(lastAngle)))); lastEndPoint = new PointF(source.Center.X + (float)(source.OuterRadius * Math.Sin(DegreeToRadian(lastAngle))), source.Center.Y + (float)(source.OuterRadius * Math.Cos(DegreeToRadian(lastAngle)))); ME_Stripe stripe = new ME_Stripe(source.SvgDocument, source.Depth + 1, id, source.Center, source.InnerRadius, source.OuterRadius, lastStartPoint, startPoint, lastEndPoint, endPoint); elements.Add(stripe); } lastStartPoint = startPoint; lastEndPoint = endPoint; } return(elements); }
public override List <MandalaElement> Apply(MandalaElement sourceElement) { // Convert source to correct type ME_Stripe source = (ME_Stripe)sourceElement; SvgPath svgPath = new SvgPath() { Fill = Colour, StrokeWidth = 0, }; svgPath.PathData = new SvgPathSegmentList(); SvgMoveToSegment svgStartMove = new SvgMoveToSegment(source.InnerVertex1); svgPath.PathData.Add(svgStartMove); SvgArcSegment arc1 = new SvgArcSegment(source.InnerVertex1, source.InnerRadius, source.InnerRadius, 0, SvgArcSize.Small, SvgArcSweep.Negative, source.InnerVertex2); svgPath.PathData.Add(arc1); SvgLineSegment line1 = new SvgLineSegment(source.InnerVertex2, source.OuterVertex2); svgPath.PathData.Add(line1); SvgArcSegment arc2 = new SvgArcSegment(source.OuterVertex2, source.OuterRadius, source.OuterRadius, 0, SvgArcSize.Small, SvgArcSweep.Positive, source.OuterVertex1); svgPath.PathData.Add(arc2); SvgLineSegment line2 = new SvgLineSegment(source.OuterVertex1, source.InnerVertex1); svgPath.PathData.Add(line2); source.SvgDocument.Children.Add(svgPath); return(new List <MandalaElement>() { }); }
public override List <MandalaElement> Apply(MandalaElement sourceElement) { // Convert source to correct type ME_StarSpike source = (ME_StarSpike)sourceElement; // Find intersection points PointF intersection1 = FindLineCircleIntersections(source.CircleCenter, SplitRadius, source.InnerVertex1, source.OuterVertex)[0]; PointF intersection2 = FindLineCircleIntersections(source.CircleCenter, SplitRadius, source.InnerVertex2, source.OuterVertex)[0]; float angle = FindAngleBetweenTwoLineSegments(source.CircleCenter, intersection1, intersection2); float startAngle = source.Angle - angle / 2; float endAngle = source.Angle + angle / 2; DrawArc(source.SvgDocument, source.CircleCenter, SplitRadius, startAngle, endAngle); // Create elements ME_StarSpike spike = new ME_StarSpike(source.SvgDocument, source.Depth + 1, SpikeId, source.CircleCenter, SplitRadius, source.Angle, intersection1, intersection2, source.OuterVertex); ME_Stripe stripe = new ME_Stripe(source.SvgDocument, source.Depth + 1, StripeId, source.CircleCenter, source.CircleRadius, SplitRadius, source.InnerVertex1, source.InnerVertex2, intersection1, intersection2); return(new List <MandalaElement>() { spike, stripe }); }