Created
February 24, 2020 12:57
-
-
Save Nekodigi/2d9937512295df3932e85bd2bac9c8ab to your computer and use it in GitHub Desktop.
This file contains 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
float r0 = 200; | |
float r1 = 100; | |
float n1 = 1, n2 = 1; | |
int NI = 100, NJ = 100; | |
PVector[][] poss = new PVector[NI][NJ]; | |
void setup(){ | |
size(700, 700, P3D); | |
//fullScreen(P3D); | |
colorMode(HSB, 360, 100, 100); | |
} | |
void draw(){ | |
n1 = map(mouseX, 0, width, 0, 5); | |
n2 = map(mouseY, 0, height, 0, 4); | |
background(360); | |
lights(); | |
noStroke(); | |
translate(width/2, height/2); | |
rotateX((float)frameCount/100); | |
rotateY((float)frameCount/100); | |
rotateZ((float)frameCount/100); | |
for(int i = 0; i < NI; i++){ | |
float theta = map(i, 0, NI, 0, TWO_PI); | |
for(int j = 0; j < NJ; j++){ | |
float phi = map(j, 0, NJ, 0, TWO_PI); | |
float x = C(theta, n1)*(r0+r1*C(phi, n2)); | |
float y = S(theta, n1)*(r0+r1*C(phi, n2)); | |
float z = r1*S(phi, n2); | |
poss[i][j] = new PVector(x, y, z); | |
} | |
} | |
beginShape(TRIANGLE_STRIP); | |
for(int i = 0; i < NI; i++){ | |
for(int j = 0; j < NJ; j++){ | |
PVector pa = poss[i][j]; | |
PVector pb = poss[(i+1)%NI][j]; | |
float hue = map(i, 0, NI, 0, 360)+frameCount*2; | |
fill(hue%360, 100, 100); | |
vertex(pa.x, pa.y, pa.z); | |
vertex(pb.x, pb.y, pb.z); | |
//point(pa.x, pa.y, pa.z); | |
} | |
} | |
PVector pa = poss[0][0]; | |
PVector pb = poss[1][0]; | |
vertex(pa.x, pa.y, pa.z); | |
vertex(pb.x, pb.y, pb.z); | |
endShape(); | |
} | |
//based on wikipedia https://en.wikipedia.org/wiki/Supertoroid | |
float C(float theta, float degree){ | |
return sgn(cos(theta))*pow(abs(cos(theta)), degree); | |
} | |
float S(float theta, float degree){ | |
return sgn(sin(theta))*pow(abs(sin(theta)), degree); | |
} | |
float sgn(float x){ | |
if(x < 0) return -1; | |
else if(x == 0) return 0; | |
else return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment