City generator
How do I make an city generator?
A collection of small dystopias hit space to regenerate. What is a city generator? How do you make a city generator? This script and codes were developed by Khalkeus on 11 November 2022, Friday.
City generator - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>city generator</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <!-- space to regen --> <script src='https://cdnjs.cloudflare.com/ajax/libs/three.js/84/three.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
City generator - Script Codes CSS Codes
body, html{ width: 100%; height: 100%; margin: 0px; padding: 0px; overflow: hidden;
}
City generator - Script Codes JS Codes
var renderer, scene, camera, world;
// Handle resizing the window so that the aspect ratio is maintained
window.onresize = function () { camera.aspect = window.innerWidth/window.innerHeight; camera.updateProjectionMatrix(); renderer.setSize(window.innerWidth, window.innerHeight);
}
// Utilities
function randomFloat(a, b){ var r = (Math.random() * (b - a) + a); return r;
}
function clamp(num, min, max){ return Math.min(Math.max(num, min), max);
}
function World() { this.bgColors = [[10, 10, 55], [55, 33, 22], [99, 99, 255]]; this.obj = new THREE.Group(); this.dirLight; this.init = function() { var citySize = randomFloat(5, 30); var density = Math.random() + .2; // Ground var mat = new THREE.MeshLambertMaterial({color: 0xff0000, emissive: 0x110033}); var o = new THREE.Mesh(new THREE.PlaneGeometry(500, 500), mat.clone()); // o.material.color.setHex(0xffffff); o.rotation.x = -Math.PI/2; o.receiveShadow = true; o.castShadow = false; this.obj.add(o); var block = new THREE.Mesh(new THREE.BoxGeometry(.8, 1, .8), mat); block.castShadow = true; block.receiveShadow = true; for(var x = 0; x < citySize; x++){ for(var z = 0; z < citySize; z++){ if(Math.random() * ((x - citySize/2)*(x - citySize/2) + (z - citySize/2)*(z - citySize/2))/20 < density){ var newBlock = block.clone(); newBlock.position.set(x - citySize/2, 0, z - citySize/2); newBlock.scale.y = randomFloat(.1, .5) * (citySize/((x - citySize/2)*(x - citySize/2) + (z - citySize/2)*(z - citySize/2))); newBlock.scale.y = clamp(newBlock.scale.y, .1, 50); if(Math.random() < .1){ newBlock.scale.x = randomFloat(.1, 5); } if(Math.random() < .1){ newBlock.scale.z = randomFloat(.1, 5); } this.obj.add(newBlock); } } } scene.add(this.obj); } this.init();
}
window.onkeydown = function (e) { console.log(e.keyCode); if(e.keyCode === 32){ scene.remove(world.obj); world = new World(); }
}
// Set up three js scene
window.onload = function(){ renderer = new THREE.WebGLRenderer({antialias: true}); renderer.shadowMapEnabled = true; scene = new THREE.Scene(); camera = new THREE.PerspectiveCamera(20, window.innerWidth/window.innerHeight, 0.1, 1000); renderer.setSize(window.innerWidth, window.innerHeight); document.body.appendChild(renderer.domElement); camera.position.z = 100; camera.position.y = 50; camera.rotation.x = -0.785398/2; scene.add(new THREE.AmbientLight(0x666666)); var dirLight = new THREE.DirectionalLight( 0xffffff, 2, 5000); dirLight.position.set(-50, 25, 0); dirLight.shadow.mapSize.width = 4096; dirLight.shadow.mapSize.height = 4096; dirLight.castShadow = true; scene.add(dirLight); var dlSub = new THREE.DirectionalLight(0xff00ff, .5, 500); dlSub.position.set(-5, -5, -5); scene.add(dlSub); scene.rotation.y = Math.PI/4; scene.background = new THREE.Color(0xff0000); world = new World(); render();
}
var render = function (){ requestAnimationFrame(render); renderer.render(scene, camera);
}
Developer | Khalkeus |
Username | khalkeus |
Uploaded | November 11, 2022 |
Rating | 4 |
Size | 2,750 Kb |
Views | 6,072 |
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 |
Fish pond | 3,799 Kb |
Random walkers | 2,512 Kb |
Metaballs | 2,277 Kb |
Square loading icons | 2,249 Kb |
Color Name Game | 3,245 Kb |
Boids i | 3,564 Kb |
Particle fire | 3,152 Kb |
Boids iii | 2,947 Kb |
Boids ii | 3,358 Kb |
Css loaders ii | 2,294 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 |
After America | Jonathangarner | 2,686 Kb |
Barber Shop | Bhlaird | 6,270 Kb |
Material design - button rainbow circle | Kunukn | 3,652 Kb |
Vue Transition | Chenming142 | 4,561 Kb |
Super Discount | Orrinward | 3,225 Kb |
Amazing CSS Menu with Notification Badges | Faizanasad | 2,549 Kb |
AngularJS Datalist Directive | M-e-conroy | 2,366 Kb |
Faux column absolute wrapper | Yurimorini | 1,823 Kb |
Brian The CSS Bee | Jonitrythall | 3,922 Kb |
Another brick in the wall | Fivera | 1,955 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!