xxxxxxxxxx
75
// Random Map Generator Code from "Mapping Imaginary Places"
// Emily Bowe
// Edit the canvas values to see how things change
let canvasWidth = 800;
let canvasHeight = 600
let pixelSize = 30;
let terrainCutoff = 0.5;
// The setup() function is what 1) creates the drawing canvas and 2) creates the sliders
function setup(){
// This function creates the canvas and sets it to the width and height values set above
createCanvas(canvasWidth,canvasHeight);
// This line sets the color mode to HSB and rescales it to values from 1 to 100
colorMode(HSB, 100);
//These sliders help to control some variables to play with
createP('Map Scale');
scale_slider = createSlider(0.01, 0.1, 0.01, 0.01);
createP('Noise Adjustment #1 (Octaves)');
octaves_slider = createSlider(1, 9, 5, 1);
createP('Noise Adjustment #2 (Falloff)');
falloff_slider = createSlider(0.05, 1, 0.52, 0.01);
}
function draw() {
//What happens if you comment out the line below?
noStroke();
// The next three lines use the sliders to set the values for
mapScale = scale_slider.value();
octaves = octaves_slider.value();
falloff = falloff_slider.value();
// This line sets the values for noiseDetail: https://p5js.org/reference/#/p5/noiseDetail
noiseDetail(octaves, falloff);
// This is where the map is being created
// First, the program loops across rows (the y values)
for(y=0; y<height; y+=pixelSize){
// Then the program loops across columns (the x values)
for (var x= 0; x<width; x+=pixelSize){
// The noise values for each pixel are here
terrain = noise(x*mapScale, y*mapScale);
// The next three lines set which values are "land" colors
if (terrain < terrainCutoff){
terrainColor = map(terrain, 0, 1, 60, 75)
fill(terrainColor, 100, 50);
rect(x,y,pixelSize,pixelSize);
//This section creates the "water" colors
} else if (terrain >= terrainCutoff){
terrainColor = map(terrain, 0, 1, 30, 60)
fill(terrainColor, 100, 50);
rect(x,y,pixelSize,pixelSize);
}
//What happens if you uncomment out the section below?
// else if (terrain>=0.55){
// terrainColor = map(terrain, 0, 1, 0, 25)
// fill(terrainColor, 100, 50);
// rect(x,y,pixelSize,pixelSize);
// }
};
};
}