Example #1
1
        public LinesModule()
        {
            Get["/examples/w3schools/lines/1"] = _ =>
            {
                var svg = new Svg(500,210);

                svg
                    .Line(0, 0, 200, 200)
                    .WithStroke(255, 0, 0)
                    .WithStrokeWidth(2);

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };
        }
Example #2
0
        public IEnumerable <XElement> GetSvgPaths()
        {
            Kurve.Curves.Curve curve = optimizer.GetCurve(specification);

            IEnumerable <string> curveCommands = Enumerables.Concatenate
                                                 (
                Enumerables.Create(Svg.MoveTo(curve.GetPoint(0))),
                from positions in Scalars.GetIntermediateValuesSymmetric(0, 1, SegmentCount + 1).GetRanges()
                let controlPoint1 = curve.GetPoint(positions.Item1) + (1.0 / (3 * SegmentCount)) * curve.GetVelocity(positions.Item1)
                                    let controlPoint2 = curve.GetPoint(positions.Item2) - (1.0 / (3 * SegmentCount)) * curve.GetVelocity(positions.Item2)
                                                        let point2 = curve.GetPoint(positions.Item2)
                                                                     select Svg.CurveTo(controlPoint1, controlPoint2, point2)
                                                 );

            yield return(Svg.PathShape(curveCommands, null, Colors.Black, 2));

            IEnumerable <string> curvatureMarkersCommands =
                (
                    from positions in Scalars.GetIntermediateValuesSymmetric(0, 1, SegmentCount + 1).GetRanges()
                    let position = Enumerables.Average(positions.Item1, positions.Item2)
                                   let curvatureVector = CurvatureMarkersFactor * curve.GetCurvature(position) * curve.GetNormalVector(position)
                                                         select Svg.Line(curve.GetPoint(position), curve.GetPoint(position) + curvatureVector)
                );

            yield return(Svg.PathShape(curvatureMarkersCommands, null, Colors.Blue, 0.5));

            foreach (PointCurveSpecification pointCurveSpecification in specification.BasicSpecification.CurveSpecifications.OfType <PointCurveSpecification>())
            {
                Vector2Double point = curve.GetPoint(pointCurveSpecification.Position);

                yield return(Svg.CircleShape(point, 10, Colors.Red, null, 0));
            }
            foreach (DirectionCurveSpecification directionCurveSpecification in specification.BasicSpecification.CurveSpecifications.OfType <DirectionCurveSpecification>())
            {
                Vector2Double directionVector = curve.GetDirectionVector(directionCurveSpecification.Position);
                Vector2Double start           = curve.GetPoint(directionCurveSpecification.Position) - 1000 * directionVector;
                Vector2Double end             = curve.GetPoint(directionCurveSpecification.Position) + 1000 * directionVector;

                yield return(Svg.LineShape(start, end, null, Colors.Green, 2));
            }
            foreach (CurvatureCurveSpecification curvatureCurveSpecification in specification.BasicSpecification.CurveSpecifications.OfType <CurvatureCurveSpecification>())
            {
                if (curvatureCurveSpecification.Curvature == 0)
                {
                    Vector2Double directionVector = curve.GetDirectionVector(curvatureCurveSpecification.Position);
                    Vector2Double start           = curve.GetPoint(curvatureCurveSpecification.Position) - 1000 * directionVector;
                    Vector2Double end             = curve.GetPoint(curvatureCurveSpecification.Position) + 1000 * directionVector;

                    yield return(Svg.LineShape(start, end, null, Colors.Blue, 2));
                }
                else
                {
                    Vector2Double center = curve.GetPoint(curvatureCurveSpecification.Position) - (1.0 / curvatureCurveSpecification.Curvature) * curve.GetNormalVector(curvatureCurveSpecification.Position);
                    double        radius = 1.0 / curvatureCurveSpecification.Curvature.Absolute();

                    yield return(Svg.CircleShape(center, radius, null, Colors.Blue, 2));
                }
            }
        }
Example #3
0
        public LinesModule()
        {
            Get["/examples/w3schools/lines/1"] = _ =>
            {
                var svg = new Svg(500, 210);

                svg
                .Line(0, 0, 200, 200)
                .WithStroke(255, 0, 0)
                .WithStrokeWidth(2);

                return(Response.AsText(svg.ToString(), "image/svg+xml"));
            };
        }
Example #4
0
        public MultiLineTextModule()
        {
            Get["examples/text/multi-line-text/howl"] = _ =>
            {
                var svg = new Svg(600, 160);

                svg.WithBackgroundFill("#ddd");

                var howl = @"I saw the best minds of my generation destroyed by madness, starving hysterical naked,
dragging themselves through the negro streets at dawn looking for an angry fix,
Angel-headed hipsters burning for the ancient heavenly connection
to the starry dynamo in the machinery of night
- Howl, Allen Ginsberg";

                svg.MultiLineText(20, 20, howl);

                return(Response.AsSvg(svg));
            };

            Get["examples/text/multi-line-text/haiku"] = _ =>
            {
                var svg = new Svg(400, 100);

                svg.WithBackgroundFill("#dde");

                var haiku = @"the first cold shower
even the monkey seems to want
a little coat of straw";

                svg.MultiLineText((svg.Width ?? 0) / 2, 20, haiku)
                .WithTextAnchor(TextAnchor.Middle)
                .WithFontStyle(FontStyle.Italic)
                .WithFontFamily(FontFamilies.Helvetica);

                return(Response.AsSvg(svg));
            };

            Get["examples/text/multi-line-text/ulysses"] = _ =>
            {
                var svg = new Svg(250, 700);

                svg.WithBackgroundFill("#333");

                var text = @"Stately, plump Buck Mulligan came from the stairhead, bearing a bowl of lather on which a mirror and a razor lay crossed. A yellow dressinggown, ungirdled, was sustained gently behind him by the mild morning air.";

                svg.MultiLineText(140, 0, text)
                .WithAutoLineSplit(10)
                .WithFontFamily(FontFamilies.Helvetica)
                .WithFill("gold")
                .WithTransformRotate(10);

                return(Response.AsSvg(svg));
            };

            Get["examples/text/multi-line-text/show-origin"] = _ =>
            {
                var svg = new Svg(400, 200);

                svg.WithBackgroundFill("#ddd");

                var text = @"FALSTAFF: Come, thou shalt go to the wars in a
gown. We will have away thy cold; and I will
take such order that thy friends shall ring for
thee. Is here all?";

                svg.MultiLineText(30, 30, text);
                svg.Circle(30, 30, 2).WithFill("red");

                return(Response.AsSvg(svg));
            };


            Get["examples/text/multi-line-text/element-line-height"] = _ =>
            {
                var svg = new Svg(550, 250);

                svg.WithBackgroundFill("#ddd");

                var text = @"No one would have believed, in the last years of the nineteenth century, that human affairs were being watched keenly and closely by intelligences greater than man’s and yet as mortal as his own; that as men busied themselves about their affairs they were scrutinized and studied, perhaps almost as narrowly as a man with a microscope might scrutinize the transient creatures that swarm and multiply in a drop of water.";

                var textElement = svg.MultiLineText(30, 40, text)
                                  .WithAutoLineSplit(60);
                svg.Line((textElement.X ?? 0) - 14, (textElement.Y ?? 0), (textElement.X ?? 0) - 14, (textElement.Y ?? 0) + (textElement.Height ?? 0))
                .WithStroke("brown")
                .WithStrokeLinecap(StrokeLinecap.Round)
                .WithStrokeWidth(3);

                return(Response.AsSvg(svg));
            };
        }
Example #5
0
        public MultiLineTextModule()
        {
            Get["examples/text/multi-line-text/howl"] = _ =>
            {
                var svg = new Svg(600, 160);

                svg.WithBackgroundFill("#ddd");

                var howl = @"I saw the best minds of my generation destroyed by madness, starving hysterical naked,
            dragging themselves through the negro streets at dawn looking for an angry fix,
            Angel-headed hipsters burning for the ancient heavenly connection
            to the starry dynamo in the machinery of night
            - Howl, Allen Ginsberg";

                svg.MultiLineText(20,20, howl);

                return Response.AsSvg(svg);
            };

            Get["examples/text/multi-line-text/haiku"] = _ =>
            {
                var svg = new Svg(400, 100);

                svg.WithBackgroundFill("#dde");

                var haiku = @"the first cold shower
            even the monkey seems to want
            a little coat of straw";

                svg.MultiLineText((svg.Width ?? 0)/2, 20, haiku)
                    .WithTextAnchor(TextAnchor.Middle)
                    .WithFontStyle(FontStyle.Italic)
                    .WithFontFamily(FontFamilies.Helvetica);

                return Response.AsSvg(svg);
            };

            Get["examples/text/multi-line-text/ulysses"] = _ =>
            {
                var svg = new Svg(250, 700);

                svg.WithBackgroundFill("#333");

                var text = @"Stately, plump Buck Mulligan came from the stairhead, bearing a bowl of lather on which a mirror and a razor lay crossed. A yellow dressinggown, ungirdled, was sustained gently behind him by the mild morning air.";

                svg.MultiLineText(140, 0, text)
                    .WithAutoLineSplit(10)
                    .WithFontFamily(FontFamilies.Helvetica)
                    .WithFill("gold")
                    .WithTransformRotate(10);

                return Response.AsSvg(svg);
            };

            Get["examples/text/multi-line-text/show-origin"] = _ =>
            {
                var svg = new Svg(400, 200);

                svg.WithBackgroundFill("#ddd");

                var text = @"FALSTAFF: Come, thou shalt go to the wars in a
            gown. We will have away thy cold; and I will
            take such order that thy friends shall ring for
            thee. Is here all?";

                svg.MultiLineText(30, 30, text);
                svg.Circle(30, 30, 2).WithFill("red");

                return Response.AsSvg(svg);
            };

            Get["examples/text/multi-line-text/element-line-height"] = _ =>
            {
                var svg = new Svg(550, 250);

                svg.WithBackgroundFill("#ddd");

                var text = @"No one would have believed, in the last years of the nineteenth century, that human affairs were being watched keenly and closely by intelligences greater than man’s and yet as mortal as his own; that as men busied themselves about their affairs they were scrutinized and studied, perhaps almost as narrowly as a man with a microscope might scrutinize the transient creatures that swarm and multiply in a drop of water.";

                var textElement = svg.MultiLineText(30, 40, text)
                    .WithAutoLineSplit(60);
                svg.Line((textElement.X ?? 0) - 14, (textElement.Y ?? 0), (textElement.X ?? 0) - 14, (textElement.Y ?? 0) + (textElement.Height ?? 0))
                    .WithStroke("brown")
                    .WithStrokeLinecap(StrokeLinecap.Round)
                    .WithStrokeWidth(3);

                return Response.AsSvg(svg);
            };
        }