PImage[] textures = new PImage[6];
Ribbon[] ribbons = new Ribbon[20];
int colMode = 2;
boolean group = false;
void setup()
{
size(800,500,P3D);
for(int i=0;i<textures.length;i++)
{
textures[i] = loadImage("0"+(i+1)+".gif");
}
for(int i=0;i<ribbons.length;i++)
{
ribbons[i] = new Ribbon();
}
background(255);
}
void draw()
{
if(random(1)>0.995) group = !group;
background(255);
pushMatrix();
translate(width/2,height/2,-500);
rotateX(-0.5);
for(int i=0;i<ribbons.length;i++)
{
ribbons[i].update();
}
popMatrix();
}
void mousePressed()
{
colMode++;
colMode%=3;
}
class Segment
{
float x,y,z;
float x2,y2,z2;
PImage img;
Segment prev;
int num;
Segment(float _x, float _y, float _z, float _x2, float _y2, float _z2, int _num)
{
x = _x;
y = _y;
z = _z;
x2 = _x2;
y2 = _y2;
z2 = _z2;
img = textures[_num];
num = _num;
}
void render()
{
switch(colMode)
{
case 0:
stroke(0);
fill(255);
beginShape(QUADS);
vertex(x,y-100,z);
vertex(x,y,z);
vertex(x2,y2,z2);
vertex(x2,y2-100,z2);
endShape();
break;
case 1:
stroke(255);
fill(0,200);
beginShape(QUADS);
vertex(x,y-100,z);
vertex(x,y,z);
vertex(x2,y2,z2);
vertex(x2,y2-100,z2);
endShape();
break;
case 2:
stroke(0);
textureMode(NORMALIZED);
beginShape(QUADS);
texture(img);
vertex(x,y-100,z,0,0);
vertex(x,y,z,0,1);
vertex(x2,y2,z2,1,1);
vertex(x2,y2-100,z2,1,0);
endShape();
}
}
}
class Ribbon
{
float x,y,z;
float seed;
ArrayList segments;
color tintcolor;
Ribbon()
{
tintcolor = color(random(255));
x = 0;
y = random(-width/2,width/2);
z = 0;
seed = random(10000);
segments = new ArrayList();
float _x = x;
float _z = z;
for(int i=0;i<textures.length;i++)
{
float degree = random(TWO_PI);
Segment temp_pt = new Segment(_x,y,_z,_x+sin(degree)*150,y,_z+cos(degree)*150,i);
_x += sin(degree)*150;
_z += cos(degree)*150;
segments.add(temp_pt);
}
}
void render()
{
for(int i=0;i<segments.size();i++)
{
Segment temp = (Segment)segments.get(i);
temp.render();
}
}
void update()
{
float _x,_z;
float degree;
Segment temp = (Segment)segments.get(0);
if(mousePressed)
{
temp.x += (mouseX-pmouseX)*2;
temp.z += (mouseY-pmouseY)*2;
}
else if(group)
{
temp.x+=(noise((frameCount)*0.01)-0.5)*300;
temp.z+=(noise((-frameCount)*0.01)-0.5)*300;
temp.x +=(0-temp.x)*0.01;
temp.z +=(0-temp.z)*0.01;
}
else
{
temp.x+=(noise((seed+frameCount)*0.003)-0.5)*150;
temp.z+=(noise((seed-frameCount)*0.003)-0.5)*150;
temp.x +=(0-temp.x)*0.02;
temp.z +=(0-temp.z)*0.02;
}
degree = atan2((temp.z2-temp.z),(temp.x2-temp.x));
temp.x2 = temp.x+cos(degree)*150;
temp.z2 = temp.z+sin(degree)*150;
_x = temp.x2;
_z = temp.z2;
tint(tintcolor);
for(int i=1;i<segments.size();i++)
{
temp = (Segment)segments.get(i);
temp.x = _x;
temp.z = _z;
degree = atan2(-(temp.z-temp.z2),-(temp.x-temp.x2));
temp.x2 = temp.x+cos(degree)*150;
temp.z2 = temp.z+sin(degree)*150;
_x = temp.x2;
_z = temp.z2;
}
render();
}
}