Skip to content

Commit

Permalink
added function to generate terain height
Browse files Browse the repository at this point in the history
  • Loading branch information
ToMaarton committed Jan 25, 2024
1 parent 6eced80 commit 01ab38f
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions sketch.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
let heightmap;
function setup() {
createCanvas(400, 400);
createCanvas(600,600);
heightmap = generateHeightMap(600,0.02);
}

function draw() {
background(220);
background(0);
image(heightmap,0,0);
print('img');
noLoop();
}

function generateHeightMap(size, roughness){
noiseDetail(2,0.5)
let img = createImage(width, height);
img.loadPixels();
for (let x = 0; x < img.width; x += 1) {
for (let y = 0; y < img.height; y += 1) {
let nx = x*roughness;
let ny = y*roughness;
img.set(x, y, noise(nx,ny)*255-dist(width/2,height/2,x,y) *(255/(size/2)));
}
}
img.updatePixels();
return img;
}

0 comments on commit 01ab38f

Please sign in to comment.