Seamless Möbius strip:
// Author: GLV
// Date: 2019-08-12
// Description: Seamless Mobius strip
// 2 extra transparent QUAD_STRIPS added to acheive this
PShape m;
float thX, thY, thZ;
float x, y, z;
int steps;
int addStep = 2; // Change this to -1, 0, 1, 2
public void settings()
{
size(1280, 1024, P3D);
}
public void setup()
{
ortho();
}
public void draw()
{
background(0);
lights();
surface.setTitle(str(frameRate));
thY += TAU/1000;
thX += TAU/2000;
thZ += TAU/1000;
pushMatrix();
translate(width/2, height/2);
rotateY(thY);
rotateX(thX);
rotateZ(thZ);
noStroke();
mobius(100, 300, 80, 0);
shape(m);
popMatrix();
}
public void mobius(int steps, float r, float v, float u)
{
m = createShape();
m.beginShape(QUAD_STRIP);
for (int step = 0; step < (steps+1) + addStep; step++) // 2 steps added for seamless mobius strip
{
u = step*(TAU/steps);
if (step > steps)
m.fill(color(255, 128, 0, 0)); //100% transparent
else
m.fill(color(255, 128, 0, 255)); //100% opaque
mobEq(r, -v, u);
m.vertex(x, y, z);
mobEq(r, v, u);
m.vertex(x, y, z);
}
m.endShape();
}
public void mobEq(float radius, float v, float u)
{
x = (radius + v * cos(u/2)) * cos(u);
y = (radius + v * cos(u/2)) * sin(u);
z = v * sin(u/2);
}