Skip to content

Instantly share code, notes, and snippets.

@camb416
Created October 26, 2015 21:46
Show Gist options
  • Save camb416/ab1cb1f86ca7278ff825 to your computer and use it in GitHub Desktop.
Save camb416/ab1cb1f86ca7278ff825 to your computer and use it in GitHub Desktop.
float x;
float y;
float z;
float outsideRadius = 150;
float insideRadius = 100;
class Point{
float x,y,z;
Point(float _x, float _y, float _z){
x = _x;
y = _y;
z = _z;
}
Point(){
x = y = z = 0;
}
}
class Ribbon{
Point origin;
Point [] pts;
int numPts;
Ribbon(int _numPts){
numPts = _numPts;
pts = new Point[numPts];
origin = new Point();
}
void setup(float _x,float _y,float _z){
origin.x = _x;
origin.y = _y;
origin.z = _z;
float angle = random(360);
float angleStep = random(180.0/numPts*10);
for (int i = 0; i < numPts; i+=2) {
//float px = x + cos(radians(angle)) * outsideRadius;
//float py = y + sin(radians(angle)) * outsideRadius;
float px = -(numPts/2.0*15.0)+15.0*i;
float py = y+sin(radians(angle))*30.0;
float pz = z+cos(radians(angle))*30.0;
angle += angleStep;
pts[i] = new Point(px,py,pz);
//vertex(px, py, pz);
//px = x + cos(radians(angle)) * insideRadius;
//py = y + sin(radians(angle)) * insideRadius;
py = y+sin(radians(angle+180))*10;
pz = z+cos(radians(angle+180))*10;
pts[i+1] = new Point(px,py,pz);
//vertex(px, py,pz);
angle += angleStep;
}
}
void update(){
}
void draw(){
stroke(0);
beginShape(TRIANGLE_STRIP);
pushMatrix();
translate(origin.x,origin.y,origin.z);
for (int i = 0; i < numPts; i++) {
vertex(pts[i].x,pts[i].y, pts[i].z);
}
endShape();
popMatrix();
}
}
Ribbon r1,r2,r3;
void setup() {
size(1920,1080,P3D);
background(204);
x = 0;
y = 0;
z = 0;
r1 = new Ribbon(128);
r2 = new Ribbon(128);
r3 = new Ribbon(128);
r1.setup(0,-100,0);
r2.setup(0,0,0);
r3.setup(0,100,0);
}
void draw() {
background(204);
stroke(255,0,0);
line(0,0,0,100,0,0);
stroke(0,255,0);
line(0,0,0,0,100,0);
stroke(0,0,255);
line(0,0,0,0,0,100);
translate(width/2,height/2,0);
rotateY(mouseX/100.0);
rotateX(mouseY/100.0);
stroke(255,0,0);
line(0,0,0,100,0,0);
stroke(0,255,0);
line(0,0,0,0,100,0);
stroke(0,0,255);
line(0,0,0,0,0,100);
r1.draw();
r2.draw();
r3.draw();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment