3d pure javascript 2d canvas
How do I make an 3d pure javascript 2d canvas?
No longer an icosahedron but a 3d sphere with however much detail you want in 3d rolling in the direction of your mouse without webgl or 3d css all done with javascript and 2dcanvas.. What is a 3d pure javascript 2d canvas? How do you make a 3d pure javascript 2d canvas? This script and codes were developed by Darby Rathbone on 24 December 2022, Saturday.
3d pure javascript 2d canvas - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>3d pure javascript 2d canvas</title>
</head>
<body> <script src="js/index.js"></script>
</body>
</html>
3d pure javascript 2d canvas - Script Codes JS Codes
function Point3d(a, c, b) { this.x = (a === undefined) ? 0 : a; this.y = (c === undefined) ? 0 : c; this.z = (b === undefined) ? 0 : b; this.fl = 400; this.vpX = 0; this.vpY = 0; this.cX = 0; this.cY = 0; this.cZ = 0
}
Point3d.prototype = { setVanishingPoint: function (b, a) { this.vpX = b; this.vpY = a }, setCenter: function (c, b, a) { this.cX = c; this.cY = b; this.cZ = a }, rotateX: function (a) { var d = Math.cos(a), b = Math.sin(a), c = this.y * d - this.z * b, e = this.z * d + this.y * b; this.y = c; this.z = e; return this }, rotateY: function (a) { var d = Math.cos(a), c = Math.sin(a), b = this.x * d - this.z * c, e = this.z * d + this.x * c; this.x = b; this.z = e; return this }, rotateZ: function (a) { var d = Math.cos(a), b = Math.sin(a), c = this.x * d - this.y * b, e = this.y * d + this.x * b; this.x = c; this.y = e; return this }, getScreenX: function () { var a = this.fl / (this.fl + this.z + this.cZ); return this.vpX + (this.cX + this.x) * a }, getScreenY: function () { var a = this.fl / (this.fl + this.z + this.cZ); return this.vpY + (this.cY + this.y) * a }
};
var pointa = new Array();
var points = new Array();
var faces =[];
//points.push(new Point3d(0, 0, -100));
var anglecount = 3;
var change = Math.PI/(anglecount);
var count = 0;
for(var j = 0;j<=Math.PI;j+=Math.PI/(anglecount)){ pointa.push([]); for (var i = 0; i <= anglecount; i++) { pointa[pointa.length-1].push(new Point3d(Math.sin(j) * Math.cos( i*2 * Math.PI / (anglecount)+(count*change)) , Math.sin(j) * Math.sin(2*i * Math.PI / (anglecount)+(count*change)) , Math.cos(j) )) }
count++;}
points =points.concat.apply(points,pointa);
console.log(points);
//for (var i = 0; i < anglecount; i++) {
//points.push(new Point3d(0,0,1));
//}
points.forEach(function(e,i){ e.x*=200; e.z*=200; e.y*=200; faces.push([e,points[(i+1)%points.length],points[(i+(pointa[0].length))%points.length]]);
faces.push([e,points[(i+1)%points.length],points[(i+1+points.length-(pointa[0].length))%points.length]]);
});
//points.push(new Point3d(0, 0, 100));
function display(b) { context.save(); context.beginPath(); context.moveTo(b[0].getScreenX(), b[0].getScreenY()); for (var a = 0; a < b.length; a++) { context.lineTo(b[a].getScreenX(), b[a].getScreenY()) } context.closePath(); context.clip(); context.fillStyle = b.color; //context.fill(); context.stroke(); context.restore()
}
faces.forEach(function (d, c, b) { d.color = "RGB(" + ((Math.random() * 255) | 0) + "," + ((Math.random() * 255) | 0) + "," + ((Math.random() * 255) | 0) + ")"
});
var can = document.createElement("canvas");
can.width = 500;
can.height = 500;
var context = can.getContext("2d");
document.body.appendChild(can);
var mousex = 250, mousey = 250;
context.lineWidth = 2;
faces.forEach(display);
//context.stroke();
context.strokeStyle = "RGB(0,0,0)";
function displayer() { context.clearRect(0, 0, can.width, can.height); points.forEach(function (a) { a.rotateX((mousey - a.vpY) * 0.0001).rotateY((mousex - a.vpX) * 0.0001); a.setVanishingPoint(250, 250); a.setCenter(a.x, a.y, 500) }); faces = faces.sort(sortbyaz); faces.forEach(display) requestAnimationFrame(displayer);
}
requestAnimationFrame(displayer);
document.body.onmousemove = function (a) { mousex = a.pageX; mousey = a.pageY
};
function sortbyaz(d, c) { var h = 0, g = 0; for (var f = 0; f < d.length; f++) { h += d[f].z } for (var e = 0; e < c.length; e++) { g += c[e].z } h /= d.length + 1; g /= c.length + 1; return g - h
};
Developer | Darby Rathbone |
Username | blackkbot |
Uploaded | December 24, 2022 |
Rating | 3 |
Size | 2,667 Kb |
Views | 6,072 |
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 |
3d pure javascript 2d canvas | 2,600 Kb |
Jigsaw puzzle | 5,193 Kb |
Webworker with an editable textbox | 3,525 Kb |
A linearly interpolated spline | 2,328 Kb |
Java style console | 2,381 Kb |
Drag, drop and snap | 2,542 Kb |
Golden ratio | 1,893 Kb |
Balls | 3,920 Kb |
Pendulum | 3,104 Kb |
Remote image | 1,989 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 |
Simple CSS loader. | Cabrera | 2,574 Kb |
Improved Page Flipping Effect | Usaphp | 5,201 Kb |
Web Spiral - p5.js | TWAIN | 2,183 Kb |
Simple, flat contact form | Zeaklous | 2,719 Kb |
Nav Test -- cats 1 | Payls | 4,735 Kb |
React Template | Isac | 1,241 Kb |
Social.svg.min | Larsenwork | 13,849 Kb |
Pomodoro Clock | Osycon | 3,705 Kb |
Circle Progression Plugin | Agrayson | 2,612 Kb |
SVG hamburger menu button | Elifitch | 2,602 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!