JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://threejs.org/build/three.js"></script>
JavaScript
let camera, scene, renderer;
init();
animate();
function init() {
camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.01, 10 );
camera.position.z = 1;
scene = new THREE.Scene();
// generate data texture
const color = new THREE.Color();
const width = 256;
const height = 256;
const size = width * height;
const data = new Uint8Array( 3 * size );
for ( let i = 0; i < size; i ++ ) {
color.setHex( 0xffffff * Math.random() );
const r = Math.floor( color.r * 255 );
const g = Math.floor( color.g * 255 );
const b = Math.floor( color.b * 255 );
const stride = i * 3;
data[ stride ] = r;
data[ stride + 1 ] = g;
data[ stride + 2 ] = b;
}
//
var texture = new THREE.DataTexture( data, width, height );
texture.format = THREE.RGBFormat;
texture.magFilter = THREE.LinearFilter;
texture.minFilter = THREE.LinearMipMapLinearFilter;
texture.generateMipmaps = true;
texture.needsUpdate = true
const geometry = new THREE.PlaneBufferGeometry();
const material = new THREE.MeshBasicMaterial( { map: texture } );
const mesh = new THREE.Mesh( geometry, material );
scene.add( mesh );
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
}
function animate() {
requestAnimationFrame( animate );
renderer.render( scene, camera );
}