-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
332 additions
and
68 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.