From e964c1497433af15ef5781e6c1bdc447c7432865 Mon Sep 17 00:00:00 2001 From: Rokas Puzonas Date: Mon, 5 Feb 2024 21:29:51 +0200 Subject: [PATCH] complete exercise 0.5 --- 0. Randomness/5. Gaussian Walker/index.html | 15 ++++++++++ 0. Randomness/5. Gaussian Walker/sketch.js | 32 +++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 0. Randomness/5. Gaussian Walker/index.html create mode 100644 0. Randomness/5. Gaussian Walker/sketch.js diff --git a/0. Randomness/5. Gaussian Walker/index.html b/0. Randomness/5. Gaussian Walker/index.html new file mode 100644 index 0000000..c390616 --- /dev/null +++ b/0. Randomness/5. Gaussian Walker/index.html @@ -0,0 +1,15 @@ + + + + + + + +
+
+ + diff --git a/0. Randomness/5. Gaussian Walker/sketch.js b/0. Randomness/5. Gaussian Walker/sketch.js new file mode 100644 index 0000000..1e15674 --- /dev/null +++ b/0. Randomness/5. Gaussian Walker/sketch.js @@ -0,0 +1,32 @@ +class Walker { + constructor(x = 0, y = 0) { + this.x = x + this.y = y + } + + step() { + let dx = randomGaussian(); + let dy = randomGaussian(); + + this.x += dx + this.y += dy + } + + draw() { + stroke(0) + point(this.x, this.y) + } +} + +let walker + +function setup() { + createCanvas(640, 240) + background(255) + walker = new Walker(320, 120) +} + +function draw() { + walker.step(); + walker.draw(); +}