Cubes

In this example below you will see how to do a Cubes with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by screener13, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright screener13 ©

Technologies

  • HTML
  • CSS
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>Cubes</title>
  
  
  
      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>

  
  <script src='https://cdnjs.cloudflare.com/ajax/libs/three.js/86/three.min.js'></script>

  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/screener13/cubes-PEMeoY */
body {
  margin: 0;
}

canvas {
  width: 100%;
  height: 100%;
}


/*Downloaded from https://www.codeseek.co/screener13/cubes-PEMeoY */
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(30, window.innerWidth / window.innerHeight, 0.1, 300);

var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);

var geometry = new THREE.BoxGeometry(1, 1, 1);
var material = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
var cube = new THREE.Mesh(geometry, material);
scene.add(cube);

var material = new THREE.MeshBasicMaterial({ color: 0xff0000 });
var cubeTwo = new THREE.Mesh(geometry, material);
scene.add(cubeTwo);

var material = new THREE.MeshBasicMaterial({ color: 0x0000ff });
var cubeThree = new THREE.Mesh(geometry, material);
scene.add(cubeThree);

camera.position.z = 5;

function animate() {
	requestAnimationFrame(animate);
	renderer.render(scene, camera);
	cube.rotation.x += 0.001;
	cube.rotation.y += 0.001;
	cubeTwo.rotation.x += 0.002;
	cubeTwo.rotation.y += 0.002;
	cubeThree.rotation.x += 0.003;
	cubeThree.rotation.y += 0.003;
}
animate();

Comments