JSFiddle - React, Tailwind, and code Playground

by navinleon

HTML

<script src="//cdn.rawgit.com/mrdoob/three.js/master/build/three.min.js"></script>

CSS

body {
	  margin: 0;
}

JavaScript

var camera, scene, renderer;

init();
animate();

function init() {

    camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.01, 10 );
    camera.position.z = 3;

    scene = new THREE.Scene();

    var geometry = new THREE.BufferGeometry();
		
		var vertices = [];
		var colors = [];
		
		vertices.push( 0, 0, 0 );
		vertices.push( 1, 1, 1 );
		
		vertices.push( 1, 0, 0 );
		vertices.push( 1, 1, 0 );
		
		vertices.push( 1, 1, 0 );
		vertices.push( 0, 1, 0 );
		console.log('vertices',vertices)
		colors.push( 1, 0, 0 );
		colors.push( 1, 0, 0 );
		
		colors.push( 0, 1, 0 );
		colors.push( 0, 1, 0 );
		
		colors.push( 0, 0, 1 );
		colors.push( 0, 0, 1 );
    		console.log('colors',colors)
		
		geometry.addAttribute( 'position', new THREE.Float32BufferAttribute( vertices, 3 ) );
		geometry.addAttribute( 'color', new THREE.Float32BufferAttribute( colors, 3 ) );
		
    var material = new THREE.LineBasicMaterial( { vertexColors: true } );

    var lines = new THREE.LineSegments( geometry, material );
    scene.add( lines );

    renderer = new THREE.WebGLRenderer( { antialias: true } );
    renderer.setSize( window.innerWidth, window.innerHeight );
    document.body.appendChild( renderer.domElement );

}

function animate() {

    requestAnimationFrame( animate );
    renderer.render( scene, camera );

}