forked from mcallegari/qlcplus
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdevtool.js
153 lines (131 loc) · 4.04 KB
/
devtool.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
function init()
{
var w = document.getElementById("width");
var h = document.getElementById("height");
if (!w.value)
w.value = 15;
if (!h.value)
h.value = 15;
updateProperties();
updateStepCount();
writeCurrentStep();
}
function updateStepCount()
{
var w = document.getElementById("width");
var h = document.getElementById("height");
var stepCount = document.getElementById("stepcount");
var currentStep = document.getElementById("currentstep");
if (w && h && stepCount && currentStep)
{
stepCount.value = testAlgo.rgbMapStepCount(w.value, h.value);
currentStep.value = -1;
nextStep();
updateProperties();
}
else
{
alert("Width, Height or Result element not found!");
}
}
function updateProperties()
{
var apiVersion = document.getElementById("apiversion");
var name = document.getElementById("name");
var author = document.getElementById("author");
if (apiVersion)
apiVersion.value = testAlgo.apiVersion;
if (name)
name.value = testAlgo.name;
if (author)
author.value = testAlgo.author;
}
function nextStep()
{
var stepCount = document.getElementById("stepcount");
var currentStep = document.getElementById("currentstep");
if (stepCount && currentStep)
{
var steps = parseInt(stepCount.value);
var current = parseInt(currentStep.value);
var next;
if ((current + 1) < steps)
next = current + 1;
else
next = 0;
currentStep.value = next;
writeCurrentStep();
}
else
{
alert("stepcount or currentstep element not found!");
}
}
function previousStep()
{
var stepCount = document.getElementById("stepcount");
var currentStep = document.getElementById("currentstep");
if (stepcount && currentStep)
{
var steps = parseInt(stepCount.value);
var current = parseInt(currentStep.value);
var next;
if (current > 0)
next = current - 1;
else
next = steps - 1;
currentStep.value = next;
writeCurrentStep();
}
else
{
alert("stepcount or currentstep element not found!");
}
}
function writeCurrentStep()
{
var map = document.getElementById("map");
var w = document.getElementById("width");
var h = document.getElementById("height");
var currentStep = document.getElementById("currentstep");
var stepCount = document.getElementById("stepcount");
var bicolor = document.getElementById("bicolor");
var currentRgb = parseInt(document.getElementById("color1").value, 16);
if (bicolor.checked)
{
var stepCountMinusOne = parseInt(stepCount.value) - 1;
stepCountMinusOne = stepCountMinusOne == 0 ? 1 : stepCountMinusOne;
var currentR = ((stepCountMinusOne - parseInt(currentStep.value)) / stepCountMinusOne) * 255;
var currentG = 0;
var currentB = (parseInt(currentStep.value) / stepCountMinusOne) * 255;
currentRgb = (Math.round(currentR) * 256 * 256 + Math.round(currentG) * 256 + Math.round(currentB)).toString(16);
currentRgb = "000000".substr(0, 6 - currentRgb.length) + currentRgb;
}
if (w && h && map && currentStep)
{
var width = parseInt(w.value);
var height = parseInt(h.value);
var step = parseInt(currentStep.value);
for (var i = map.rows.length - 1; i >= 0; i--)
map.deleteRow(i);
var rgb = testAlgo.rgbMap(width, height, currentRgb, step);
for (var y = 0; y < height; y++)
{
var row = map.insertRow(y);
for (var x = 0; x < width; x++)
{
var cell = row.insertCell(x);
var rgbStr = rgb[y][x].toString(16);
while (rgbStr.length != 6)
rgbStr = "0" + rgbStr;
cell.style.backgroundColor = rgbStr;
cell.style.height = 20;
cell.style.width = 20;
}
}
}
else
{
alert("map element not found!");
}
}