nature-of-code/0. Randomness/10. Perlin elevated/sketch.js

44 lines
895 B
JavaScript

let t = 0
let animationSpeed = 0.0008
function setup() {
createCanvas(640, 240, WEBGL)
pixelDensity(1)
}
function draw() {
background(255);
let pointsX = 20
let pointsY = 40
let pointGap = 10
let zs = []
for (let y = 0; y < pointsY+1; y++) {
for (let x = 0; x < pointsX; x++) {
let increment = 0.1
zs.push(noise(x*increment, y*increment, t*animationSpeed))
}
}
push()
rotateX(PI/3)
rotateZ(0.0001*t)
scale(pointGap)
translate(-pointsX/2, -pointsY/2, 0)
for (let y = 0; y < pointsY; y++) {
beginShape(QUAD_STRIP)
for (let x = 0; x < pointsX; x++) {
fill(zs[x + y * pointsX] * 255, 255)
vertex(x, y, zs[x + y * pointsX] * 10)
vertex(x, y+1, zs[x + (y+1) * pointsX] * 10)
}
endShape()
}
pop()
t += deltaTime
}