Created
March 29, 2021 04:52
-
-
Save cesarmiquel/95dca0e2e05eb765a88de41c41a0178e to your computer and use it in GitHub Desktop.
Toroid p5js experiment #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function setup() { | |
createCanvas(800, 800, WEBGL); | |
} | |
function draw() { | |
background("#111515"); | |
let scaleFactor = 1; | |
let R = 200; | |
let r = 60; | |
let n1 = 17; | |
let n2 = 57; | |
let c6 = ["ff595e","ffca3a","8ac926","1982c4","6a4c93"]; | |
let colors = c6.map(function(i) { return '#' + i; }); | |
strokeWeight(3); | |
noFill(); | |
scale(scaleFactor); | |
i = 0; | |
for(t = 0; t < 1031; t++) { | |
if (t%30 == 0) { | |
beginShape(); | |
} | |
let th = (t % n1) * 2 * PI / n1; | |
let phi = (t % n2) * 2 * PI / n2; | |
let x = R*cos(phi) + r*cos(phi)*cos(th); | |
let y = R*sin(phi) + r*sin(phi)*cos(th); | |
let z = r*sin(th); | |
curveVertex(x,y,z); | |
if (t%30 == 29) { | |
endShape(); | |
stroke(colors[i % colors.length]); | |
i++; | |
} | |
} | |
// draw palette | |
for(j = 0; j < colors.length; j++) { | |
fill(colors[j]); | |
stroke(colors[j]); | |
square((j+1)*30, 300, 20); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment