public override void Initialize(MandalaElement sourceElement, Random random) { // Convert source to correct type ME_CircleSector source = (ME_CircleSector)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; SvgPath svgPath = new SvgPath() { Fill = Colour, StrokeWidth = 0 }; svgPath.PathData = new SvgPathSegmentList(); SvgMoveToSegment svgStartMove = new SvgMoveToSegment(source.InnerVertex); svgPath.PathData.Add(svgStartMove); SvgLineSegment line = new SvgLineSegment(source.InnerVertex, source.OuterVertex1); svgPath.PathData.Add(line); SvgArcSegment arc = new SvgArcSegment(source.OuterVertex1, source.OuterRadius, source.OuterRadius, 0, SvgArcSize.Small, SvgArcSweep.Negative, source.OuterVertex2); svgPath.PathData.Add(arc); source.SvgDocument.Children.Add(svgPath); return(new List <MandalaElement>() { }); }
public override void Initialize(MandalaElement sourceElement, Random random) { // Convert source to correct type ME_CircleSector source = (ME_CircleSector)sourceElement; // Element ids CircleId = MandalaElement.ElementId++; }
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 void Initialize(MandalaElement sourceElement, Random random) { // Convert source to correct type ME_CircleSector source = (ME_CircleSector)sourceElement; // # Stripes if (random.Next(2) == 1) { NumStripes = MinStripes; } else { NumStripes = random.Next(MaxStripes - MinStripes + 2) + MinStripes; } Alternating = random.Next(2) == 1; // Element ids SectorId = MandalaElement.ElementId++; StripeId1 = MandalaElement.ElementId++; StripeId2 = MandalaElement.ElementId++; }
public override List <MandalaElement> Apply(MandalaElement sourceElement) { // Convert source to correct type ME_Circle source = (ME_Circle)sourceElement; // Draw Star float angle; if (source.Centered) { angle = 180; } else { angle = source.AngleFromCenter; } PointF[] vertices = DrawStar(source.SvgDocument, source.Center, InnerRadius, source.Radius, NumCorners, angle); List <MandalaElement> elements = new List <MandalaElement>(); // Create Star Element ME_Star star = new ME_Star(source.SvgDocument, source.Depth + 1, StarId, source.Center, InnerRadius, source.Radius, NumCorners, angle, source.Centered, vertices); elements.Add(star); // Create Sectors float angleStep = 360f / NumCorners; for (int i = 0; i < NumCorners; i++) { float startAngle = angle + i * angleStep; float endAngle = startAngle + angleStep; ME_CircleSector sector = new ME_CircleSector(source.SvgDocument, source.Depth + 1, SectorId, source.Center, InnerRadius, source.Radius, startAngle, endAngle); elements.Add(sector); } return(elements); }
public override List <MandalaElement> Apply(MandalaElement sourceElement) { // Convert source to correct type ME_CircleSector source = (ME_CircleSector)sourceElement; float sin = (float)(Math.Sin(DegreeToRadian(source.InnerAngle / 2))); float radius = ((-source.InnerRadius * sin) + (source.OuterRadius * sin)) / (sin + 1); float circleAngle = (source.StartAngle + source.EndAngle) / 2; PointF tangent = FindPointOnCircle(source.Center, source.OuterRadius, circleAngle); List <PointF> intersect = FindLineCircleIntersections(tangent, radius, source.InnerVertex, tangent); PointF center = intersect[1]; DrawCircle(source.SvgDocument, center, radius); ME_Circle circle = new ME_Circle(source.SvgDocument, source.Depth + 1, CircleId, center, radius, circleAngle, false); return(new List <MandalaElement>() { circle }); }