diff --git a/README.md b/README.md
index 333efba..5ea8207 100644
--- a/README.md
+++ b/README.md
@@ -19,35 +19,28 @@ On the basis of these three inputs, it simulates conic or linear view for given
Random Disco Light Simulator
- 1. Number of Colors:
+ 1. Number of Colors:
- 2. Time interval ('in milliseconds' ), with which the color changes
- randomly:
+ 2. Time interval (with which the color changes
+ randomly) :
+
+ Unit
+ milliseconds
+ seconds
+
[Negative interval or no input will be treated as 0 interval]
- 3. View:
+ 3. View:
Select
Conic
diff --git a/script.js b/script.js
index 1fa7222..d776f5b 100644
--- a/script.js
+++ b/script.js
@@ -15,6 +15,7 @@ function run() {
let n = document.getElementById("color").value
let set_time = document.getElementById("time").value
+ let unit = document.getElementById("unit").value
let view = document.getElementById("view").value
if (Number(n) < 0) {
@@ -35,16 +36,21 @@ function run() {
}
+ else if (unit == "unit") {
+ document.getElementById("error").innerText = "Please select 'Unit'!"
+ document.getElementById("error").style.color = "red"
+ }
+
else if (view == "select") {
document.getElementById("error").innerText = "Please select 'View'!"
document.getElementById("error").style.color = "red"
}
else {
- document.body.children[0].style.display = 'none';
-
alert("Double click on the screen to reload!")
+ document.body.children[0].style.display = 'none';
+
document.body.style.cursor = "pointer";
document.body.addEventListener("dblclick", () => {
@@ -55,53 +61,60 @@ function run() {
})
}
- function number(n) {
- let ch = `${getRandomColor()}, `;
- if (n == parseInt(n)) {
- while (n >= 2) {
- ch += `${getRandomColor()}, `;
- n = n - 1;
- }
- return ch;
+ if (unit != "unit") {
+
+ if (unit == "seconds") {
+ set_time *= 1000;
}
- }
- setInterval(() => {
- random_color = `${getRandomColor()}`;
- }, `${set_time}`);
+ function number(n) {
+ let ch = `${getRandomColor()}, `;
+ if (n == parseInt(n)) {
+ while (n >= 2) {
+ ch += `${getRandomColor()}, `;
+ n = n - 1;
+ }
+ return ch;
+ }
+ }
- if (n == 1 && view != "select") {
- document.body.style.backgroundColor = `${getRandomColor()}`
setInterval(() => {
- document.body.style.backgroundColor = `${getRandomColor()}`
+ random_color = `${getRandomColor()}`;
}, `${set_time}`);
- }
- else if (n > 1) {
+ if (n == 1 && view != "select") {
+ document.body.style.backgroundColor = `${getRandomColor()}`
+ setInterval(() => {
+ document.body.style.backgroundColor = `${getRandomColor()}`
+ }, `${set_time}`);
+ }
- if (view == "conic") {
+ else if (n > 1) {
+
+ if (view == "conic") {
- document.body.style.background = `conic-gradient(${random_color}, ${number(n - 1)} ${random_color})`;
- setInterval(() => {
document.body.style.background = `conic-gradient(${random_color}, ${number(n - 1)} ${random_color})`;
- }, `${set_time}`);
+ setInterval(() => {
+ document.body.style.background = `conic-gradient(${random_color}, ${number(n - 1)} ${random_color})`;
+ }, `${set_time}`);
- }
- else if (view == "linear") {
+ }
+ else if (view == "linear") {
- document.body.style.background = `linear-gradient(${number(n - 1)} ${random_color})`;
- setInterval(() => {
document.body.style.background = `linear-gradient(${number(n - 1)} ${random_color})`;
- }, `${set_time}`);
+ setInterval(() => {
+ document.body.style.background = `linear-gradient(${number(n - 1)} ${random_color})`;
+ }, `${set_time}`);
- }
- else if (view == "radial") {
+ }
+ else if (view == "radial") {
- document.body.style.background = `radial-gradient(${number(n - 1)} ${random_color})`;
- setInterval(() => {
document.body.style.background = `radial-gradient(${number(n - 1)} ${random_color})`;
- }, `${set_time}`);
+ setInterval(() => {
+ document.body.style.background = `radial-gradient(${number(n - 1)} ${random_color})`;
+ }, `${set_time}`);
+ }
}
}
diff --git a/style.css b/style.css
index edd5395..7408a9d 100644
--- a/style.css
+++ b/style.css
@@ -26,7 +26,8 @@ h1 {
box-shadow: 0px 0px 15px 10px black;
}
-#view {
+#view,
+#unit {
text-align: center;
border-radius: 10px;
}