1using System.Collections.Generic;
19 private readonly
IElement[] complexParameters;
20 private readonly
IElement[] doubleParameters;
21 private readonly
double[] homogeneousTransform;
25 private double[] variationWeights;
26 private double[] variation2Weights;
27 private bool[] variation2IsReal;
28 private readonly List<IFlameVariation> variationsList =
new List<IFlameVariation>();
29 private readonly List<ILambdaExpression> variations2List =
new List<ILambdaExpression>();
30 private readonly List<double> variationsWeightList =
new List<double>();
31 private readonly List<double> variations2WeightList =
new List<double>();
32 private readonly List<bool> isReal =
new List<bool>();
33 private SKColor color = SKColors.Red;
34 private double weight = 1.0;
35 private int nrVariations = 0;
36 private int nrVariations2 = 0;
37 private object lastVariation =
null;
38 private double red = 1.0;
39 private double green = 0.0;
40 private double blue = 0.0;
41 private readonly
bool hasProjection;
42 private bool hasVariations;
43 private bool isTransparent =
false;
52 this.homogeneousTransform =
new double[9];
57 this.doubleParameters =
new IElement[] { xv, yv };
58 this.complexParameters =
new IElement[] { zv };
62 this.homogeneousTransform[0] = (double)E[0, 0];
63 this.homogeneousTransform[1] = (double)E[0, 1];
64 this.homogeneousTransform[2] = 0;
65 this.homogeneousTransform[3] = (double)E[1, 0];
66 this.homogeneousTransform[4] = (double)E[1, 1];
67 this.homogeneousTransform[5] = 0;
68 this.homogeneousTransform[6] = 0;
69 this.homogeneousTransform[7] = 0;
70 this.homogeneousTransform[8] = 1;
71 this.hasProjection =
false;
75 this.homogeneousTransform[0] = (double)E[0, 0];
76 this.homogeneousTransform[1] = (double)E[0, 1];
77 this.homogeneousTransform[2] = (double)E[0, 2];
78 this.homogeneousTransform[3] = (double)E[1, 0];
79 this.homogeneousTransform[4] = (double)E[1, 1];
80 this.homogeneousTransform[5] = (double)E[1, 2];
81 this.homogeneousTransform[6] = (double)E[2, 0];
82 this.homogeneousTransform[7] = (double)E[2, 1];
83 this.homogeneousTransform[8] = (double)E[2, 2];
85 this.hasProjection = this.homogeneousTransform[6] != 0 ||
86 this.homogeneousTransform[7] != 0 ||
87 this.homogeneousTransform[8] != 1;
90 throw new ScriptRuntimeException(
"Linear transformation must be a 2D or homogeneous 2D transformation.", Node);
98 this.variationsList.Add(Variation);
99 this.variationsWeightList.Add(1);
100 this.lastVariation = Variation;
111 this.isReal.Add(
false);
115 this.isReal.Add(
true);
119 throw new ScriptRuntimeException(
"Only lambda expressions taking 2 real-valued parmeters or 1 complex-valued parameter are allowed.", this.node);
122 this.variations2List.Add(Variation);
123 this.variations2WeightList.Add(1);
124 this.lastVariation = Variation;
133 this.variationsWeightList[this.variationsWeightList.Count - 1] =
Weight;
136 this.variations2WeightList[this.variations2WeightList.Count - 1] =
Weight;
148 this.red = this.color.Red / 255.0;
149 this.green = this.color.Green / 255.0;
150 this.blue = this.color.Blue / 255.0;
151 this.isTransparent = (this.color.Alpha == 0);
159 this.color = SKColors.Black;
160 this.red = H / 360.0;
161 this.green = S / 100.0;
162 this.blue = L / 100.0;
163 this.isTransparent =
false;
166 internal void DefinitionDone()
168 this.variations = this.variationsList.ToArray();
169 this.variationWeights = this.variationsWeightList.ToArray();
170 this.nrVariations = this.variations.Length;
172 this.variations2 = this.variations2List.ToArray();
173 this.variation2Weights = this.variations2WeightList.ToArray();
174 this.nrVariations2 = this.variation2Weights.Length;
175 this.variation2IsReal = this.isReal.ToArray();
177 this.hasVariations = this.nrVariations > 0 || this.nrVariations2 > 0;
179 int c = this.variations.Length;
182 for (i = 0; i < c; i++)
183 this.variations[i].Initialize(this.homogeneousTransform, this.variationWeights[i]);
196 double x2 = this.homogeneousTransform[0] * x +
197 this.homogeneousTransform[1] * y +
198 this.homogeneousTransform[2];
200 double y2 = this.homogeneousTransform[3] * x +
201 this.homogeneousTransform[4] * y +
202 this.homogeneousTransform[5];
204 if (this.hasProjection)
206 double p = this.homogeneousTransform[6] * x +
207 this.homogeneousTransform[7] * y +
208 this.homogeneousTransform[6];
217 if (this.hasVariations)
224 if (this.nrVariations > 0)
226 for (i = 0; i < this.nrVariations; i++)
231 this.variations[i].
Operate(ref x, ref y);
232 w = this.variationWeights[i];
239 if (this.nrVariations2 > 0)
241 for (i = 0; i < this.nrVariations2; i++)
243 w = this.variation2Weights[i];
245 if (this.variation2IsReal[i])
252 if (!(Result is
IVector V) || V.Dimension != 2)
253 throw new ScriptRuntimeException(
"Real-valued lambda expressions must return a vector containing 2 real-valued numbers.", this.node);
260 this.zv.Value =
new Complex(x2, y2);
264 y3 += w * z.Imaginary;
278 if (!this.isTransparent)
280 switch (point.ColorMode)
283 point.red = (point.red + this.red) * 0.5;
284 point.green = (point.green + this.green) * 0.5;
285 point.blue = (point.blue + this.blue) * 0.5;
291 if (this.red < point.red)
293 d = point.red - this.red;
295 point.red -= d * 0.5;
299 point.red += d * 0.5;
306 d = this.red - point.red;
308 point.red += d * 0.5;
312 point.red -= d * 0.5;
318 point.green = (point.green + this.green) * 0.5;
319 point.blue = (point.blue + this.blue) * 0.5;
Script runtime exception.
Class managing a script expression.
static Complex ToComplex(object Object)
Converts an object to a complex value.
static double ToDouble(object Object)
Converts an object to a double value.
void Add(ILambdaExpression Variation)
TODO
FlameFunction(DoubleMatrix M, ScriptNode Node)
TODO
void SetColor(SKColor Color)
TODO
void Add(IFlameVariation Variation)
TODO
void SetWeight(double Weight)
TODO
void SetColorHsl(double H, double S, double L)
TODO
Base class for all nodes in a parsed script tree.
double[,] Values
Matrix element values.
int Columns
Number of columns.
Basic interface for all types of elements.
Basic interface for vectors.
void Operate(ref double x, ref double y)
TODO
Base interface for lambda expressions.
IElement Evaluate(IElement[] Arguments, Variables Variables)
Evaluates the lambda expression.
int NrArguments
Number of arguments.