This repository has been archived by the owner on Mar 26, 2022. It is now read-only.
forked from lovre/stroboskop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskripta.js
68 lines (54 loc) · 1.85 KB
/
skripta.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
window.addEventListener('load', function() {
//stran nalozena
//Dodaj novo barvo
var dodajBarvo = function(event) {
var input = document.createElement('button');
var picker = new jscolor(input);
picker.fromRGB(Math.floor(Math.random()*255), Math.floor(Math.random()*255), Math.floor(Math.random()*255))
document.getElementById("barve").appendChild(input);
}
document.querySelector("#novaBarva")
.addEventListener('click', dodajBarvo);
//Odstrani barve
document.getElementById('odstraniBarve').addEventListener('click', function() {
document.getElementById('barve').innerHTML = "";
});
//Stroboskop
var vrednosti = [];
var minCas = 0;
var maxCas = 0;
var ustavi = false;
var spremeniBarvo = function(id) {
document.getElementById("stroboskop").style.backgroundColor = "#"+vrednosti[id];
if (ustavi) {
ustavi = false;
} else {
novId = (id+1) % vrednosti.length;
timeout = Math.floor((Math.random() * (maxCas-minCas)) + minCas);
setTimeout(function() {spremeniBarvo(novId)} , timeout);
}
}
var stop = function(event) {
ustavi = true;
var start = document.querySelector("#start");
start.innerHTML = "Zaženi stroboskop";
start.removeEventListener('click', stop);
start.addEventListener('click', zagon);
}
var zagon = function(event) {
vrednosti = [];
var barve = document.querySelectorAll("#barve > button");
for (i = 0; i < barve.length; i++) {
var barva = barve[i];
vrednosti.push(barva.innerHTML);
}
minCas = document.getElementById('min').value;
maxCas = document.getElementById('max').value;
spremeniBarvo(0);
var start = document.querySelector("#start");
start.innerHTML = "Ustavi stroboskop";
start.removeEventListener('click', zagon);
start.addEventListener('click', stop);
}
document.querySelector("#start").addEventListener('click', zagon);
});