Rotating Cubes with p5.js

Developer
Size
1,753 Kb
Views
28,336

How do I make an rotating cubes with p5.js?

What is a rotating cubes with p5.js? How do you make a rotating cubes with p5.js? This script and codes were developed by Ruslan Marin on 07 December 2022, Wednesday.

Rotating Cubes with p5.js Previews

Rotating Cubes with p5.js - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Rotating Cubes with p5.js</title>
</head>
<body> <div id="canvasContainer"></div> <script src='https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.6/p5.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Rotating Cubes with p5.js - Script Codes JS Codes

var cube3d = { theta: 0, draw: function(p, sizeX, sizeY) { p.push(); p.rotateZ(this.theta); p.rotateX(this.theta); p.rotateY(this.theta); p.box(sizeX/8, sizeX/8, sizeX/8); p.pop(); this.theta += Math.PI/128; }
};
var cube2d = { theta: 0, draw: function(p, sizeX, sizeY) { p.push(); p.rotateZ(-this.theta); p.translate(sizeX/4, -sizeX/16); p.rotateZ(-2*this.theta); p.rect(-sizeX/16, -sizeX/16, sizeX/8, sizeY/8); p.pop(); this.theta += Math.PI/128; }
};
var sketchProc = function(p) { var sizeX = 400; var sizeY = 400; var theta = 0; var objects = [cube3d, cube2d]; p.setup = function() { p.frameRate(30); p.createCanvas(sizeX, sizeY, p.WEBGL); }; // Draw loop p.draw = function(){ p.background(1); objects.forEach(function(obj) { obj.draw(p, sizeX, sizeY); }); };
};
new p5(sketchProc, document.getElementById("canvasContainer"));
Rotating Cubes with p5.js - Script Codes
Rotating Cubes with p5.js - Script Codes
Home Page Home
Developer Ruslan Marin
Username marinru
Uploaded December 07, 2022
Rating 3
Size 1,753 Kb
Views 28,336
Do you need developer help for Rotating Cubes with p5.js?

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!

Ruslan Marin (marinru) Script Codes
Create amazing blog posts with AI!

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!