From a28e6926d0b3406bbc4c0f99f956d1342f0f26e6 Mon Sep 17 00:00:00 2001 From: 123niel Date: Tue, 22 Jan 2019 18:24:41 +0100 Subject: [PATCH] added gitignore and koch --- .gitignore | 1 + koch/index.html | 14 ++++++++++++++ koch/sketch.js | 44 +++++++++++++++++++++++++++++++++++++++++++ sierpinski/index.html | 1 - 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 koch/index.html create mode 100644 koch/sketch.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1d74e21 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.vscode/ diff --git a/koch/index.html b/koch/index.html new file mode 100644 index 0000000..5f4c71e --- /dev/null +++ b/koch/index.html @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/koch/sketch.js b/koch/sketch.js new file mode 100644 index 0000000..e325ea4 --- /dev/null +++ b/koch/sketch.js @@ -0,0 +1,44 @@ +let v1, v2; + +function setup() { + createCanvas(800, 300); + v1 = createVector(50, 250); + v2 = createVector(750, 250); + background(0); + stroke(255); + koch(v1, v2, 6); +} + +function koch(p1, p2, i) { + if (i === 1) connect(p1, p2); + else { + const {a, b, c, d, e} = generateEdges(p1, p2) + + koch(a, b, i-1) + koch(b, c, i-1) + koch(c, d, i-1) + koch(d, e, i-1) + } +} + +function connect(p1, p2) { + line(p1.x, p1.y, p2.x, p2.y); +} + +function generateEdges(p1, p2) { + let v = p5.Vector.sub(p2, p1); + v.div(3); + + let a = p1.copy(); + + let b = p5.Vector.add(p1, v); + + let d = p5.Vector.sub(p2, v); + + v.rotate(-PI/3); + let c = p5.Vector.add(b, v); + + e = p2.copy(); + + return {a, b, c, d, e} +} diff --git a/sierpinski/index.html b/sierpinski/index.html index f870a58..5f4c71e 100644 --- a/sierpinski/index.html +++ b/sierpinski/index.html @@ -4,7 +4,6 @@ -