class Cylinder
{
float topRadius;
float bottomRadius;
int sides = 30;
Particle a;
Particle b;
Cylinder(float _topRadius, float _bottomRadius, Particle _a, Particle _b)
{
a = _a;
b = _b;
topRadius =_topRadius;
bottomRadius = _bottomRadius;
}
void render()
{
float angle = 0;
float angleIncrement = TWO_PI / sides;
PVector c = new PVector(a.position().x()-b.position().x(),a.position().y()-b.position().y(),a.position().z()-b.position().z());
float h = dist(0,0,0,c.x,c.y,c.z);
float r = sqrt(pow(c.x,2)+pow(c.y,2)+pow(c.z,2));
float theta = atan2(c.y,c.x);
float phi = acos(c.z/r);
pushMatrix();
translate(b.position().x(),b.position().y(),b.position().z());
rotateZ(theta);
rotateY(phi);
rotateX(-HALF_PI);
beginShape(QUAD_STRIP);
texture(skin);
for (int i = 0; i < sides + 1; ++i) {
float u = skin.width / sides * i;
vertex(bottomRadius*cos(angle), h, bottomRadius*sin(angle), u, 0);
vertex(topRadius*cos(angle), -1, topRadius*sin(angle), u, skin.height);
angle += angleIncrement;
}
endShape();
popMatrix();
}
}
class Esphera
{
float radius = 10;
float u,x,y,z;
final int NUM_POINTS = 16;
PVector[] points = new PVector[NUM_POINTS];
Tentacle[] t = new Tentacle[NUM_POINTS];
PVector initialPos = new PVector(0, 0, 0);
Esphera()
{
for(int i = 0; i < NUM_POINTS; i++)
{
float theta = i/PI;
u = random(-1,1);
x = initialPos.x + radius*cos(theta)*sqrt(1-(u*u));
y = initialPos.y + radius*sin(theta)*sqrt(1-(u*u));
z = initialPos.z + u*radius;
points[i] = new PVector(x,y,z);
t[i] = new Tentacle();
}
}
void render()
{
for(int i = 0; i < points.length; i++)
{
PVector c = new PVector(initialPos.x-points[i].x,initialPos.y-points[i].y,initialPos.z-points[i].z);
float r = sqrt(pow(c.x,2)+pow(c.y,2)+pow(c.z,2));
float theta = atan2(c.y,c.x);
float phi = acos(c.z/r);
pushMatrix();
translate(-points[i].x,-points[i].y,-points[i].z);
rotateZ(theta);
rotateY(phi);
rotateX(-HALF_PI);
t[i].render();
popMatrix();
}
}
}
//import processing.video.*;
//MovieMaker mm;
import peasy.*;
import traer.physics.*;
float roty = 0.0;
Esphera e;
PeasyCam pCamera;
PImage skin;
void setup()
{
size(800, 600, P3D);
pCamera = new PeasyCam(this, 370);
e = new Esphera();
skin = loadImage("txture.jpg");
noStroke();
//mm = new MovieMaker(this, width, height, "drawing.mov", 30, MovieMaker.VIDEO, MovieMaker.LOSSLESS);
}
void draw()
{
background(#042F5D);
lights();
rotateY(roty -= 0.010);
e.render();
//mm.addFrame();
}
void keyPressed()
{
switch(key) {
case 's':
//saveFrame();
break;
case 'f':
//mm.finish();
break;
}
}
class Tentacle
{
ParticleSystem tentPhysics;
ArrayList temporaryCoords = new ArrayList();
int currParticle = 1;
float currPartMass = 1.0;
Cylinder c;
float cyLength = 0.1;
float cyStrength = 1.7;
int tentLength = int(random(50, 70));
int maxParticles = tentLength/2;
float d=127,f=0;
Tentacle()
{
tentPhysics = new ParticleSystem( 0, 0.05 );
Particle p = tentPhysics.makeParticle(1.0, 0,0,0);
p.makeFixed();
}
void calcNextPoint()
{
Particle temp = tentPhysics.getParticle(currParticle-1);
float radius = 3;
float factor = 0.05;
float x,y,z;
for(float phi = 0.0; phi < QUARTER_PI; phi += factor) {
for(float theta = 0.0; theta < TWO_PI + factor; theta += factor) {
x = temp.position().x() + radius * sin(phi) * cos(theta);
z = temp.position().z() + radius * sin(phi) * sin(theta);
y = temp.position().y() -radius * cos(phi);
temporaryCoords.add( new PVector(x,y,z) );
}
}
}
void calcSVector()
{
calcNextPoint();
PVector thisPos = (PVector) temporaryCoords.get(int(random(temporaryCoords.size())));
Particle p = tentPhysics.makeParticle(currParticle, thisPos.x, thisPos.y, thisPos.z );
addNode();
}
void addNode()
{
temporaryCoords.clear();
if(currParticle >= maxParticles)
return;
Particle p = tentPhysics.getParticle(currParticle);
Particle q = tentPhysics.getParticle( currParticle -1 );
makeSprng( p, q );
}
void makeSprng( Particle a, Particle b )
{
tentPhysics.makeSpring( a, b, cyStrength, cyStrength, cyLength );
}
void drawTentacle()
{
for ( int i = 0; i < tentPhysics.numberOfSprings(); ++i )
{
Spring e = tentPhysics.getSpring( i );
Particle a = e.getOneEnd();
Particle b = e.getTheOtherEnd();
c = new Cylinder(tentLength/3.98 * pow(0.9, i), tentLength/3.55 * pow(0.9, i), a, b);
c.render();
}
}
void render(){
float e = cos(PI*(f+=1.0)/d);
calcSVector();
if(currParticle <= maxParticles)
currParticle += 1;
tentPhysics.setGravity( e/2, -0.4, 0);
tentPhysics.tick();
drawTentacle();
}
}