public override void Execute(ExecutionContext context) { SprakNumber input = context.Memory.GetVariable <SprakNumber>(TargetName); SprakNumber output = new SprakNumber(input.Value - 1); context.Memory.SetVariable(TargetName, output); }
public override void Execute(ExecutionContext context) { SprakArray array = context.Memory.GetVariable <SprakArray>(TargetName); SprakNumber count = new SprakNumber(array.Value.Count); context.Memory.PushValue(count); }
public override void Execute(ExecutionContext context) { SprakNumber index = context.Memory.PopValue <SprakNumber>(); SprakArray array = context.Memory.PopValue <SprakArray>(); Value result = array.Value[(int)index.Value]; context.Memory.PushValue(result); }
public override void Execute(ExecutionContext context) { // Remember, latest first on a stack SprakNumber second = context.Memory.PopValue <SprakNumber>(); SprakNumber first = context.Memory.PopValue <SprakNumber>(); SprakBoolean result = SprakBoolean.From(first.Value > second.Value); context.Memory.PushValue(result); }
public override void Execute(ExecutionContext context) { SprakNumber index = context.Memory.PopValue <SprakNumber>(); Value value = context.Memory.PopValue(); SprakArray array = context.Memory .GetVariable <SprakArray>(VariableName); array.Value[(int)index.Value] = value; }
public static SprakUnit Color( ExecutionContext context, SprakNumber r, SprakNumber g, SprakNumber b) { context.Computer?.Screen.SetColor(new Color( r.Value, g.Value, b.Value )); return(SprakUnit.Value); }
public static SprakNumber Decrement(SprakNumber left) { return(new SprakNumber(left.Value - 1)); }
public static SprakNumber Divide(SprakNumber left, SprakNumber right) { return(new SprakNumber(left.Value / right.Value)); }
public static SprakNumber Multiply(SprakNumber left, SprakNumber right) { return(new SprakNumber(left.Value * right.Value)); }
public static SprakNumber Subtract(SprakNumber left, SprakNumber right) { return(new SprakNumber(left.Value - right.Value)); }
public static SprakNumber Add(SprakNumber left, SprakNumber right) { return(new SprakNumber(left.Value + right.Value)); }
public static SprakBoolean LessThanOrEquals(SprakNumber left, SprakNumber right) { return(SprakBoolean.From(left.Value <= right.Value)); }
public static SprakUnit Rect(ExecutionContext context, SprakNumber x, SprakNumber y, SprakNumber w, SprakNumber h) { context.Computer.Screen?.Rect(x.Value, y.Value, w.Value, h.Value); return(SprakUnit.Value); }
public static SprakNumber Min(SprakNumber a, SprakNumber b) { return(new SprakNumber(Math.Min(a.Value, b.Value))); }
public static SprakNumber Add(SprakNumber right) { return(new SprakNumber(-right.Value)); }
// T public static SprakUnit Text(ExecutionContext context, SprakNumber x, SprakNumber y, SprakString text) { context.Computer.Screen?.Text(text.Value, x.Value, y.Value); return(SprakUnit.Value); }
public static SprakNumber Sqrt(SprakNumber a) { return(new SprakNumber(Math.Sqrt(a.Value))); }
public static SprakUnit Sleep(SprakNumber seconds) { System.Threading.Thread.Sleep((int)(seconds.Value * 1000)); return(SprakUnit.Value); }
// S public static SprakNumber Sin(SprakNumber radians) { return(new SprakNumber(Math.Sin(radians.Value))); }
public static SprakNumber Round(SprakNumber a) { return(new SprakNumber(Math.Round(a.Value))); }
public static SprakArray RGBToHSV( SprakNumber r, SprakNumber g, SprakNumber b) { // Note: all colours in sprak are normalized to [0, 1] double R = r.Value; double G = g.Value; double B = b.Value; double V = Math.Max(Math.Max(R, G), B); double C = V - Math.Min(Math.Min(R, G), B); double H; // Remember that V is max(R, G, B), and so should be // exactly R or G or B. (i.e. no need to worry about // floating point tolerance or an else case) if (C == 0) { H = 0; } else if (V == R) { H = 60 * ((G - B) / C); } else if (V == G) { H = 60 * (2 + ((B - R) / C)); } else if (V == B) { H = 60 * (4 + ((R - G) / C)); } else { // This should never happen. H = 0; } double S; if (V == 0) { S = 0; } else { S = C / V; } H = (H % 360) / 360; S = Math.Clamp(S, 0, 1); V = Math.Clamp(V, 0, 1); SprakNumber h = new SprakNumber(H); SprakNumber s = new SprakNumber(S); SprakNumber v = new SprakNumber(V); return(new SprakArray(new List <Value>() { h, s, v })); }
// L public static SprakUnit Line(ExecutionContext context, SprakNumber x1, SprakNumber y1, SprakNumber x2, SprakNumber y2) { context.Computer.Screen?.Line(x1.Value, y1.Value, x2.Value, y2.Value); return(SprakUnit.Value); }
public static SprakBoolean GreaterThanOrEquals(SprakNumber left, SprakNumber right) { return(SprakBoolean.From(left.Value >= right.Value)); }
public static SprakNumber Cos(SprakNumber radians) { return(new SprakNumber(Math.Cos(radians.Value))); }
// P public static SprakNumber Pow(SprakNumber a, SprakNumber b) { return(new SprakNumber(Math.Pow(a.Value, b.Value))); }
public static SprakBoolean NotEqual(SprakNumber left, SprakNumber right) { return(SprakBoolean.From(left != right)); }
public static SprakArray HSVToRGB( SprakNumber h, SprakNumber s, SprakNumber v) { // All sprak color values are in [0, 1] double H = h.Value * 360; double S = s.Value; double V = v.Value; double C = V * S; double Hn = H / 60; double X = C * (1 - Math.Abs((Hn % 2) - 1)); double R, G, B; if (Hn < 1) { R = C; G = X; B = 0; } else if (Hn < 2) { R = X; G = C; B = 0; } else if (Hn < 3) { R = 0; G = C; B = X; } else if (Hn < 4) { R = 0; G = X; B = C; } else if (Hn < 5) { R = X; G = 0; B = C; } else if (Hn < 6) { R = C; G = 0; B = X; } else { // I'm not sure if this else case // is possible. R = 0; G = 0; B = 0; } double m = V - C; R += m; G += m; B += m; R = Math.Clamp(R, 0, 1); G = Math.Clamp(G, 0, 1); B = Math.Clamp(B, 0, 1); SprakNumber r = new SprakNumber(R); SprakNumber g = new SprakNumber(G); SprakNumber b = new SprakNumber(B); return(new SprakArray(new List <Value>() { r, g, b })); }