Created
March 29, 2021 04:15
-
-
Save cesarmiquel/9f8917ceb50b4c1eef2060ce78e9410e to your computer and use it in GitHub Desktop.
Toroid p5js experiment #1
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 = 2; | |
let R = 100; | |
let r = 30; | |
let n1 = 17; | |
let n2 = 57; | |
let colors = | |
[ | |
"#16697a", | |
"#489fb5", | |
"#82c0cc", | |
"#ede7e3", | |
"#ffa62b" | |
]; | |
rotateX(frameCount * 0.05); | |
rotateY(frameCount * 0.02); | |
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++; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment