Icosahedron
How do I make an icosahedron?
CSS 3D transforms. What is a icosahedron? How do you make a icosahedron? This script and codes were developed by Dmitriy Karpov on 27 August 2022, Saturday.
Icosahedron - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Icosahedron</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <wrapper> <h1>Icosahedron</h1> <header> <div> <span>edge</span> <input id="edge" type="range" min="50" max="250" value="100" step="1"> <b>100</b> </div> <div> <span>angle</span> <input id="angle" type="range" min="0" max="180" value="30" step="1"> <b>30</b> </div> </header> <section> <figure id="icosahedron"> </figure> </section> <footer> <a href="http://en.wikipedia.org/wiki/Icosahedron" target="_blank">Icosahedron</a> is regular polyhedron, one of the <a href="http://en.wikipedia.org/wiki/Platonic_solid" target="_blank">Platonic solids</a>. Each of the 20 sides is an equilateral triangle. The number of edges is 30, vertices - 12. </footer> </wrapper> <script src="js/index.js"></script>
</body>
</html>
Icosahedron - Script Codes CSS Codes
html { height:100%; width:100%; min-width:460px; min-height:460px; position:relative;
}
body { position:absolute; top:0; left:0; right:0; bottom:0; background-color:#222; font-family:Arial, Helvetica, sans-serif; font-size:11px; color:#777; background-image:-webkit-radial-gradient(cover, #333, #111); background-image: -moz-radial-gradient(cover, #333, #111); background-image: radial-gradient(cover, #333, #111);
}
a { color:#44ABDA; text-decoration:none;
}
wrapper { position:absolute; height:450px; width:450px; top:50%; left:50%; margin-top:-225px; margin-left:-225px; -webkit-perspective:500px; -moz-perspective:500px; perspective:500px;
}
h1 { font-size:22px; margin:0; font-weight:normal; color:#FFF; position:absolute; top:6px; left:0;
}
/* header */
header { position:absolute; top:0; right:0;
}
header div { margin:2px 0 0 0;
}
header span { display:inline-block; vertical-align:middle; width:32px; color:#999;
}
header b { color:#44ABDA; display:inline-block; vertical-align:middle; font-weight:normal; width:20px;
}
header input { display:inline-block; vertical-align:middle; background:#111; width:120px; height:12px; -webkit-appearance:none; -webkit-transition:background 0.2s ease; -moz-transition:background 0.2s ease; transition:background 0.2s ease;
}
header input:focus { outline:none;
}
header input:hover { background:#090909;
}
header input::-webkit-slider-thumb { background:#44ABDA; width:4px; height:14px; -webkit-appearance:none;
}
/* section */
section { position:absolute; top:0; left:0; right:0; bottom:0; -webkit-animation:spin 8s linear infinite; -moz-animation:spin 8s linear infinite; animation:spin 8s linear infinite;
}
section, section figure, section span { -webkit-transform-style:preserve-3d; -moz-transform-style:preserve-3d; transform-style:preserve-3d;
}
section figure { position:absolute; margin:0; top:0; left:0; right:0; bottom:0; -webkit-transform:rotateZ(30deg); -moz-transform:rotateZ(30deg); transform:rotateZ(30deg);
}
section span { display:block; position:absolute; overflow:hidden;
}
section span:before { content:''; position:absolute; width:100%; height:100%; background:rgba(0,0,0,.95); -webkit-transform:rotate(60deg) skew(30deg); -moz-transform:rotate(60deg) skew(30deg); transform:rotate(60deg) skew(30deg);
}
section span.a:before { top:50%; border-top:2px dashed #FFF;
}
section span.b { border-top:2px dashed #FFF;
}
section span.b:before { top:-50%; border-right:2px dashed #FFF;
}
/* footer */
footer { position:absolute; bottom:0; left:0; right:0; font-size:10px;
}
/* keyframes */
@-webkit-keyframes spin { from {-webkit-transform:translateZ(-230px) rotateY(0deg);} to {-webkit-transform:translateZ(-230px) rotateY(360deg);}
}
@-moz-keyframes spin { from {-moz-transform:translateZ(-230px) rotateY(0deg);} to {-moz-transform:translateZ(-230px) rotateY(360deg);}
}
@keyframes spin { from {transform:translateZ(-230px) rotateY(0deg);} to {transform:translateZ(-230px) rotateY(360deg);}
}
Icosahedron - Script Codes JS Codes
var figure; var Icosahedron = function(element) { // -------------- // vars // -------------- var e = this; e.c = element; e.l = 20; // triangles length e.s = 150; // edge size e.a = 108; // pentagon's angle e.b = 2; // border width // -------------- // methods // -------------- e.css = function(s, i) { var n = e.span[i]; for (var p in s) { switch(p) { case 'name': n.className = s[p]; break case 'transform': var t = ''; for (var a in s[p]) { t += a + '(' + s[p][a] + ') ' } n.style[e.transform] = t; break; default: n.style[p] = s[p]; } } } // edge style e.draw = function() { for (var i = 0; i < e.l; i++) { var s = { width: e.s + 'px', height: e.h + 'px', top: (e.c.offsetHeight - e.h) / 2 + 'px', left: (e.c.offsetWidth - e.s) / 2 + 'px' } if (i < e.l / 4) { s.name = 'a'; s.transform = { translateY: -e.t + 'px', rotateY: 360/5 * i + 'deg', translateZ: e.ry + 'px', rotateX: 90-e.ax + 'deg' } } else if (i >= e.l / 4 && i < e.l * 3/4) { var k = (i % 2 == 0) ? 1 : -1; s.name = (k == 1) ? 'b' : 'a'; s.transform = { rotateY: 360/10*i + 'deg', translateZ: e.rz + 'px', rotateX: (90-e.ay)/2*k + 'deg' } } else { s.name = 'b'; s.transform = { translateY: e.t + 'px', rotateY: 360/5*(i+0.5) + 'deg', translateZ: e.ry + 'px', rotateX: e.ax-90 + 'deg' } } e.css(s, i); } } // icosahedron properties e.init = function() { e.h = e.s*Math.sin(Math.PI/3); // triangle height e.hx = e.s*Math.sin(Math.PI*3/10); // body height e.rx = e.s/2*Math.tan(Math.PI*3/10); // piramid radius e.rz = e.s/4/Math.tan(Math.PI/10) + e.b*2; // body radius e.ax = Math.acos(e.rx/e.h)*180/Math.PI; // piramid face angle e.ay = Math.asin(e.hx/e.h)*180/Math.PI; // body face angel e.ry = e.h/2*Math.cos(e.ax*Math.PI/180) + e.b // piramid midradius e.t = Math.sin((90-e.ax)*Math.PI/180)*e.h + e.b // piramid height e.draw(); } // detect transform property e.detector = function() { var prefixes = [ 'transform', 'WebkitTransform', 'MozTransform' ]; for (var i = 0; i < prefixes.length; i++) { var div = document.createElement('div'); var ind = div.style[prefixes[i]]; if (ind !== undefined) { return prefixes[i]; } } } // add edges e.html = function() { for (var i = 0; i < e.l; i++) { var n = document.createElement('span'); e.c.appendChild(n); } e.span = e.c.getElementsByTagName('span'); e.transform = e.detector(); } // create e.create = function() { e.html(); e.init(); } } // scaling var scale = function() { figure.s = parseInt(this.value); this.nextElementSibling.innerHTML = this.value; figure.init(); return false; } // ratation var rotate = function() { var val = parseInt(this.value); this.nextElementSibling.innerHTML = this.value; figure.c.style[figure.transform] = 'rotateZ(' + val + 'deg)' return false; } // initialization var init = function() { var element = document.getElementById('icosahedron'); figure = new Icosahedron(element); figure.create(); var edge = document.getElementById('edge'); var angle = document.getElementById('angle'); edge.addEventListener('change', scale, false); angle.addEventListener('change', rotate, false); } window.addEventListener('DOMContentLoaded', init, false);
Developer | Dmitriy Karpov |
Username | karpovsystems |
Uploaded | August 27, 2022 |
Rating | 4 |
Size | 4,053 Kb |
Views | 52,624 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Javascript Pagination | 6,333 Kb |
CSS3 text transitions | 2,569 Kb |
Curve Bezier | 3,261 Kb |
Larvaes | 2,686 Kb |
CSS 3D Panorama | 3,478 Kb |
City generator | 2,944 Kb |
Metro style icons | 3,691 Kb |
Spin | 4,269 Kb |
Eye of Sauron | 3,085 Kb |
Sphere | 2,432 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Siema - add pagination to prototype | Pawelgrzybek | 2,575 Kb |
Kut D3 | Jellevrswk | 3,687 Kb |
APortfolio | Skybutterfly | 5,174 Kb |
Cool audio | Bigliam | 1,868 Kb |
Parallax.js | Zmeeey5 | 2,330 Kb |
Table Exercise | Fresco | 9,585 Kb |
A simple log in form made with css | Mayurelbhar | 2,160 Kb |
Twitch JSON API | Jvhti | 2,808 Kb |
Minimal Material Design Form Input | Koenigsegg1 | 3,076 Kb |
Savemedia1.1 | EdsonAlcala | 2,148 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!