private int GetMaxNumCircles(ME_Ring source) { // Get center point of first circle float centerX1 = source.Center.X + (float)((source.InnerRadius + source.Width / 2) * Math.Sin(DegreeToRadian(0))); float centerY1 = source.Center.Y + (float)((source.InnerRadius + source.Width / 2) * Math.Cos(DegreeToRadian(0))); PointF center1 = new PointF(centerX1, centerY1); float radius = source.Width / 2; // Get intersections of "tangent circle of first circle" (circle that has all the points which would tangent the first circle as a center with the same radius) // with the "radius circle" (middle between inner and outer radius of ring) List <PointF> intersections = FindCircleCircleIntersections(center1, radius * 2, source.Center, source.InnerRadius + source.Width / 2); // Return 1 if only 1 circle possible if (intersections.Count == 0) { return(1); } // Keep making circles in one directions until it touches first circle int count = 0; while (count == 0 || (intersections.Count == 2 && FindCircleCircleIntersections(intersections[0], radius, center1, radius).Count == 0)) { intersections = FindCircleCircleIntersections(intersections[0], radius * 2, source.Center, source.InnerRadius + source.Width / 2); count++; } return(count + 1); }
public override void Initialize(MandalaElement sourceElement, Random random) { // Convert source to correct type ME_Ring source = (ME_Ring)sourceElement; // # circles int maxCircles = GetMaxNumCircles(source); if (maxCircles < MinCircles) { NumCircles = 0; // Don't draw any circles if minimum is not possible } else { if (random.Next(2) == 1) { NumCircles = maxCircles; } else { NumCircles = random.Next(maxCircles - MinCircles) + MinCircles; } } // Creating element ids Alternating = random.Next(2) == 1; if (NumCircles % 2 == 1) { Alternating = false; } RingId1 = MandalaElement.ElementId++; RingId2 = MandalaElement.ElementId++; // only used for alternating }
public override List <MandalaElement> Apply(MandalaElement sourceElement) { // Convert source to correct type ME_Ring source = (ME_Ring)sourceElement; // Get Circle radius float circleRadius = source.Width / 2; // Create SvgElement and add it to SvgDocument List <MandalaElement> elements = new List <MandalaElement>(); float angleStep = 360f / NumCircles; for (int i = 0; i < NumCircles; i++) { float angle = i * angleStep; float centerX = source.Center.X + (float)((source.InnerRadius + source.Width / 2) * Math.Sin(DegreeToRadian(angle))); float centerY = source.Center.Y + (float)((source.InnerRadius + source.Width / 2) * Math.Cos(DegreeToRadian(angle))); PointF center = new PointF(centerX, centerY); DrawCircle(source.SvgDocument, center, circleRadius); elements.Add(new ME_Circle(source.SvgDocument, source.Depth + 1, (Alternating && i % 2 == 1) ? RingId2 : RingId1, center, circleRadius, angle, false)); } return(elements); }
public override bool CanApply(MandalaElement sourceElement) { if (sourceElement.Type != MandalaElementType.Ring) { return(false); } else { return(true); // ? } ME_Ring source = (ME_Ring)sourceElement; // Ring has to be thinner than innerradius return(source.Width < source.InnerRadius); }
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_Circle source = (ME_Circle)sourceElement; // Create SvgElement and add it to SvgDocument DrawCircle(source.SvgDocument, source.Center, Radius); // Create Mandala Elements and return them ME_Circle circle = new ME_Circle(source.SvgDocument, source.Depth + 1, CircleId, source.Center, Radius, source.AngleFromCenter, source.Centered);; ME_Ring ring = new ME_Ring(source.SvgDocument, source.Depth + 1, RingId, source.Center, Radius, source.Radius); return(new List <MandalaElement>() { circle, ring }); }
public override void Initialize(MandalaElement sourceElement, Random random) { // Convert source to correct type ME_Ring source = (ME_Ring)sourceElement; // Get # of Stripes int factor = random.Next(MaxFactor - MinFactor) + MinFactor; NumStripes = 1; for (int i = 0; i < factor; i++) { NumStripes *= 2; } Alternating = random.Next(2) == 1; // Element ids StripeId1 = MandalaElement.ElementId++; StripeId2 = MandalaElement.ElementId++; }