protected override void GeneratePattern()
        {
            var scale    = HexVal(0, 1);
            var diameter = scale.MapTo(0, 15, 25, 200);
            var radius   = diameter / 2;

            Svg.Width  = radius * 6;
            Svg.Height = radius * 6;

            var i = 0;

            for (var y = 0; y <= 5; y++)
            {
                for (var x = 0; x <= 5; x++)
                {
                    var val     = HexVal(i, 1);
                    var opacity = Opacity(val);
                    var fill    = FillColor(val);

                    var styles = new Dictionary <string, object>
                    {
                        { "fill", fill },
                        { "style", new Dictionary <string, object>
                          {
                              { "opacity", opacity }
                          } }
                    };

                    Svg.Circle(x * radius, y * radius, radius, styles);

                    // Add an extra one at top-right, for tiling.
                    if (x == 0)
                    {
                        Svg.Circle(6 * radius, y * radius, radius, styles);
                    }

                    // Add an extra row at the end that matches the first row, for tiling.
                    if (y == 0)
                    {
                        Svg.Circle(x * radius, 6 * radius, radius, styles);
                    }

                    // Add an extra one at bottom-right, for tiling.
                    if (x == 0 && y == 0)
                    {
                        Svg.Circle(6 * radius, 6 * radius, radius, styles);
                    }

                    i++;
                }
            }
        }
        protected override void GeneratePattern()
        {
            var scale        = HexVal(0, 1);
            var ring_size    = scale.MapTo(0, 15, 10, 60);
            var stroke_width = ring_size / 4;

            Svg.Width  = ring_size * 6;
            Svg.Height = ring_size * 6;

            var i = 0;

            for (var y = 0; y <= 5; y++)
            {
                for (var x = 0; x <= 5; x++)
                {
                    var val     = HexVal(i, 1);
                    var opacity = Opacity(val);
                    var fill    = FillColor(val);

                    var styles = new Dictionary <string, object> {
                        { "fill", "none" },
                        { "stroke", fill },
                        {
                            "style", new Dictionary <string, object> {
                                { "opacity", opacity },
                                { "stroke-width", stroke_width + "px" }
                            }
                        }
                    };

                    Svg.Circle(x * ring_size, y * ring_size, ring_size - stroke_width / 2, styles);

                    // Add an extra one at top-right, for tiling.
                    if (x == 0)
                    {
                        Svg.Circle(6 * ring_size, y * ring_size, ring_size - stroke_width / 2, styles);
                    }

                    if (y == 0)
                    {
                        Svg.Circle(x * ring_size, 6 * ring_size, ring_size - stroke_width / 2, styles);
                    }

                    if (x == 0 && y == 0)
                    {
                        Svg.Circle(6 * ring_size, 6 * ring_size, ring_size - stroke_width / 2, styles);
                    }

                    i++;
                }
            }
        }
        protected override void GeneratePattern()
        {
            var scale        = HexVal(0, 1);
            var ring_size    = scale.MapTo(0, 15, 10, 60);
            var stroke_width = ring_size / 5;

            Svg.Width  = (ring_size + stroke_width) * 6;
            Svg.Height = (ring_size + stroke_width) * 6;

            var i = 0;

            for (var y = 0; y <= 5; y++)
            {
                for (var x = 0; x <= 5; x++)
                {
                    var val     = HexVal(i, 1);
                    var opacity = Opacity(val);
                    var fill    = FillColor(val);

                    Svg.Circle(x * ring_size + x * stroke_width + (ring_size + stroke_width) / 2,
                               y * ring_size + y * stroke_width + (ring_size + stroke_width) / 2,
                               ring_size / 2,
                               new Dictionary <string, object> {
                        { "fill", "none" },
                        { "stroke", fill },
                        {
                            "style", new Dictionary <string, object> {
                                { "opacity", opacity },
                                { "stroke-width", stroke_width + "px" }
                            }
                        }
                    });

                    val     = HexVal(39 - i, 1);
                    opacity = Opacity(val);
                    fill    = FillColor(val);

                    Svg.Circle(x * ring_size + x * stroke_width + (ring_size + stroke_width) / 2,
                               y * ring_size + y * stroke_width + (ring_size + stroke_width) / 2,
                               ring_size / 4,
                               new Dictionary <string, object> {
                        { "fill", fill },
                        { "fill-opacity", opacity }
                    });

                    i++;
                }
            }
        }
Exemple #4
0
        public CirclesModule()
        {
            Get["/examples/w3schools/circles/1"] = _ =>
            {
                var svg = new Svg(100, 100);

                svg
                    .Circle(50, 50, 40)
                    .WithStroke("black")
                    .WithStrokeWidth(3)
                    .WithFill("red");

                return Response.AsText(svg.ToString(), "image/svg+xml");
            };
        }
Exemple #5
0
        public CirclesModule()
        {
            Get["/examples/w3schools/circles/1"] = _ =>
            {
                var svg = new Svg(100, 100);

                svg
                .Circle(50, 50, 40)
                .WithStroke("black")
                .WithStrokeWidth(3)
                .WithFill("red");

                return(Response.AsText(svg.ToString(), "image/svg+xml"));
            };
        }
Exemple #6
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));
            };
        }
        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);
            };
        }