complete exercise 1.2
This commit is contained in:
parent
5ddad8d145
commit
ba0dec0bb4
15
1. Vectors/2. Perlin Walker/index.html
Normal file
15
1. Vectors/2. Perlin Walker/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>
|
32
1. Vectors/2. Perlin Walker/sketch.js
Normal file
32
1. Vectors/2. Perlin Walker/sketch.js
Normal file
@ -0,0 +1,32 @@
|
||||
class Walker {
|
||||
constructor(x = 0, y = 0) {
|
||||
this.t = createVector(0, 10000)
|
||||
this.pos = createVector(x, y)
|
||||
}
|
||||
|
||||
step() {
|
||||
let dx = map(noise(this.t.x), 0, 1, -1, 1)
|
||||
let dy = map(noise(this.t.y), 0, 1, -1, 1)
|
||||
|
||||
this.pos.add(createVector(dx, dy))
|
||||
this.t.add(createVector(0.01, 0.01))
|
||||
}
|
||||
|
||||
draw() {
|
||||
stroke(0)
|
||||
point(this.pos)
|
||||
}
|
||||
}
|
||||
|
||||
let walker
|
||||
|
||||
function setup() {
|
||||
createCanvas(640, 240)
|
||||
background(255)
|
||||
walker = new Walker(320, 120)
|
||||
}
|
||||
|
||||
function draw() {
|
||||
walker.step();
|
||||
walker.draw();
|
||||
}
|
Loading…
Reference in New Issue
Block a user