complete exercise 0.9
This commit is contained in:
parent
e24fc3db4f
commit
7601e5f8f8
15
0. Randomness/9. Perlin animated/index.html
Normal file
15
0. Randomness/9. Perlin animated/index.html
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/p5@1.9.0/lib/p5.js"></script>
|
||||||
|
<script src="sketch.js"></script>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
background: #212121;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<main>
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
30
0. Randomness/9. Perlin animated/sketch.js
Normal file
30
0. Randomness/9. Perlin animated/sketch.js
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
let increment = 0.01
|
||||||
|
let octaves = 8
|
||||||
|
let falloff = 0.4
|
||||||
|
|
||||||
|
let t = 0
|
||||||
|
let animationSpeed = 0.0005
|
||||||
|
|
||||||
|
function setup() {
|
||||||
|
createCanvas(640, 240)
|
||||||
|
pixelDensity(1)
|
||||||
|
noiseDetail(octaves, falloff)
|
||||||
|
}
|
||||||
|
|
||||||
|
function draw() {
|
||||||
|
loadPixels()
|
||||||
|
for (let x = 0; x < width; x++) {
|
||||||
|
for (let y = 0; y < height; y++) {
|
||||||
|
let index = (x + y * width) * 4
|
||||||
|
|
||||||
|
let noiseValue = noise(x*increment, y*increment, t*animationSpeed)
|
||||||
|
let bright = map(noiseValue, 0, 1, 0, 255)
|
||||||
|
pixels[index+0] = bright
|
||||||
|
pixels[index+1] = bright
|
||||||
|
pixels[index+2] = bright
|
||||||
|
pixels[index+3] = 255
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updatePixels()
|
||||||
|
t += deltaTime
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user