Cube
How do I make an cube?
A CSS 3D cube built with canvases. Inspired by Nate Wiley's Particle Cube. What is a cube? How do you make a cube? This script and codes were developed by Gabi on 22 August 2022, Monday.
Cube - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Cube</title> <style> /* NOTE: The styles were added inline because Prefixfree needs access to your styles and they must be inlined if they are on local disk! */ html,
body { height: 100%;
}
body { background: radial-gradient(#2aa4d5, #030633); overflow: hidden; perspective: 500px;
}
.cube { bottom: 0; height: 150px; left: 0; margin: auto; position: absolute; -webkit-transform-style: preserve-3d; transform-style: preserve-3d; right: 0; top: 0; width: 150px; /*opacity: .75;*/ animation: rotate 10s linear infinite;
}
.face { height: 100%; left: 0; position: absolute; top: 0; width: 100%;
}
.cvs{border:1px solid #444;}
.back {}
.left { transform: translateX(-150px) rotateY(-90deg); transform-origin: right center;
}
.right { transform: translateX(150px) rotateY(90deg); transform-origin: left center;
}
.top { transform: translateY(-150px) rotateX(90deg); transform-origin: bottom center;
}
.bottom { transform: translateY(150px) rotateX(-90deg); transform-origin: center top;
}
.front { transform: translateY(450px) translateZ(-150px) rotateX(180deg); transform-origin: center -150px;
}
@-webkit-keyframes rotate { 0% { transform: rotateY(0deg) rotateX(0deg) rotateZ(0deg) } 100% { transform: rotateY(360deg) rotateX(360deg) rotateZ(720deg) }
}
@keyframes rotate { 0% { transform: rotateY(0deg) rotateX(0deg) rotateZ(0deg) } 100% { transform: rotateY(360deg) rotateX(360deg) rotateZ(720deg) }
} </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</head>
<body> <div class="cube"> <div class="face back"><canvas class = 'cvs'></canvas></div> <div class="face left"><canvas class = 'cvs'></canvas></div> <div class="face right"><canvas class = 'cvs'></canvas></div> <div class="face top"><canvas class = 'cvs'></canvas></div> <div class="face bottom"><canvas class = 'cvs'></canvas></div> <div class="face front"><canvas class = 'cvs'></canvas></div>
</div> <script src='js/vlqxyo.js'></script> <script src="js/index.js"></script>
</body>
</html>
Cube - Script Codes CSS Codes
html,
body { height: 100%;
}
body { background: radial-gradient(#2aa4d5, #030633); overflow: hidden; perspective: 500px;
}
.cube { bottom: 0; height: 150px; left: 0; margin: auto; position: absolute; -webkit-transform-style: preserve-3d; transform-style: preserve-3d; right: 0; top: 0; width: 150px; /*opacity: .75;*/ animation: rotate 10s linear infinite;
}
.face { height: 100%; left: 0; position: absolute; top: 0; width: 100%;
}
.cvs{border:1px solid #444;}
.back {}
.left { transform: translateX(-150px) rotateY(-90deg); transform-origin: right center;
}
.right { transform: translateX(150px) rotateY(90deg); transform-origin: left center;
}
.top { transform: translateY(-150px) rotateX(90deg); transform-origin: bottom center;
}
.bottom { transform: translateY(150px) rotateX(-90deg); transform-origin: center top;
}
.front { transform: translateY(450px) translateZ(-150px) rotateX(180deg); transform-origin: center -150px;
}
@-webkit-keyframes rotate { 0% { transform: rotateY(0deg) rotateX(0deg) rotateZ(0deg) } 100% { transform: rotateY(360deg) rotateX(360deg) rotateZ(720deg) }
}
@keyframes rotate { 0% { transform: rotateY(0deg) rotateX(0deg) rotateZ(0deg) } 100% { transform: rotateY(360deg) rotateX(360deg) rotateZ(720deg) }
}
Cube - Script Codes JS Codes
var cc = document.querySelectorAll(".cvs");
var cctx = [];
for (var i = 0; i < cc.length; i++) { cctx[i] = cc[i].getContext("2d"); console.log(cctx[i]) cc[i].width = 150; cc[i].height = 150; cctx[i].fillStyle = "rgba(0,0,40,.1)";
}
var c = document.createElement("canvas");
var ctx = c.getContext("2d");
var cw = c.width = 150;
var ch = c.height = 150;
var cx = cw / 2, cy = ch / 2;
var rad = Math.PI / 180;
var frames = 0;
var Ry = [];
var R = 20;
var A = 1.5, A1;
var B = 1;
var K = 3;
var rotation = 0;
ctx.lineWidth = 2;
function buildRy(rotation, A1) { for (var a = 0; a < 360; a += 3) { var o = {} o.r = A * R + B * R * Math.sin(K * (a + rotation) * rad); o.x = cx + o.r * Math.cos(a * rad); o.y = cy + o.r * Math.sin(a * rad); o.r1 = A1 * R + B * R * Math.cos(K * (a - rotation / 3) * rad); o.x1 = cx + o.r1 * Math.cos(a * rad); o.y1 = cy + o.r1 * Math.sin(a * rad); o.color = "hsl(" + a + ", 100%,50%)"; Ry.push(o); }
}
function Draw() { Ry.length = 0; rotation++; A1 = A * Math.sin(rotation * rad); buildRy(rotation, A1); ctx.clearRect(0, 0, cw, ch); for (var i = 0; i < Ry.length; i += 6) { var o = Ry[i]; ctx.strokeStyle = o.color; ctx.beginPath(); ctx.strokeRect(o.x, o.y, 3, 3); ctx.stroke(); ctx.beginPath(); ctx.strokeRect(o.x1, o.y1, 2, 2); } requestId = window.requestAnimationFrame(Draw); var img = c; for (var i = 0; i < cctx.length; i++) { cctx[i].fillRect(0, 0, cw, ch); cctx[i].drawImage(img, 0, 0); }
}
requestId = window.requestAnimationFrame(Draw);
Developer | Gabi |
Username | enxaneta |
Uploaded | August 22, 2022 |
Rating | 4.5 |
Size | 3,814 Kb |
Views | 36,432 |
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 |
Fat worm | 2,695 Kb |
Animated SVG Turbulence Filter | 2,330 Kb |
Circular trail | 2,363 Kb |
Sine wave ice cream | 2,127 Kb |
Some flowers | 3,895 Kb |
Sphere Within Sphere | 4,769 Kb |
Sea Creature | 3,380 Kb |
Intersecting Lines | 3,407 Kb |
Sakura | 3,605 Kb |
Conical Helix | 2,196 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 |
Bubble animation | Ftabor | 6,565 Kb |
CSS3 Diamond | Rendro | 1,960 Kb |
Shopping List | Markmurray | 6,015 Kb |
Pure CSS Spinners | Jlong | 2,043 Kb |
Drill-down Map | Good886 | 8,484 Kb |
Animated skewed panes | NyX | 4,462 Kb |
Incremental game | Eprouver | 5,868 Kb |
HTML5 Breakout | Jaysalvat | 4,873 Kb |
A Pen by Brendan Skousen | Bskousen | 2,954 Kb |
Resizable SASS Icons | Marianarlt | 7,611 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!