summaryrefslogtreecommitdiff
path: root/js/modularcircles.js
diff options
context:
space:
mode:
authorpommicket <leonardomtenenbaum@gmail.com>2016-07-01 17:43:58 -0400
committerpommicket <leonardomtenenbaum@gmail.com>2016-07-01 17:43:58 -0400
commitbe06edbcfd1213ea1658d36f8934493a92205aac (patch)
tree28dca6130833e3a770611961bc6559c08bed4161 /js/modularcircles.js
Created pommicket.github.io
Diffstat (limited to 'js/modularcircles.js')
-rw-r--r--js/modularcircles.js54
1 files changed, 54 insertions, 0 deletions
diff --git a/js/modularcircles.js b/js/modularcircles.js
new file mode 100644
index 0000000..8b588f9
--- /dev/null
+++ b/js/modularcircles.js
@@ -0,0 +1,54 @@
+function setup()
+{
+ createCanvas(600, 600);
+}
+
+function nPoints()
+{
+ return document.getElementById("npoints").value;
+}
+
+function shouldMul()
+{
+ return document.getElementById("should_mul").checked;
+}
+
+function amount()
+{
+ return parseFloat(document.getElementById("amount").value);
+}
+
+function getPos(number)
+{
+ angle = 2*PI * number/(nPoints());
+ return [cos(angle)*250+300, sin(angle)*250+300];
+}
+
+function draw()
+{
+ if (shouldMul())
+ document.getElementById("amount").step = 0.1;
+ else
+ document.getElementById("amount").step = 1;
+ background(255);
+ ellipseMode(CENTER);
+ noStroke();
+ fill(0);
+ for (var i = 0; i < nPoints(); i++)
+ ellipse(getPos(i)[0], getPos(i)[1], 3, 3);
+
+ stroke(0);
+ for (var i = 0; i < nPoints(); i++)
+ {
+ if (shouldMul())
+ {
+ stroke(map(map((amount()*i)%nPoints(), 0, nPoints(), 0, 256) - map(i, 0, nPoints(), 0, 256), -256, 256, 0, 256), map(i, 0, nPoints(), 0, 256), map((amount()*i)%nPoints(), 0, nPoints(), 0, 256));
+ line(getPos(i)[0], getPos(i)[1], getPos((amount()*i)%nPoints())[0], getPos((amount()*i)%nPoints())[1]);
+ }
+ else
+ {
+ stroke(0, map(i, 0, nPoints(), 0, 256), map((amount()+i)%nPoints(), 0, nPoints(), 0, 256));
+ line(getPos(i)[0], getPos(i)[1], getPos((amount()+i)%nPoints())[0], getPos((amount()+i)%nPoints())[1]);
+ }
+ }
+} \ No newline at end of file