Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
RandomSingleHue.cs
1using System;
2using SkiaSharp;
8
10{
21 {
27 {
28 }
29
34 : base(new ScriptNode[] { N, BandSize }, argumentTypes2Scalar, Start, Length, Expression)
35 {
36 }
37
42 : base(new ScriptNode[] { N, BandSize, Seed }, argumentTypes3Scalar, Start, Length, Expression)
43 {
44 }
45
53 {
54 int i = 0;
55 int c = Arguments.Length;
56 int N;
57 int BandSize;
58 int Seed;
59
60 if (i < c)
61 N = (int)Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
62 else
63 {
64 N = 1024;
65 Variables.ConsoleOut?.WriteLine("N = " + N.ToString(), Variables);
66 }
67
68 if (i < c)
69 BandSize = (int)Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
70 else
71 {
72 BandSize = 16;
73 Variables.ConsoleOut?.WriteLine("BandSize = " + BandSize.ToString(), Variables);
74 }
75
76 if (i < c)
77 Seed = (int)Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
78 else
79 {
80 lock (gen)
81 {
82 Seed = gen.Next();
83 }
84
85 Variables.ConsoleOut?.WriteLine("Seed = " + Seed.ToString(), Variables);
86 }
87
88 return new ObjectVector(CreatePalette(N, BandSize, Seed, this));
89 }
90
94 public override string[] DefaultArgumentNames
95 {
96 get
97 {
98 return new string[] { "N", "BandSize", "Seed" };
99 }
100 }
101
105 public static SKColor[] CreatePalette(int N, int BandSize, ScriptNode Node)
106 {
107 return CreatePalette(N, BandSize, null, Node);
108 }
109
113 public static SKColor[] CreatePalette(int N, int BandSize, int? Seed, ScriptNode Node)
114 {
115 if (N <= 0)
116 throw new ScriptRuntimeException("N in RandomSingleHue(N[,BandSize]) has to be positive.", Node);
117
118 if (BandSize <= 0)
119 throw new ScriptRuntimeException("BandSize in RandomSingleHue(N[,BandSize]) has to be positive.", Node);
120
121 SKColor[] Result = new SKColor[N];
122 double H, S, V;
123 Random Generator;
124 int i;
125
126 if (Seed.HasValue)
127 Generator = new Random(Seed.Value);
128 else
129 Generator = gen;
130
131 lock (Generator)
132 {
133 H = Generator.NextDouble() * 360;
134 S = 1.0;
135
136 i = 0;
137 while (i < N)
138 {
139 S = V = Math.Cos((2.0 * Math.PI * i) / BandSize + Math.PI / 2) * 0.5 + 0.5;
140 Result[i++] = Graph.ToColorHSV(H, S, V);
141 }
142 }
143
144 return Result;
145 }
146
147 private static readonly Random gen = new Random();
148
152 public override string FunctionName => nameof(RandomSingleHue);
153 }
154}
Class managing a script expression.
Definition: Expression.cs:39
static double ToDouble(object Object)
Converts an object to a double value.
Definition: Expression.cs:4824
Calculates a palette of random color from a single random hue, oscillating the value,...
override string[] DefaultArgumentNames
Default Argument names
RandomSingleHue(ScriptNode N, ScriptNode BandSize, int Start, int Length, Expression Expression)
TODO
static SKColor[] CreatePalette(int N, int BandSize, ScriptNode Node)
TODO
override IElement Evaluate(IElement[] Arguments, Variables Variables)
Evaluates the function.
RandomSingleHue(ScriptNode N, int Start, int Length, Expression Expression)
TODO
RandomSingleHue(ScriptNode N, ScriptNode BandSize, ScriptNode Seed, int Start, int Length, Expression Expression)
TODO
static SKColor[] CreatePalette(int N, int BandSize, int? Seed, ScriptNode Node)
TODO
Base class for graphs.
Definition: Graph.cs:79
static SKColor ToColorHSV(double H, double S, double V)
Creates a Color from its HSV representation.
Definition: Graph.cs:877
Base class for multivariate funcions.
ScriptNode[] Arguments
Function arguments.
static readonly ArgumentType[] argumentTypes2Scalar
Two scalar parameters.
static readonly ArgumentType[] argumentTypes3Scalar
Three scalar parameters.
static readonly ArgumentType[] argumentTypes1Scalar
One scalar parameter.
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:219
Basic interface for all types of elements.
Definition: IElement.cs:20