import traer.physics.*;
import traer.animation.*;
//import org.json.*;
/// import moviemaker.*;
final float NODE_SIZE = 10;
final float EDGE_LENGTH = 20;
final float EDGE_STRENGTH = 0.2;
final float SPACER_STRENGTH = 500;
SmartSystem textSystem, boxSystem, boxSizeSystem, floatSystem;
int frame;
PFont htmlFont;
PFont renderFont, renderFontItal;
String htmlText[] = {"","
","this is just plain text,
","but text with structure
","and connections
","",""};
color bgColor;
class SmartSystem {
ParticleSystem physics;
ArrayList names; // Holds an id string for each particle
ArrayList centroids;
ArrayList attribs; // Holds a hashtable of attribs for each particle
Animator anim;
SmartSystem(float gravity, float drag, float smoothness){
anim = new Animator(smoothness);
physics = new ParticleSystem(gravity, drag);
names = new ArrayList();
centroids = new ArrayList();
}
void clear(){
physics.clear();
names.clear();
centroids.clear();
}
int count(){
return physics.numberOfParticles();
}
ParticleSystem sys(){
return physics;
}
void dbgState(){
int numP = physics.numberOfParticles();
for (int i=0; i0.0){
anim.tick();
}
// For all the particles without -1,-1 targets, move them toward the target
for (int i=0; i 250){
frame = 250;
}
}
void draw()
{
background(bgColor);
textSystem.tick( 1.6 );
boxSizeSystem.tick();
boxSystem.tick();
floatSystem.tick(0.2 );
// Loop back to the box drawing once the tree floats around for a while
if (frame>1800){ frame = 250; }
// Handle the element box drawing
if (frame==250){ growBoxes(); }
if (frame==400){ shrinkBoxes(); }
// Draw the floating tree
if (frame==500){ floatBoxes(); }
// Draw the element boxes
if (frame>=250){
noStroke();
for (int i=0; i<7; i++){
Particle p, s;
p = boxSystem.getParticle(i);
s = boxSizeSystem.getParticle(i);
fill(255,255,255,30);
if (i==0){
fill(#38372e);
}else if (i==1){
fill(#52524a);
}else if (i>1 && i<5){
fill(#6b6b64); //60
}else if (i==5){
fill(#582d0b);
} else if(i==6){
fill(#122d51);
}
rect(p.position().x(),p.position().y(),
s.position().x(),s.position().y());
}
}
// Draw the floating pieces of HTML text
fill(255);
textFont(htmlFont,12);
if (frame<60){
if(frame>20){
fill(255,255,255,255*((frame-20)/40.0));
}else{
fill(255,255,255,0);
}
}else if (frame==100){
arrangeHtml();
}
// draw the ghost text floating over
if (frame >170){
color textColor = color(255,255,255,0);
float offset = 350*(frame-170)/70.0;
boolean shouldDraw = true;
if (frame<220){
textColor = color(255,255,255,20+50*(frame-170)/50.0);
}else if (frame>=220 && frame < 235){
textColor = color(255,255,255,20+50*(frame-230)/-15.0);
}else{
shouldDraw = false;
}
if(shouldDraw){
float meanY = 0;
float maxY = 0;
float minY = height;
for (int i=0; i 200){
color pageColor = color(255,255,255,0);
color textColor = color(0,0,0,0);
float alpha = (frame-200)/40.0;
if(frame < 240){
pageColor = color(235,235,235,200*alpha);
textColor = color(40,40,40,255*alpha);
}else{
pageColor = color(235,235,235,200);
textColor = color(40,40,40,255);
}
int gutter = 412;
int hangline = 45;
// blank out the page
fill(pageColor);
noStroke();
rect(gutter-10,hangline-21,139,143);
// draw the three lines of text
fill(textColor);
textFont(renderFont,14);
text("this is just plain text,", gutter, hangline);
text("but text with ", gutter, hangline+15);
float lineWidth = textWidth("but text with ");
textFont(renderFontItal,14);
//fill(151,49,18,255*alpha);
fill(88,45,11,255*alpha);
text("structure", gutter+lineWidth, hangline+15);
fill(textColor);
textFont(renderFont,14);
text("and ",gutter,hangline+30);
lineWidth = textWidth("and ");
fill(18,45,81,255*alpha);
text("connections", gutter+lineWidth, hangline+30);
float linkWidth = textWidth("connections");
strokeWeight(1);
stroke(18,45,81,100*alpha);
line(gutter+lineWidth,hangline+31,gutter+lineWidth+linkWidth,hangline+31);
}
if (frame>=250 && floatSystem.count()>0){
// kick things
Particle body = floatSystem.getParticle("body");
body.addVelocity(0.5,-0.25,0.0);
Particle html = floatSystem.getParticle("html");
html.setMass(2);
html.addVelocity(0.01,-0,0.0);
for (int i=0; iwidth*.4 && p.position().x()