Skip to content

Instantly share code, notes, and snippets.

@Pan-Maciek
Created June 14, 2016 18:59
Show Gist options
  • Save Pan-Maciek/24fee2fac72c909991a0d1dc8b738435 to your computer and use it in GitHub Desktop.
Save Pan-Maciek/24fee2fac72c909991a0d1dc8b738435 to your computer and use it in GitHub Desktop.
<html>
<head>
<title>Stronka</title>
<link rel="stylesheet" href="style.css">
<meta charset="utf-8">
<script src="script.js"></script>
</head>
<body>
<table id="can">
</table>
<div id="sel">
<input type="color" id="color">
<button onclick="generateC()">Generate</button>
<button onclick="hide()">Hide</button>
</div>
</body>
</html>
var can, w, elements = []
window.onload = function(){
can = document.getElementById("can")
generate()
}
function generate(){
w = window.innerWidth
can.innerHTML = ""
var l = Math.floor(w/60) - 1
var colorR = Math.floor(Math.random() * 100 + 20),
colorG = Math.floor(Math.random() * 80 + 20),
colorB = Math.floor(Math.random() * 120 + 20)
var j
var c = Math.floor((window.innerHeight - 150) /180)
for (j = 0 ; j < c ; j++){
var tr = document.createElement("tr")
for(var i = 0; i < l; i++){
var el = document.createElement("td")
el.style.top = Math.floor(Math.random() * 100 + 20) + "px"
el.style.backgroundColor = "rgb(" + parseInt(colorR/Math.pow(0.8,j)) + "," + parseInt(colorG/Math.pow(0.8,j)) + "," + parseInt(colorB/Math.pow(0.8,j)) + ")"
tr.appendChild(el)
elements.push(el)
}
tr.style.top = (75 * j) + "px"
tr.style.zIndex = -j
can.appendChild(tr)
}
can.style.backgroundColor = "rgb(" + parseInt(colorR/Math.pow(0.8,j)) + "," + parseInt(colorG/Math.pow(0.8,j)) + "," + parseInt(colorB/Math.pow(0.8,j)) + ")"
for (j = 0 ; j < 5 ; j++){
var tr = document.createElement("tr")
for(var i = 0; i < l; i++){
var el = document.createElement("td")
el.style.top = Math.floor(Math.random() * 100 + 20) + "px"
el.style.backgroundColor = "rgb(" + parseInt(colorR/Math.pow(0.8,j)) + "," + parseInt(colorG/Math.pow(0.8,j)) + "," + parseInt(colorB/Math.pow(0.8,j)) + ")"
tr.appendChild(el)
elements.push(el)
}
tr.style.bottom = (75 * j) + "px"
tr.className = "bot"
tr.style.zIndex = -j
can.appendChild(tr)
}
}
function generateC(){
w = window.innerWidth
can.innerHTML = ""
var a = document.getElementById("color")
a = a.value
var l = Math.floor(w/60) - 1
var colorR = hexToRgb(a).r,
colorG = hexToRgb(a).g,
colorB = hexToRgb(a).b
var j
var c = Math.floor((window.innerHeight - 150) /180)
for (j = 0 ; j < c ; j++){
var tr = document.createElement("tr")
for(var i = 0; i < l; i++){
var el = document.createElement("td")
el.style.top = Math.floor(Math.random() * 100 + 20) + "px"
el.style.backgroundColor = "rgb(" + parseInt(colorR/Math.pow(0.8,j)) + "," + parseInt(colorG/Math.pow(0.8,j)) + "," + parseInt(colorB/Math.pow(0.8,j)) + ")"
tr.appendChild(el)
elements.push(el)
}
tr.style.top = (75 * j) + "px"
tr.style.zIndex = -j
can.appendChild(tr)
}
can.style.backgroundColor = "rgb(" + parseInt(colorR/Math.pow(0.8,j)) + "," + parseInt(colorG/Math.pow(0.8,j)) + "," + parseInt(colorB/Math.pow(0.8,j)) + ")"
for (j = 0 ; j < 5 ; j++){
var tr = document.createElement("tr")
for(var i = 0; i < l; i++){
var el = document.createElement("td")
el.style.top = Math.floor(Math.random() * 100 + 20) + "px"
el.style.backgroundColor = "rgb(" + parseInt(colorR/Math.pow(0.8,j)) + "," + parseInt(colorG/Math.pow(0.8,j)) + "," + parseInt(colorB/Math.pow(0.8,j)) + ")"
tr.appendChild(el)
elements.push(el)
}
tr.style.bottom = (75 * j) + "px"
tr.className = "bot"
tr.style.zIndex = -j
can.appendChild(tr)
}
}
function hexToRgb(hex) {
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16)
} : null;
}
function hide(){
document.getElementById("sel").style.display = "none"
}
body {
margin: 0;
}
td{
display: inline-block;
height: 220px;
width: 60px;
background-color: red;
border-radius: 60px;
position: relative
}
tr{
position: absolute;
transform: translateY(-150px)
}
table {
position: fixed;
display: block;
width: 100%;
height: 100%;
}
.bot{
transform: translateY(50px);
}
#sel {
position: fixed;
width: 350px;
height: 300px;
left: Calc(50% - 175px);
top: Calc(50% - 150px);
background-color: #1f1f1f;
border-radius: 20px;
text-align: center;
display: none
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment