import traer.physics.*;
ParticleSystem physics; // case1
Particle points;
Word w, w2, w3, w4;
Star s;
star2 s2;
float a; //X方向の重力
float b; //ドラッグ?ダンピング
//////////////////////////////////////////////////////////////
void setup() {
size(1000, 600, P3D);
physics = new ParticleSystem();
w = new Word("?riaf os tey uoht tra yhw ,teiluJ raed ,hA", physics);//逆から書く
//Ah, dear Juliet, why art thou yet so fair?
// s = new Star();
//s.setup();
s2 = new star2();
s2.setup();
frameRate(30);
// background(0);
}
//////////////////////////////////////////////////////////////////
//////////////////////////////////////
void draw()
{
physics.setGravity(a, 0, 0); //void setGravity( float x, float, y, float z )
physics.setDrag(b); //void setDrag( float drag )
fill(0, 0, 0, 100);
rect(0, 0, width, height);
// s.draw();
s2.draw();
if (mousePressed == true) {
a=5;
b=2;
w.update();
w.draw();
// physics.tick();
//////星屑描写////////////////////////////////////////
// fadeToBrack();
noStroke();
fill(0, 0, 0, 100);
rectMode(CORNER);
// rect(0, 0, width, height);
//drawing
for (int i = 0; i < 10; i++) {
float r = random(1, 10);
int x = int (random(mouseX, mouseX+400)); //Pick a random spot in the composition to test
int y = int (random(mouseY-70, mouseY+70));
fill(random(205, 230), random(5, 100), random(165, 210), random(0, 255));
ellipse(x, y, r, r); //ellipse(x, y, width, height)
//delay(10);
}
//////星屑描写終わり///////////////////////////////////
}
else {
a=0.1;
b=0.1;
w.update();
w.draw();
// physics.tick();
}
physics.tick(0.8);
}
//////////////////////////////////////////
import traer.physics.*;
class Word {
ParticleSystem physics;
Particle[] lettersParticules;
Spring[] lettersSpring;
String wordString;
//char[] charArray;
float xPos;
float yPos;
int nbLetters;
PFont font;
////////////////////////////////////////////////////////////////////////////////////////////
Word(String wstr,ParticleSystem ps) {
wordString = wstr;
nbLetters = wordString.length();
physics = ps;
// The font must be located in the sketch's
// "data" directory to load successfully
font = loadFont("ArialMT-48.vlw");
xPos = random(width);
yPos = random(height);
lettersParticules = new Particle[nbLetters];
lettersSpring = new Spring[nbLetters];
boolean firstTime=true;
/////無理やりここで
float[][] particleStatus = { {5,0.1,1},
{5,0.1,1},
{5,0.1,1},
{5,0.1,1},
{5,0.1,1},
{5,0.1,1},
{5,0.1,1},
{5,0.1,1},
{5,0.1,1},
{5,0.1,1},
{5,0.1,1},
{5,0.1,1},
{5,0.1,1},
{5,0.1,1},
{5,0.1,1},
{5,0.1,1},
{5,0.1,1},
{5,0.1,1},
{5,0.1,1},
{5,0.1,1},
{5,0.1,1},
{5,0.1,1},
{5,0.1,1},
{5,0.1,1},
{5,0.1,1},
{5,0.1,1},
{5,0.1,1},
{5,0.1,1},
{5,0.1,1},
{5,0.1,1},
{5,0.1,1},
{5,0.1,1},
{5,0.1,1},
{5,0.1,1},
{5,0.1,1},
{5,0.1,1},
{5,0.1,1},
{5,0.1,1},
{5,0.1,1},
{5,0.1,1},
{5,0.1,1},
{5,0.1,1},
{5,0.1,1},
};
///////////////////////////////////////////
for(int i=0;i<nbLetters;i++){
xPos = random(width);
yPos = random(height);
lettersParticules[i] = physics.makeParticle(10,xPos,yPos,0.0);
//解説:ぱーてぃくるを作る Particle makeParticle( float mass, float x, float y, float z )
if(!firstTime)
{ //解説:Spring makeSpring( Particle a, Particle b, float strength, float damping, float restLength )
lettersSpring[i] = physics.makeSpring( lettersParticules[i], lettersParticules[i-1], particleStatus[i][0], particleStatus[i][1], particleStatus[i][2]);
//lettersSpring[0] = physics.makeSpring(lettersParticules[1],lettersParticules[0], 1.2, 0.1, 10);
//lettersSpring[1] = physics.makeSpring(lettersParticules[2],lettersParticules[1], 1.2, 0.1, 10);
//lettersSpring[2] = physics.makeSpring(lettersParticules[3],lettersParticules[2], 1.2, 0.1, 20);
// lettersSpring[3] = physics.makeSpring(lettersParticules[3],lettersParticules[2], 1.2, 0.1, 20);
// lettersSpring[4] = physics.makeSpring(lettersParticules[4],lettersParticules[3], 1.2, 0.1, 10);
// lettersSpring[5] = physics.makeSpring(lettersParticules[5],lettersParticules[4], 1.2, 0.1, 10);
// lettersSpring[5] = physics.makeSpring(lettersParticules[6],lettersParticules[5], 1.2, 0.1, 10);
//physics.makeAttraction(lettersParticules[i] , lettersParticules[i-1], -200 , -100 );
}
else
{
firstTime=false;
}
}
////////////////////////////////////////////////////////
lettersParticules[0].makeFixed();
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
void draw()
{
fill(255,255,255, 100);
for(int i=0;i<nbLetters;i++)
{
textFont(font, 20+i/10.0);
text(wordString.charAt(nbLetters-i-1),lettersParticules[i].position().x(),lettersParticules[i].position().y());
}
}
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
void update()
{
for(int i=0;i<nbLetters;i++)
{
if(lettersParticules[i].position().y() > height)
{
lettersParticules[i].velocity().set(lettersParticules[i].velocity().x(),-abs(lettersParticules[i].velocity().y()),lettersParticules[i].velocity().z());
}
if(lettersParticules[i].position().x() > width)
{
lettersParticules[i].velocity().set(-abs(lettersParticules[i].velocity().x()),lettersParticules[i].velocity().y(),lettersParticules[i].velocity().z());
}
;
}
//lettersParticules[0].position().set( width-frameCount*2,height/2, 0);
lettersParticules[0].position().set(mouseX,mouseY, 0);
//lettersParticules[0].setX(mouseX);
//lettersParticules[0].setY(mouseY);
}
////////////////////////////////////////////////////////////////////////////////
}