コード例 #1
0
    public override void Initialize(MandalaElement sourceElement, Random random)
    {
        // Convert source to correct type
        ME_Circle source = (ME_Circle)sourceElement;

        // Get # corners
        NumCorners = random.Next(MaxCorners - MinCorners + 1) + MinCorners;

        // Get Radius (keep doing until shape is concave)
        float innerAngle = 361;

        while (innerAngle > 180)
        {
            float minInnerRadius = source.Radius * MinInnerRadius;
            float maxInnerRadius = source.Radius;
            InnerRadius = (float)random.NextDouble() * (maxInnerRadius - minInnerRadius) + minInnerRadius;

            float  angleStep = 360f / (NumCorners * 2);
            PointF outer1    = FindPointOnCircle(source.Center, source.Radius, 0);
            PointF inner     = FindPointOnCircle(source.Center, InnerRadius, angleStep);
            PointF outer2    = FindPointOnCircle(source.Center, source.Radius, angleStep * 2);

            innerAngle = FindAngleBetweenTwoLineSegments(inner, outer1, outer2);
        }

        // Element ids
        StarId   = MandalaElement.ElementId++;
        SectorId = MandalaElement.ElementId++;
    }
コード例 #2
0
    public override void Initialize(MandalaElement sourceElement, Random random)
    {
        // Convert source to correct type
        ME_Circle source = (ME_Circle)sourceElement;

        // Get Radius
        float minRadius = source.Radius * MinRadius;
        float maxRadius = source.Radius * MaxRadius;

        Radius = (float)random.NextDouble() * (maxRadius - minRadius) + minRadius;

        // Element ids
        CircleId = MandalaElement.ElementId++;
        RingId   = MandalaElement.ElementId++;
    }
コード例 #3
0
    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
        });
    }
コード例 #4
0
    public override List <MandalaElement> Apply(MandalaElement sourceElement)
    {
        // Convert source to correct type
        ME_Empty source = (ME_Empty)sourceElement;

        // Take Center
        float  centerX = source.SvgDocument.Width / 2;
        float  centerY = source.SvgDocument.Height / 2;
        PointF center  = new PointF(centerX, centerY);

        // Create SvgElement and add it to SvgDocument
        DrawCircle(source.SvgDocument, center, Radius);

        // Create Mandala Elements and return them
        ME_Circle circle = new ME_Circle(source.SvgDocument, source.Depth + 1, CircleId, center, Radius, 0, true);

        return(new List <MandalaElement>()
        {
            circle
        });
    }
コード例 #5
0
    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);
    }
コード例 #6
0
    public override List <MandalaElement> Apply(MandalaElement sourceElement)
    {
        // Convert source to correct type
        ME_Star source = (ME_Star)sourceElement;

        // Take Center
        float radius = source.InnerRadius;

        DrawCircle(source.SvgDocument, source.Center, radius);

        List <MandalaElement> elements = new List <MandalaElement>();

        // Add circle element
        ME_Circle circle = new ME_Circle(source.SvgDocument, source.Depth + 1, CircleId, source.Center, radius, source.AngleFromCenter, source.Centered);

        elements.Add(circle);

        // Add star spike elements
        float angleStep = 360f / source.Corners;

        for (int i = 0; i < source.Corners; i++)
        {
            int   cornerId = i * 2;
            float angle    = source.AngleFromCenter + i * angleStep;
            int   id       = (Alternating && i % 2 == 1) ? SpikeId2 : SpikeId1;

            ME_StarSpike spike = new ME_StarSpike(source.SvgDocument, source.Depth + 1, id, source.Center, source.InnerRadius, angle,
                                                  source.Vertices[cornerId == 0 ? (source.Vertices.Length - 1) : (cornerId - 1)],
                                                  source.Vertices[(cornerId + 1) % source.Vertices.Length],
                                                  source.Vertices[cornerId]
                                                  );
            elements.Add(spike);
        }

        return(elements);
    }
コード例 #7
0
    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
        });
    }