From 9651423ae5db9b8ca70e539c08d91dd2990713d2 Mon Sep 17 00:00:00 2001 From: Rokas Puzonas Date: Mon, 5 Feb 2024 20:09:44 +0200 Subject: [PATCH] complete exercise 0.1 --- 0. Randomness/1. Down Right Walker/index.html | 15 +++++++++ 0. Randomness/1. Down Right Walker/sketch.js | 32 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 0. Randomness/1. Down Right Walker/index.html create mode 100644 0. Randomness/1. Down Right Walker/sketch.js diff --git a/0. Randomness/1. Down Right Walker/index.html b/0. Randomness/1. Down Right Walker/index.html new file mode 100644 index 0000000..c390616 --- /dev/null +++ b/0. Randomness/1. Down Right Walker/index.html @@ -0,0 +1,15 @@ + + + + + + + +
+
+ + diff --git a/0. Randomness/1. Down Right Walker/sketch.js b/0. Randomness/1. Down Right Walker/sketch.js new file mode 100644 index 0000000..22ad061 --- /dev/null +++ b/0. Randomness/1. Down Right Walker/sketch.js @@ -0,0 +1,32 @@ +class Walker { + constructor(x = 0, y = 0) { + this.x = x + this.y = y + } + + step() { + let dx = min(floor(random(4)) - 1, 1); + let dy = min(floor(random(4)) - 1, 1); + + 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(); +}