2050
How do I make an 2050?
Experimenting with the three.js water shader. Created for day 20, Codevember, 2016.Created by XORXOR, 2016 Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0). What is a 2050? How do you make a 2050? This script and codes were developed by XORXOR on 27 January 2023, Friday.
2050 - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>2050</title>
</head>
<body> <html> <head> <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"> <title>[2050]</title> <style> body { margin: 0px; overflow: hidden; background-color: #ffffff; font-family: 'Arial'; } #help{ position: absolute; top: 1%; left: 1%; font-size: 30px; color:#324147; } </style> </head> <body> <div id="help">[2050]</div> </body>
</html> <script src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/896175/three.min.js'></script>
<script src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/896175/OrbitControls.js'></script>
<script src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/896175/Mirror.js'></script>
<script src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/896175/WaterShader.js'></script>
<script src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/896175/SkyShader.js'></script> <script src="js/index.js"></script>
</body>
</html>
2050 - Script Codes JS Codes
var container, stats;
var camera, scene, renderer;
var waterNormals;
var envTexture;
var azimuth = .45843;
var inclination = .3011;
var loader = new THREE.TextureLoader();
var clock = new THREE.Clock();
var time=0;
var uniforms;
var v;
var light;
var rusty;
loader.load( 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/896175/waternormals.jpg', function ( t ) { t.mapping = THREE.UVMapping; waterNormals = t; waterNormals.wrapS = waterNormals.wrapT = THREE.RepeatWrapping; rusty = loader.load( 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/896175/tex02.jpg') rusty.wrapS = rusty.wrapT = THREE.RepeatWrapping; init(); animate();
})
function initSky() { // Add Sky Mesh sky = new THREE.Sky(); scene.add( sky.mesh ); // Add Sun Helper sunSphere = new THREE.Mesh( new THREE.SphereBufferGeometry( 20, 16, 8 ), new THREE.MeshBasicMaterial( { color: 0xffffff } ) ); sunSphere.visible = false; scene.add( sunSphere ); uniforms = sky.uniforms; uniforms.turbidity.value = 0.01; uniforms.rayleigh.value = 0.0066; uniforms.luminance.value = 0.8; uniforms.mieCoefficient.value = 10.1; uniforms.mieDirectionalG.value = 0.824; moveSun();
}
function moveSun(){ var distance = 4500; var theta = Math.PI * ( inclination - 0.5 ); var phi = 2 * Math.PI * (azimuth - 0.5 ); sunSphere.position.x = distance * Math.cos( phi ); sunSphere.position.y = distance * Math.sin( phi ) * Math.sin( theta ); sunSphere.position.z = distance * Math.sin( phi ) * Math.cos( theta ); sky.uniforms.sunPosition.value.copy( sunSphere.position );
}
function init() { container = document.createElement( 'div' ); document.body.appendChild( container ); renderer = new THREE.WebGLRenderer({antialias: true}); renderer.setPixelRatio( window.devicePixelRatio ); renderer.setSize( window.innerWidth, window.innerHeight ); renderer.shadowMap.enabled = true; renderer.shadowMap.type = THREE.PCFSoftShadowMap; container.appendChild( renderer.domElement ); scene = new THREE.Scene(); camera = new THREE.PerspectiveCamera( 55, window.innerWidth / window.innerHeight, 0.5, 3000000 ); camera.position.set( 0, 15, 0 ); camera.rotation.set(-0,0,0); initSky(); water = new THREE.Water( renderer, camera, scene, { textureWidth: 512, textureHeight: 512, waterNormals: waterNormals, alpha: 1.0, sunDirection: sky.uniforms.sunPosition.value.normalize(), sunColor: 0xf5ebce, waterColor: 0x5b899b, distortionScale: 15.0, } ); mirrorMesh = new THREE.Mesh( new THREE.PlaneGeometry( 4400, 4400,120,120 ), water.material ); mirrorMesh.add( water ); mirrorMesh.rotation.x = - Math.PI * 0.5; scene.add( mirrorMesh ); v = mirrorMesh.geometry.vertices; //LIGHT var ambient = new THREE.AmbientLight( 0xf5ebce, 0.25 ); scene.add(ambient); light = new THREE.DirectionalLight( 0xf5ebce, 0.8 ); light.position.set( 0, 0, 0 ); light.castShadow = true; light.shadow = new THREE.LightShadow( new THREE.PerspectiveCamera( 40, .7, 4000, 4800 ) ); light.shadow.bias = 0.0000001; light.shadow.mapSize.width = 2048; light.shadow.mapSize.height = 2048; scene.add( light ); n = 110; var elementMaterial = new THREE.MeshPhongMaterial( { specular: 0xf5ebce, shininess: 23,specularMap:rusty, shading: THREE.FlatShading,map:rusty } ); for (var i = n - 1; i >= 0; i--) { var elementGeometry = new THREE.CylinderGeometry( 5, 5, (random(i)+1) *50, 4 ); var addU = Math.random(); var addV = Math.random(); for ( var z = 0; z < elementGeometry.faces.length; z ++ ) { elementGeometry.faceVertexUvs[ 0 ][ z ][ 0 ].x += addU; elementGeometry.faceVertexUvs[ 0 ][ z ][ 0 ].y += addV; elementGeometry.faceVertexUvs[ 0 ][ z ][ 1 ].x += addU; elementGeometry.faceVertexUvs[ 0 ][ z ][ 1 ].y += addV; elementGeometry.faceVertexUvs[ 0 ][ z ][ 2 ].x += addU; elementGeometry.faceVertexUvs[ 0 ][ z ][ 2 ].y += addV; } elementGeometry.uvsNeedUpdate = true; var element = new THREE.Mesh(elementGeometry, elementMaterial); scene.add(element); element.position.y= elementGeometry.parameters.height/2 -5; element.position.x = (random(i+214)-.5)* 1500; element.position.z = -random(i*35) * 1500 -100; element.rotation.set(random(i)*Math.PI/20,0,0); element.receiveShadow = true; element.castShadow = true; }
}
//
function animate() { var delta = clock.getDelta(); time += delta * 0.5; for (var i = v.length - 1; i >= 0; i--) { v[i].z =Math.sin(i*1+time*-1)*3; } camera.position.y=v[7320].z*1.5 +14; mirrorMesh.geometry.verticesNeedUpdate = true; moveSun(); water.material.uniforms.time.value -= 1.0 / 60.0; water.sunDirection = sky.uniforms.sunPosition.value.normalize()//sunSphere.position.normalize() light.position.copy( sunSphere.position); water.render(); requestAnimationFrame( animate ); renderer.render( scene, camera ); window.addEventListener('resize', onWindowResize, false);
}
function random(seed) { var x = Math.sin(seed) * 10000; return x - Math.floor(x);
}
function onWindowResize() { camera.aspect = window.innerWidth / window.innerHeight; camera.updateProjectionMatrix(); renderer.setSize( window.innerWidth, window.innerHeight );
}
Developer | XORXOR |
Username | xorxor_hu |
Uploaded | January 27, 2023 |
Rating | 4.5 |
Size | 3,612 Kb |
Views | 4,048 |
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!
Name | Size |
Birds | 5,934 Kb |
Pastel Pump | 3,763 Kb |
Morphing Tubes | 3,406 Kb |
Pipes | 3,300 Kb |
Grid of Birds | 3,512 Kb |
The Walking Raymarcher | 7,934 Kb |
Complex Form with Black and White Spirals | 3,340 Kb |
Complex Form with Black and White Bands | 3,209 Kb |
Cubic Tunnel | 4,791 Kb |
Kaleidoscope | 3,536 Kb |
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!
Name | Username | Size |
Tooltip in table | Roine | 3,713 Kb |
Adding and Removing Element | Accimeesterlin | 2,119 Kb |
Pure CSS Torch Light | Juliendargelos | 2,727 Kb |
Blank Starter | Mhartington | 2,171 Kb |
Pure CSS Dial | Lukewatts | 3,018 Kb |
Responsive Advert | James_zedd | 2,354 Kb |
Apex Calculator | Michaelwnelson | 2,370 Kb |
Funny menu | AxeLVaisper | 4,671 Kb |
Example SVGZ Data URI | Joeyhoer | 2,981 Kb |
Update CSS Variables with JS | Wesbos | 2,335 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!