Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
removed unnecessary comments
  • Loading branch information
sk66641 committed May 24, 2024
1 parent fecebf0 commit 577756f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 90 deletions.
9 changes: 0 additions & 9 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ <h1>Random Disco Light Simulator</h1>
<option style="background-color: lightslategray; color: white;" value="select">Select</option>
<option value="conic">Conic</option>
<option value="linear">Linear</option>

</select>
</div>
<div class="button">
Expand All @@ -37,14 +36,6 @@ <h1>Random Disco Light Simulator</h1>
</div>
<div id="error"></div>
</div>
<!-- <div class="connect">
<a href="https://www.linkedin.com/in/sanu-kumar-2a9492283/" target="_blank"> <img class="img1" height="50px"
width="50px" src="linkedin.png" alt="linkedin">
</a>
<a href="https://github.com//sk66641" target="_blank"> <img class="img2" style="border-radius: 5px;"
height="50px" width="50px" src="github.jpeg" alt="github">
</a>
</div> -->
</div>
<script src="script.js"></script>

Expand Down
86 changes: 5 additions & 81 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ function run() {
function getRandomColor() {

// range of Math.random(): [0,1)
// Generating random nubmers for [a, b]: parseInt(a + Math.random()*(b+1-a))
// Generating random integers for [a, b]: parseInt(a + Math.random()*(b+1-a))
let val1 = parseInt(0 + Math.random() * (255 + 1 - 0));
let val2 = parseInt(0 + Math.random() * (255 + 1 - 0));
let val3 = parseInt(0 + Math.random() * (255 + 1 - 0));
Expand All @@ -13,37 +13,6 @@ function run() {

let random_color = `${getRandomColor()}`;

/* do {
var view = prompt("1:) To choose gradient between conic & linear, view: \n -> 'c' or 'C' for conic \n -> 'l' or 'L' for linear");
if (view != 'c' && view != 'l' && view != 'C' && view != 'L') {
alert("Please enter 'c' or 'C' for conic or 'l' or 'L' for linear");
}
} while (view != 'c' && view != 'l' && view != 'C' && view != 'L');
do {
var set_time = Number(prompt("2:) Set the time interval (in 'milliseconds') with which the color changes randomly:\n(Negative interval or no input will be treated as 0 interval)"));
if (isNaN(set_time)) {
alert("Please enter a valid time interval");
}
} while (isNaN(set_time));
do {
var n = Number(prompt("3:) Enter number of random colors:"));
if (isNaN(n) || n < 1 || Number.isInteger(n) == false) {
alert("Please enter a positive integer greater than or equal to '1'");
}
} while (isNaN(n) || n < 1 || Number.isInteger(n) == false); */

var color = document.getElementById("color")
var time = document.getElementById("time")
var _view = document.getElementById("view")
Expand All @@ -52,14 +21,11 @@ function run() {
var set_time = time.value
var view = _view.value

console.log(Number.isInteger(n))
if (n < 0) {


document.getElementById("error").innerText = "Please enter a positive integer in 'Number of Colors'!"
document.getElementById("error").style.color = "red"

}

else if (Number.isInteger(n) == false || n == "") {
if (n == "") {

Expand All @@ -72,71 +38,40 @@ function run() {
}

}

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.style.cursor = "pointer";
document.body.addEventListener("dblclick", () => {
let cnf1 = confirm("Are you sure you want to reload?");
if (cnf1) {

window.location.reload();
}
})
}

// color.addEventListener("change", ()=>{
// // set_time = time.value
// // view = _view.value
// n = color.value
// run()
// })
// time.addEventListener("change", ()=>{
// // n = color.value
// // view = _view.value
// set_time = time.value
// run()
// })
// _view.addEventListener("change", ()=>{
// // n = color.value
// // alert("warning")
// // set_time = time.value
// view = _view.value
// run()
// })

// let n = Number(prompt("1:) Enter the number of random colors:"));
// let set_time = Number(prompt("2:) Set the time interval (in 'milliseconds') with which the color changes randomly:\n(Negative interval or no input will be treated as 0 interval)"));
// let view = prompt("3:) To choose gradient between conic & linear, Enter: \n -> 'c' or 'C' for conic \n -> 'l' or 'L' for linear");
// alert("𝘙𝘢𝘯𝘥𝘰𝘮 𝘋𝘪𝘴𝘤𝘰 𝘓𝘪𝘨𝘩𝘵 𝘚𝘪𝘮𝘶𝘭𝘢𝘵𝘰𝘳 (𝘸𝘪𝘵𝘩 💖 𝘣𝘺 '𝘬𝘶𝘮𝘢𝘳 𝘴𝘢𝘯𝘶')");


function number(n) {

var ch = `${getRandomColor()}, `;

if (n == parseInt(n)) {

while (n >= 2) {
ch += `${getRandomColor()}, `;
n = n - 1;
}

return ch;
}

}

setInterval(() => {
random_color = `${getRandomColor()}`;
}, `${set_time}`);

if (n == 1) {

document.body.style.backgroundColor = `${getRandomColor()}`
setInterval(() => {
document.body.style.backgroundColor = `${getRandomColor()}`
Expand All @@ -149,29 +84,18 @@ function run() {

document.body.style.background = `conic-gradient(${random_color}, ${number(n - 1)} ${random_color})`;
setInterval(() => {
// document.body.style.backgroundColor = `${getRandomColor()}`
document.body.style.background = `conic-gradient(${random_color}, ${number(n - 1)} ${random_color})`;
}, `${set_time}`);

}
else if (view == "l" || view == "L" || view == "linear" || view == "Linear") {

document.body.style.background = `linear-gradient(${number(n - 1)} ${random_color})`;
console.log(set_time)
setInterval(() => {
// document.body.style.backgroundColor = `${getRandomColor()}`

document.body.style.background = `linear-gradient(${number(n - 1)} ${random_color})`;
}, `${set_time}`);

}
}

}
// document.addEventListener("keydown", (event) => {
// if (event.key == "Enter") {
// run();
// }
// })
// issue: each time i press enter, speed increases
// try: should try again after adding feature which resets values
}

0 comments on commit 577756f

Please sign in to comment.