Example #1
0
        public static Sm.LinearGradientBrush ToMediaBrush(this Wg.GradientLinear input)
        {
            Sm.LinearGradientBrush brush = new Sm.LinearGradientBrush();
            int i = 0;

            foreach (Wg.Color color in input.Colors)
            {
                brush.GradientStops.Add(new Sm.GradientStop(color.ToMediaColor(), input.Stops[i]));
                i++;
            }

            brush.SpreadMethod = Sm.GradientSpreadMethod.Pad;
            brush.MappingMode  = Sm.BrushMappingMode.RelativeToBoundingBox;

            double radians = input.Angle / 180 * Math.PI;
            double XA      = (0.5 + Math.Sin(radians) * 0.5);
            double YA      = (0.5 + Math.Cos(radians) * 0.5);
            double XB      = (0.5 + Math.Sin(radians + Math.PI) * 0.5);
            double YB      = (0.5 + Math.Cos(radians + Math.PI) * 0.5);

            brush.StartPoint = new Point(XA, YA);
            brush.EndPoint   = new Point(XB, YB);

            return(brush);
        }
Example #2
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Wg.Graphic graphic = Wg.Graphics.FillBlack;
            if (!DA.GetData(0, ref graphic))
            {
                graphic = new Wg.Graphic(graphic);
            }

            List <Color> colors = new List <Color>();

            DA.GetDataList(1, colors);

            List <double> stops = new List <double>();

            DA.GetDataList(2, stops);

            double angle = 0;

            DA.GetData(3, ref angle);

            List <Wg.Color> windColors = new List <Wg.Color>();

            foreach (Color color in colors)
            {
                windColors.Add(color.ToWindColor());
            }

            Wg.GradientLinear gradient = new Wg.GradientLinear(windColors, stops);
            gradient.Angle = angle;
            graphic.Fill   = gradient;

            DA.SetData(0, graphic);
        }
Example #3
0
        public static string ToSVG(this Wg.GradientLinear input)
        {
            double radians = input.Angle / 180 * Math.PI;
            double XA      = (50 + Math.Sin(radians) * 50);
            double YA      = (50 + Math.Cos(radians) * 50);
            double XB      = (50 + Math.Sin(radians + Math.PI) * 50);
            double YB      = (50 + Math.Cos(radians + Math.PI) * 50);

            string output = "<linearGradient id=\"" + input.ID + "\" ";

            output += "x1=\"" + XA + "%\" y1=\"" + YA + "%\" ";
            output += "x2=\"" + XB + "%\" y2=\"" + YB + "%\" ";
            output += "gradientUnits=\"objectBoundingBox\" >" + Environment.NewLine;
            for (int i = 0; i < input.Colors.Count; i++)
            {
                output += "<stop offset=\"" + (input.Stops[i] * 100.0) + "%\" style=\"stop-color:" + input.Colors[i].ToSVG() + "; stop-opacity:" + (input.Colors[i].A / 255.0) + "\" />" + Environment.NewLine;
            }
            output += "</linearGradient>";

            return(output);
        }
Example #4
0
 public GradientLinear(GradientLinear gradient) : base(gradient)
 {
     this.Angle = gradient.Angle;
 }