-
Notifications
You must be signed in to change notification settings - Fork 0
/
script_animation.js
96 lines (79 loc) · 2.5 KB
/
script_animation.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
var tables = document.querySelectorAll('tbody');
var table;
for(let i = 0; i < tables.length; i++) {
let ta = tables[i];
if(ta.querySelectorAll('tr').length > 10) {
table = ta;
}
}
var trs = table.querySelectorAll(':scope > tr');
var gradeTables = [];
for(let i = 0; i < trs.length; i++) {
let tr = trs[i];
if(tr.id) continue;
if(tr.className != 'line0' && tr.className != 'line1') continue;
gradeTables.push(tr);
}
var final = [];
for(let i = 0; i < gradeTables.length; i++) {
let gTable = gradeTables[i];
let trs = gTable.querySelectorAll(':scope > td');
trs[2].innerHTML = ''; trs[5].innerHTML = '';
final.push([trs[2], trs[5]]);
}
console.log('[+] wszystko git, rysowanko!');
/* drawing */
const gradeTemplate = '<span class="grade-box" style="background-color:{COLOR};"><a class="ocena">{GRADE}</a></span>';
function add(grade, color) {
return gradeTemplate.replace('{COLOR}', color).replace('{GRADE}', grade);
}
function grayScale(color) {
return 0.299*color[0] + 0.587*color[1] + 0.114*color[2];
}
function clr() {
for(let i = 0; i < final.length; i++) {
final[i][0].innerHTML = '';
final[i][1].innerHTML = '';
}
}
// const: width, height, fps - added later by python
var i = 0;
var lastDraw = 0;
var drawingStarted = 0;
var frames = [];
function draw() {
if(frames.length < fps*2) {
fetch(`http://127.0.0.1:5000?index=${i}&count=${fps*3}`).then(res => res.json()).then(json => {
if(json['end']) {
console.log('[+] zakonczono sukcesem!');
return;
}
json.forEach((frame) => {
frames.push(frame);
});
requestAnimationFrame(draw);
});
return;
}
const diff = new Date().getTime() - drawingStarted;
if(diff < (1000/fps)*i) {
requestAnimationFrame(draw); return;
}
console.log('[*] rysowanie klatki', i, 'delta t', new Date().getTime() - lastDraw, '/', Math.round(100/fps)*10, 'offset', Math.round(1000/fps)*i - diff);
lastDraw = new Date().getTime();
var current = frames[0];
frames.shift();
var frameI = 0;
clr();
for(let y = 0; y < height; y++) {
var toAdd = '';
for(let x = 0; x < width; x++) {
toAdd += add(Math.floor(3+grayScale(current[frameI])/80), 'rgb('+current[frameI]+')');
frameI++;
}
final[y][0].innerHTML = toAdd;
}
i++;
requestAnimationFrame(draw);
}
// python-generated code starts here...