Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
sk66641 committed May 23, 2024
1 parent beb5f14 commit 67d2696
Show file tree
Hide file tree
Showing 6 changed files with 332 additions and 68 deletions.
Binary file added github.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,43 @@
</head>

<body>
<div class="container">
<div class="box">
<h1>Random Disco Light Simulator</h1>
<div>
<label>1. Number of Colors:</label>
<input type="number" id="color" placeholder="Enter">
</div>
<div>
<label>2. Time interval (<em>'in milliseconds'</em>), <br>with which the color changes
randomly:</label><br>
<input type="number" id="time" placeholder="Enter">
<br><strong>[Negative interval or no input will be treated as 0 interval]</strong>
</div>
<div>
<label>3. View:</label>
<select id="view">
<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">
<button id="submit" onclick="run()">Submit</button>
<button id="reset" onclick="window.location.reload()">Reset</button>
</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>

</body>
Expand Down
Empty file added j.js
Empty file.
Binary file added linkedin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
211 changes: 145 additions & 66 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,98 +1,177 @@
function getRandomColor() {
function run() {

// range of Math.random(): [0,1)
// Generating random nubmers 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));
return `rgb(${val1}, ${val2}, ${val3})`;
function getRandomColor() {

}

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");
// range of Math.random(): [0,1)
// Generating random nubmers 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));
return `rgb(${val1}, ${val2}, ${val3})`;

}

} while (view != 'c' && view != 'l' && view != 'C' && view != 'L');
let random_color = `${getRandomColor()}`;

do {
/* 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 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)"));
var color = document.getElementById("color")
var time = document.getElementById("time")
var _view = document.getElementById("view")

if (isNaN(set_time)) {
alert("Please enter a valid time interval");
}
var n = Number(color.value)
var set_time = time.value
var view = _view.value

} while (isNaN(set_time));
console.log(Number.isInteger(n))
if (n < 0) {

do {

var n = Number(prompt("3:) Enter number of random colors:"));
document.getElementById("error").innerText = "Please enter a positive integer in 'Number of Colors'!"
document.getElementById("error").style.color = "red"

if (isNaN(n) || n < 1 || Number.isInteger(n) == false) {
alert("Please enter a positive integer greater than or equal to '1'");
}
else if (Number.isInteger(n) == false || n == "") {
if (n == "") {

} while (isNaN(n) || n < 1 || Number.isInteger(n) == false); */

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()}, `;
document.getElementById("error").innerText = "Please enter 'Number of Colors'!"
document.getElementById("error").style.color = "red"
}
else if (Number.isInteger(n) == false) {
document.getElementById("error").innerText = "Please enter a positive integer in 'Number of Colors'!"
document.getElementById("error").style.color = "red"
}

if (n == parseInt(n)) {
}
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();
}
})
}

while (n >= 2) {
ch += `${getRandomColor()}, `;
n = n - 1;
// 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;
}

return ch;
}

}

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

if (n == 1) {
if (n == 1) {

document.body.style.backgroundColor = `${getRandomColor()}`
setInterval(() => {
document.body.style.backgroundColor = `${getRandomColor()}`
}, `${set_time}`);
}
setInterval(() => {
document.body.style.backgroundColor = `${getRandomColor()}`
}, `${set_time}`);
}

else if (n > 1) {
else if (n > 1) {

if (view == "c" || view == "C" || view == "conic" || view == "Conic") {
if (view == "c" || view == "C" || view == "conic" || view == "Conic") {

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}`);
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") {
}
else if (view == "l" || view == "L" || view == "linear" || view == "Linear") {

document.body.style.background = `linear-gradient(${number(n - 1)} ${random_color})`;
setInterval(() => {
// document.body.style.backgroundColor = `${getRandomColor()}`
document.body.style.background = `linear-gradient(${number(n - 1)} ${random_color})`;
}, `${set_time}`);
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
Loading

0 comments on commit 67d2696

Please sign in to comment.