Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
EstimateFlameSize.cs
1using SkiaSharp;
2using System;
11
13{
44 {
48 public EstimateFlameSize(ScriptNode N, ScriptNode FlameFunctions, ScriptNode DimX, ScriptNode DimY, ScriptNode Seed,
50 : base(new ScriptNode[] { N, FlameFunctions, DimX, DimY, Seed },
51 new ArgumentType[] { ArgumentType.Scalar, ArgumentType.Vector, ArgumentType.Scalar, ArgumentType.Scalar,
52 ArgumentType.Scalar }, Start, Length, Expression)
53 {
54 }
55
59 public EstimateFlameSize(ScriptNode N, ScriptNode FlameFunctions, ScriptNode DimX, ScriptNode DimY,
61 : base(new ScriptNode[] { N, FlameFunctions, DimX, DimY },
62 new ArgumentType[] { ArgumentType.Scalar, ArgumentType.Vector, ArgumentType.Scalar, ArgumentType.Scalar }, Start, Length, Expression)
63 {
64 }
65
70 : base(new ScriptNode[] { N, FlameFunctions, DimX },
71 new ArgumentType[] { ArgumentType.Scalar, ArgumentType.Vector, ArgumentType.Scalar }, Start, Length, Expression)
72 {
73 }
74
79 : base(new ScriptNode[] { N, FlameFunctions },
80 new ArgumentType[] { ArgumentType.Scalar, ArgumentType.Vector }, Start, Length, Expression)
81 {
82 }
83
87 public override string[] DefaultArgumentNames
88 {
89 get
90 {
91 return new string[]
92 {
93 "N", "FlameFunctions", "DimX", "DimY", "Seed"
94 };
95 }
96 }
97
101 public override string FunctionName => nameof(EstimateFlameSize);
102
107 {
108 long N;
109 int dimx, dimy;
110 int i, c;
111 int Seed;
112
113 i = 0;
114 c = Arguments.Length;
115 N = (long)Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
116 if (N <= 0)
117 throw new ScriptRuntimeException("N in calls to EstimateFlameSize() must be a positive integer.", this);
118
119 object Obj = Arguments[i++].AssociatedObjectValue;
120
121 if (!(Obj is Array FlameArray))
122 throw new ScriptRuntimeException("The second parameter to EstimateFlameSize must be an array, containing flame definitions.", this);
123
125 double Weight;
126 FlameFunction CurrentFunction = null;
127
128 foreach (object FlameItem in FlameArray)
129 {
130 if (FlameItem is DoubleMatrix M)
131 {
132 CurrentFunction = new FlameFunction(M, this);
133 FlameFunctions.Add(CurrentFunction);
134 }
135 else if (FlameItem is SKColor || FlameItem is string)
136 {
137 if (CurrentFunction is null)
138 {
139 M = new DoubleMatrix(new double[,] { { 1, 0 }, { 0, 1 } });
140 CurrentFunction = new FlameFunction(M, this);
141 FlameFunctions.Add(CurrentFunction);
142 }
143
144 SKColor cl = Graph.ToColor(FlameItem);
145 cl.ToHsl(out float H, out float S, out float L);
146
147 CurrentFunction.SetColorHsl(H, S, L);
148 CurrentFunction = null;
149 }
150 else if (FlameItem is IFlameVariation Var)
151 {
152 if (CurrentFunction is null)
153 {
154 M = new DoubleMatrix(new double[,] { { 1, 0 }, { 0, 1 } });
155 CurrentFunction = new FlameFunction(M, this);
156 FlameFunctions.Add(CurrentFunction);
157 }
158
159 CurrentFunction.Add(Var);
160 }
161 else if (FlameItem is ILambdaExpression Lambda)
162 {
163 if (CurrentFunction is null)
164 {
165 M = new DoubleMatrix(new double[,] { { 1, 0 }, { 0, 1 } });
166 CurrentFunction = new FlameFunction(M, this);
167 FlameFunctions.Add(CurrentFunction);
168 }
169
170 CurrentFunction.Add(Lambda);
171 }
172 else
173 {
174 try
175 {
176 Weight = Expression.ToDouble(FlameItem);
177
178 if (CurrentFunction is null)
179 {
180 M = new DoubleMatrix(new double[,] { { 1, 0 }, { 0, 1 } });
181 CurrentFunction = new FlameFunction(M, this);
182 FlameFunctions.Add(CurrentFunction);
183 }
184
185 CurrentFunction.SetWeight(Weight);
186 }
187 catch (Exception)
188 {
189 throw new ScriptRuntimeException("Invalid flame variation definition.", this);
190 }
191 }
192 }
193
194 if (i < c)
195 dimx = (int)Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
196 else
197 dimx = 320;
198
199 if (i < c)
200 dimy = (int)Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
201 else
202 dimy = 200;
203
204 if (i < c)
205 Seed = (int)Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
206 else
207 {
208 lock (gen)
209 {
210 Seed = gen.Next();
211 }
212
213 Variables.ConsoleOut?.WriteLine("Seed = " + Seed.ToString(), Variables);
214 }
215
216 if (i < c)
217 {
218 throw new ScriptRuntimeException("Parameter mismatch in call to EstimateFlameSize(N,FlameFunctions[dimx[,dimy[,Seed]]]).",
219 this);
220 }
221
222 if (dimx <= 0 || dimx > 5000 || dimy <= 0 || dimy > 5000)
223 throw new FractalImageSizeScriptException(this);
224
225 FlameFunction[] Functions = FlameFunctions.ToArray();
226
227 FlameFractalRgba.EstimateSize(out double xc, out double yc, out double dr, Functions, dimx, dimy, Seed, N, Variables, this);
228
229 return new DoubleVector(xc, yc, dr);
230 }
231
232 private static readonly Random gen = new Random();
233
234 }
235}
A chunked list is a linked list of chunks of objects of type T .
Definition: ChunkedList.cs:54
Class managing a script expression.
Definition: Expression.cs:41
static double ToDouble(object Object)
Converts an object to a double value.
Definition: Expression.cs:5110
Exception thrown if an image with invalid size is requested.
Estimates the size of a flame fractal.
EstimateFlameSize(ScriptNode N, ScriptNode FlameFunctions, ScriptNode DimX, int Start, int Length, Expression Expression)
TODO
EstimateFlameSize(ScriptNode N, ScriptNode FlameFunctions, ScriptNode DimX, ScriptNode DimY, ScriptNode Seed, int Start, int Length, Expression Expression)
TODO
override IElement Evaluate(IElement[] Arguments, Variables Variables)
TODO
EstimateFlameSize(ScriptNode N, ScriptNode FlameFunctions, ScriptNode DimX, ScriptNode DimY, int Start, int Length, Expression Expression)
TODO
EstimateFlameSize(ScriptNode N, ScriptNode FlameFunctions, int Start, int Length, Expression Expression)
TODO
Calculates a flame fractal in RGBA space. Intensity is calculated along the A-axis....
static void EstimateSize(out double xCenter, out double yCenter, out double rDelta, FlameFunction[] Functions, int Width, int Height, int Seed, long N, Variables Variables, ScriptNode Node)
TODO
Base class for graphs.
Definition: Graph.cs:88
static SKColor ToColor(object Object)
Converts an object to a color.
Definition: Graph.cs:844
Base class for multivariate funcions.
ScriptNode[] Arguments
Function arguments.
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
int Length
Length of expression covered by node.
Definition: ScriptNode.cs:101
Expression Expression
Expression of which the node is a part.
Definition: ScriptNode.cs:177
int Start
Start position in script expression.
Definition: ScriptNode.cs:92
Collection of variables.
Definition: Variables.cs:25
TextWriter ConsoleOut
Console out interface. Can be used by functions and script to output data to the console.
Definition: Variables.cs:223
Basic interface for all types of elements.
Definition: IElement.cs:21
Base interface for lambda expressions.
ArgumentType
Type of parameter used in a function definition or a lambda definition.
Definition: IFunction.cs:9