Skip to content

Instantly share code, notes, and snippets.

@modiprabal
Last active November 25, 2020 07:05
Show Gist options
  • Save modiprabal/9284a9392790af24ea84d42bb06efe3c to your computer and use it in GitHub Desktop.
Save modiprabal/9284a9392790af24ea84d42bb06efe3c to your computer and use it in GitHub Desktop.
TubeCircle
import peasy.*;
boolean pcam = true, record = false;
PeasyCam cam;
PFont font;
color c1, c2;
TubeCircle tube1;
void settings(){
System.setProperty("jogl.disable.openglcore", "true");
size(displayHeight, displayHeight, P3D);
}
void setup()
{
if(pcam)
{
cam = new PeasyCam(this, 0, 0, 0, 1000);
}
font = loadFont("CharterBT-BoldItalic-25.vlw");
textFont(font);
tube1 = new TubeCircle(350, 100, 15, 1.55);
strokeWeight(3);
fill(178, 255, 241);
textAlign(LEFT, BOTTOM);
c1 = color(178, 255, 241);
c2 = color(#CEBFFF);
}
float rotateDegree=0, rotateSpeed = 1;
void draw()
{
ortho();
if(!pcam)
{
translate(width/2, height/2);
}
background(#FFFCB9);
fill(0);
text("@modiprabal", -width/2+10, height/2-70);
rotate(radians(rotateDegree));
rotateDegree = (rotateDegree + rotateSpeed)%361;
fill(c2);
push();
rotateX(radians(45));
//translate(0,-r);
tube1.showRightSemiTube();
pop();
push();
rotateX(-radians(45));
//translate(0,-r);
tube1.showLeftSemiTube();
pop();
if(record) save();
}
void save()
{
saveFrame("img###.png");
if(rotateDegree==180) exit();
}
class TubeCircle
{
float radius, boxLength, strips = 20, compressionRatio = 2;
TubeCircle(float radius)
{
this.radius = radius;
this.boxLength = 20;
}
TubeCircle(float radius, float boxLength)
{
this.radius = radius;
this.boxLength = boxLength;
}
TubeCircle(float radius, float boxLength, float strips, float compressionRatio)
{
this.radius = radius;
this.boxLength = boxLength;
this.strips = strips;
this.compressionRatio = compressionRatio;
}
void showTube()
{
for(int i=0; i<100; i++)
{
push();
rotate(TAU*i/100);
translate(0, radius);
box(boxLength/compressionRatio, boxLength, boxLength);
pop();
}
}
void showLeftSemiTube()
{
for(int i=0; i<strips; i++)
{
push();
rotate(PI*i/strips);
translate(0, radius);
box(boxLength/compressionRatio, boxLength, boxLength);
pop();
}
}
void showRightSemiTube()
{
for(int i=0; i<strips; i++)
{
push();
rotate(PI*i/strips);
translate(0, -radius);
box(boxLength/compressionRatio, boxLength, boxLength);
pop();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment