Exemple #1
0
        public static string GetFlameModelJson(TransformModel[] transformations, VariationModel[] variations,
                                               ViewSettingsModel viewSettings, GradientModel gradModel)
        {
            var flameModel = FlameModelFromObjects(transformations, variations, viewSettings, gradModel);

            return(JsonConvert.SerializeObject(flameModel, Formatting.Indented, JsonSerializerSettings));
        }
Exemple #2
0
        private static FlameModel FlameModelFromObjects(IReadOnlyList <TransformModel> transformations,
                                                        IReadOnlyList <VariationModel> variations,
                                                        ViewSettingsModel viewSettings, GradientModel gradModel)
        {
            var coefficients   = new List <double[]>();
            var variationIds   = new List <int>();
            var parameters     = new List <double[]>();
            var colors         = new List <Color>();
            var colorPositions = new List <double>();
            var weights        = new List <double>();
            var isFinal        = new List <bool>();

            for (var i = 0; i < transformations.Count; i++)
            {
                //todo isFinal
                isFinal.Add(transformations[i].IsFinal);
                coefficients.Add(new[]
                {
                    transformations[i].A,
                    transformations[i].B,
                    transformations[i].C,
                    transformations[i].D,
                    transformations[i].E,
                    transformations[i].F,
                    transformations[i].Probability
                });
                variationIds.Add(variations[i].Id);
                parameters.Add(new double[variations[i].HasParameters]);
                for (var j = 0; j < variations[i].HasParameters; j++)
                {
                    switch (j)
                    {
                    case 0:
                        parameters[i][j] = variations[i].P1;
                        break;

                    case 1:
                        parameters[i][j] = variations[i].P2;
                        break;

                    case 2:
                        parameters[i][j] = variations[i].P3;
                        break;

                    case 3:
                        parameters[i][j] = variations[i].P4;
                        break;
                    }
                }

                colorPositions.Add(transformations[i].ColorPosition);
                colors.Add(transformations[i].Color);
                weights.Add(variations[i].W);
            }

            var flameModel = new FlameModel
            {
                ImageWidth     = viewSettings.ImageWidth,
                ImageHeight    = viewSettings.ImageHeight,
                Rotation       = viewSettings.Rotation,
                ViewShiftX     = viewSettings.ShiftX,
                ViewShiftY     = viewSettings.ShiftY,
                Symmetry       = viewSettings.Symmetry,
                ViewZoom       = viewSettings.Zoom,
                Coefficients   = coefficients,
                Weights        = weights,
                Parameters     = parameters,
                VariationIds   = variationIds,
                FunctionColors = colors,
                BackColor      = viewSettings.BackColor,
                IsFinal        = isFinal
            };

            if (gradModel != null)
            {
                flameModel.GradientPack           = gradModel.Pack();
                flameModel.FunctionColorPositions = colorPositions;
            }

            return(flameModel);
        }