Fake 3D
How do I make an fake 3d?
Playing with 3d effect in canvas. What is a fake 3d? How do you make a fake 3d? This script and codes were developed by Massimo on 17 September 2022, Saturday.
Fake 3D - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Fake 3D</title> <link rel="stylesheet" href="css/style.css">
</head>
<body>
<canvas id="c"></canvas> <script src='https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.6.2/dat.gui.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Fake 3D - Script Codes CSS Codes
@import url("https://fonts.googleapis.com/css?family=Open+Sans");
body { margin: 0; overflow: hidden; background: #000;
}
body li, body .close-button { font-family: 'Open Sans', sans-serif; font-size: 14px; text-transform: capitalize;
}
Fake 3D - Script Codes JS Codes
var c = document.getElementById('c'), ctx = c.getContext('2d'), shapes = [], s = { 'count': 100, 'size': 20, 'speed': 10, 'focal': 300, 'perspective': 5000 };
window.requestAnimFrame = (function () { return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function (callback) { window.setTimeout(callback, 1000/60); };
})();
function resize() { c.width = window.innerWidth; c.height = window.innerHeight; ctx.translate(.5*c.width, .5*c.height); shapes = []; init();
}
resize();
window.addEventListener("resize", resize);
var gui = new dat.GUI();
gui.add(s, "count", 1, 300, 1).onChange(resize);
gui.add(s, "size", 1, 100, 1).onChange(resize);
gui.add(s, "speed", 1, 50, 1);
gui.add(s, "focal", 1, 1000, 1);
gui.add(s, "perspective", 1, 10000, 1);
function Shape(x, y, z, col, shape) { this.x = x; this.y = y; this.z = z; this.col = col; this.shape = shape;
}
function setColor () { return 'rgba(' + Math.round(255*Math.random()) + ',' + Math.round(255*Math.random()) + ',' + Math.round(255*Math.random()) + ',' + Math.random() ')';
}
function setShape(v) { var rand = Math.random(), shape; if(rand < .3) { shape = 'rect'; } else if(rand > .3 && rand < .7) { shape = 'triangle'; } else { shape = 'circle'; } return shape;
}
function drawShape(shape) { ctx.beginPath(); if(shape == 'rect') { ctx.rect(-s.size/2, -s.size/2, s.size, s.size); } else if(shape == 'triangle') { ctx.moveTo(0, 0); ctx.lineTo(s.size/2, -s.size); ctx.lineTo(s.size, 0); } else { ctx.arc(0, 0, s.size, 0, 2*Math.PI); } ctx.fill();
}
function init() { for(var i=0; i<s.count; i++) { var x = -c.width/2 + c.width*Math.random(), y = -c.height/2 + c.height*Math.random(), z = s.perspective*Math.random(), col = setColor(), shape = setShape(Math.random()); shapes.push(new Shape(x, y, z, col, shape)); }
}
function update() { ctx.clearRect(-.5*c.width, -.5*c.height, c.width, c.height); for(var i=0; i<shapes.length; i++) { var sh = shapes[i]; ctx.save(); var p = s.focal / (s.focal + sh.z); ctx.translate(p*sh.x, p*sh.y); ctx.scale(p, p); ctx.fillStyle = sh.col; drawShape(sh.shape); ctx.restore(); sh.z -= s.speed; if(sh.z < -s.focal) { sh.z = s.perspective*Math.random(); } } window.requestAnimFrame(update);
}
update();
Developer | Massimo |
Username | _massimo |
Uploaded | September 17, 2022 |
Rating | 4.5 |
Size | 3,086 Kb |
Views | 38,456 |
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 |
Upside down cat | 5,464 Kb |
Page Not Found | 3,710 Kb |
Spinner | 3,072 Kb |
Cat loader | 3,899 Kb |
Pathfinder | 5,360 Kb |
Css preloader | 3,888 Kb |
Run T-REX run in CSS | 8,203 Kb |
Mandala drawing concept | 3,474 Kb |
Melting ice cream | 3,839 Kb |
Bernard the polar bear | 4,070 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 |
CSS3 Diamond | Rendro | 1,960 Kb |
Responsive Minimal Blog Layout | Hackthevoid | 5,261 Kb |
Minimal Menu | Achudars | 3,430 Kb |
GLSL Hills | Ykob | 6,991 Kb |
CSS Infinite 360 | APinix | 5,564 Kb |
Parallax-ish Sliding Content | Jdsteinbach | 2,748 Kb |
BabyStore | Pablo-Ai | 3,807 Kb |
Transition | Shayhowe | 1,632 Kb |
Sticky notes with CSS3 | HaiNguyen007 | 2,146 Kb |
JavaScript constructors | Simboonlong | 2,415 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!