“This is the 12th day of my participation in the First Challenge 2022. For details: First Challenge 2022
Near the end of the semester, are you still writing an HTML web design class assignment and the teacher’s homework requirements are overwhelming? Is the total number of pages required too high? Don’t know how to do your HTML web homework? Don’t have the right template? And so on. The problem you’re trying to solve, In the column here common web design homework topics are personal, food, company, sports, cosmetics, logistics, environmental protection, books, wedding, military, games, festivals, smoking cessation, film, photography school, tourism, e-commerce, pets, electrical appliances, tea, home, hotel, dance, animation, stars, Clothing, culture, hometown, flowers, gifts, cars, other web design topics, A+ level homework, can meet college students web design needs can meet your needs. The original HTML+CSS+JS page design, Web college students web design job source code, this is a good # HTML+CSS+JS 3D architectural structure rotation effect web design production, the picture is smart
Effect demonstration:
Main code implementation:
CSS styles:
html.body {
overflow: hidden;
touch-action: none;
position: absolute;
margin: 0px;
padding: 0px;
width: 100%;
height: 100%;
background: rgb(0.0.0);
}
canvas {
position: absolute;
width: 100%;
height: 100%;
user-select: none;
background: rgb(0.0.0);
cursor: pointer;
}
Copy the code
The HTML code
<! DOCTYPEhtml>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>3D architectural structure rotation effects</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<canvas></canvas>
<! -- Click to generate a new structure -->
<script src="js/script.js"></script>
</body>
</html>
Copy the code
Js part of the code:
const webGL = (transforms, setup) = > {
const canvas = document.querySelector("canvas");
const gl = canvas.getContext("webgl", {
alpha: false
});
if(! gl)return false;
gl.enable(gl.DEPTH_TEST);
gl.enable(gl.CULL_FACE);
const resize = () = > {
canvas.width = canvas.offsetWidth;
canvas.height = canvas.offsetHeight;
gl.viewport(0.0, gl.drawingBufferWidth, gl.drawingBufferHeight);
camera.projection(fov);
};
window.addEventListener("resize".() = > {
mustResize = true;
});
const clearScreen = () = > {
if (mustResize) resize();
gl.clearColor(0.2.0.225.0.25.1);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
};
const u3 = (program, name) = > {
const loc = gl.getUniformLocation(program, name);
return {
set(v) {
gl.uniform3f(loc, v[0], v[1], v[2]); }}};const computeNormals = (v) = > {
const n = [];
for (let i = 0; i < v.length; i += 9) {
const p1x = v[i + 3] - v[i];
const p1y = v[i + 4] - v[i + 1];
const p1z = v[i + 5] - v[i + 2];
const p2x = v[i + 6] - v[i];
const p2y = v[i + 7] - v[i + 1];
const p2z = v[i + 8] - v[i + 2];
const p3x = p1y * p2z - p1z * p2y;
const p3y = -(p1x * p2z - p1z * p2x);
const p3z = p1x * p2y - p1y * p2x;
const mag = Math.sqrt(p3x * p3x + p3y * p3y + p3z * p3z);
if (mag === 0) {
n.push(0.0.0.0.0.0.0.0.0);
} else{ n.push(p3x / mag, p3y / mag, p3z / mag); n.push(p3x / mag, p3y / mag, p3z / mag); n.push(p3x / mag, p3y / mag, p3z / mag); }}return n;
};
Copy the code
Clocked articles updated 33/100 days
You can like, collect, pay attention to, comment on me, there are database related questions to contact me or exchange yo ~!