Changing Terrain Experiment
How do I make an changing terrain experiment?
What is a changing terrain experiment? How do you make a changing terrain experiment? This script and codes were developed by Ben Matthews on 10 September 2022, Saturday.
Changing Terrain Experiment - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Changing Terrain Experiment</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <script src='https://github.com/processing/p5.js/releases/download/0.5.6/p5.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.6.2/dat.gui.js'></script> <script src="js/index.js"></script>
</body>
</html>
Changing Terrain Experiment - Script Codes CSS Codes
* { margin:0; padding:0; }
html, body { width:100%; height:100%; }
canvas { display:block; }
Changing Terrain Experiment - Script Codes JS Codes
window.addEventListener('resize', resize, false);
var cellSize = 30;
var xOff = 2*cellSize*Math.sqrt(3)/3;
var yOff = cellSize*Math.sqrt(3)/3;
var heightDivisions = 10;
var noiseScale = .005;
var heightScale = 1.8;
var colorScale = 1;
var speed = .01;
var z = 0;
var colors = [];
var hexes = [];
var gridWidth, gridHeight;
function Point(x, y){ this.x = x; this.y = y;
}
function Hex(p){ this.center = p; this.height = round(pow(noise(p.x*noiseScale, p.y*noiseScale, z), heightScale)*heightDivisions);
}
Hex.prototype.tick = function(){ var p = this.center; this.height = round(pow(noise(p.x*noiseScale, p.y*noiseScale, z), heightScale)*heightDivisions);
}
Hex.prototype.render = function(){ fill(colors[this.height]); ellipse(this.center.x, this.center.y, cellSize)
}
function setup(){ colorMode(HSB, 100, 100); createCanvas(); resize(); gridWidth = floor(width/cellSize); gridHeight = floor(height/cellSize); createColors(); createHexes(); background(0); var gui = new dat.GUI(); gui.add(this, "noiseScale", .001, .05, .003); gui.add(this, "heightScale", .2, 5, .003); gui.add(this, "speed", 0, 1, .003);
}
function createHexes(){ hexes = []; for (var i = 0; i <= gridWidth; i++){ for (var j = 0; j <= gridHeight+1; j++){ var x = i*cellSize; var y = j*cellSize; if (j%2 == 0) x += cellSize/2; var p = new Point(x, y); var hex = new Hex(p); hexes.push(hex); } }
}
function createColors(){ for (var i = 0; i < heightDivisions; i++){ var satbal = pow((i/heightDivisions), colorScale)*100; var c = color(120, 100 - satbal, satbal); colors.push(c); }
}
function draw(){ if (hexes == undefined) return; for (var i = 0; i < hexes.length; i++){ hexes[i].tick(); hexes[i].render(); } z += speed; // noLoop();
}
function resize(){ resizeCanvas(window.innerWidth, window.innerHeight); background(0);
}
Developer | Ben Matthews |
Username | tsuhre |
Uploaded | September 10, 2022 |
Rating | 4 |
Size | 2,337 Kb |
Views | 32,384 |
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 |
Zelda BOTW Sheikah Language | 4,039 Kb |
Voronoi Pursuit Curves | 4,234 Kb |
Flame Animation Test 1 | 2,257 Kb |
Tree Generator V2 | 5,891 Kb |
Ellipses | 2,312 Kb |
Fractal Fun | 3,965 Kb |
Maze Runners | 3,628 Kb |
GameBunny1 | 2,270 Kb |
Prisms | 0 Kb |
Ribbons | 2,140 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 |
SVG Animation | Pollardld | 3,133 Kb |
A Pen by aleen42 | Aleen42 | 11,473 Kb |
Mobile Nav Menu | AliKlein | 4,745 Kb |
Update CSS Variables with JS | Wesbos | 2,335 Kb |
Slide like Mailbox | Hmps | 3,758 Kb |
Base64 SVG Me | MrBambule | 44,786 Kb |
CSS Letter animations | Sladix | 2,116 Kb |
Portfolio Layout Flex | Lahvjal | 3,489 Kb |
Simple blog concept | Drew_mc | 2,666 Kb |
Blank Starter | Mhartington | 2,171 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!