-
Notifications
You must be signed in to change notification settings - Fork 0
/
simplecurves.js
104 lines (90 loc) · 1.82 KB
/
simplecurves.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/////// Constants
var NO_TYPE = null;
var CONSTANT = 1;
var LINEAR = 2;
var QUADRATIC = 3;
var CUBIC = 4;
var QUARTIC = 5;
/////// Objects
var CurrentCurveStyle;
function SetCurveStyle(curvestyle)
{
CurrentCurveStyle = curvestyle;
}
function CurveStyle(accuracy)
{
this.Accuracy = accuracy;
}
CurrentCurveStyle = new CurveStyle(.1);
function GenerateCurve(a, b, c, d, e)
{
var type = NO_TYPE;
var Coefficients = 0; // used to determine what kind of function this is
if (typeof a !== "undefined")
{
Coefficients++;
if (typeof b !== "undefined")
{
Coefficients++;
if (typeof c !== "undefined")
{
Coefficients++;
if (typeof d !== "undefined")
{
Coefficients++;
if (typeof e !== "undefined")
{
Coefficients++;
}
}
}
}
}
if (Coefficients == 0)
{
return;
}
else
{
type = Coefficients;
}
var Curve = new DataObject();
Curve.Type = type;
Curve.Scale = CurrentCurveStyle.Accuracy;
var LeftBound = CurrentWindow.x_left;
var RightBound = CurrentWindow.x_right;
switch (type)
{
case CONSTANT:
for (var i = LeftBound; i <= RightBound; i += Curve.Scale)
{
Curve.Data.push(a);
}
break;
case LINEAR:
for (var i = LeftBound; i <= RightBound; i += Curve.Scale)
{
Curve.Data.push(a * i + b);
}
break;
case QUADRATIC:
for (var i = LeftBound; i <= RightBound; i += Curve.Scale)
{
Curve.Data.push( a * Math.pow(i, 2) + b * i + c );
}
break;
case CUBIC:
for (var i = LeftBound; i <= RightBound; i += Curve.Scale)
{
Curve.Data.push(a * Math.pow(i, 3) + b * Math.pow(i, 2) + c * i + d);
}
break;
case QUARTIC:
for (var i = LeftBound; i <= RightBound; i += Curve.Scale)
{
Curve.Data.push(a * Math.pow(i, 4) + b * Math.pow(i, 3) + c * Math.pow(i, 2) + d * i + e);
}
break;
}
return Curve;
}