Skip to content

Instantly share code, notes, and snippets.

@lee2sman
Created April 3, 2018 08:30
Show Gist options
  • Save lee2sman/f0ade10f36394c2ad5fa5ad17af0e2d1 to your computer and use it in GitHub Desktop.
Save lee2sman/f0ade10f36394c2ad5fa5ad17af0e2d1 to your computer and use it in GitHub Desktop.
a very simple terrain generator in p5js
let rows = 16, cols = 9, xStep, yStep;
let c = ['DeepSkyBlue','forestgreen','Sienna','BurlyWood'];
function setup() {
createCanvas(windowWidth, windowHeight);
xStep = width/cols;
yStep = height/rows;
for (let x = 0; x < width; x+=xStep){
for (let y = 0; y < height; y +=yStep){
stroke(0);
stroke(150);
strokeWeight(2);
let dieroll = floor(random(c.length));
fill(color(c[dieroll]));
rect(x,y, xStep, yStep);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment