Created
November 25, 2016 20:43
-
-
Save anonymous/3364cd5ded5112e9adce02cf6e15bbb8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import igeo.*; | |
import processing.pdf.*; | |
void setup(){ | |
size(480,360,IG.GL); | |
beginRecord(PDF, "everything.pdf"); | |
for(int i=0; i < 1; i++){ //Changing I < Value Changes charges | |
new LineAgent(new IParticle(IRand.pt(-40,-40,0,40,40,0)).hide().fric(0.2), IRand.dir(IG.zaxis).len(2)); | |
} | |
for(int i=0; i < 20; i++){ | |
new IAttractor(IRand.pt(-200,-200,0,200,200,0)).linear(50).intensity(-30); //repulsion force | |
} | |
IG.bg(1.0,1.0,1.0); | |
IG.top(); | |
} | |
class LineAgent extends IParticle{ | |
LineAgent parent; | |
boolean isColliding; | |
IVec dir; | |
LineAgent(IParticle parent, IVec dir){ | |
super(parent.pos().cp(dir)); | |
if(parent instanceof LineAgent){ | |
this.parent = (LineAgent)parent; | |
} | |
isColliding=false; | |
hide(); // hide point | |
this.dir = dir; | |
fric(0.2); | |
} | |
void interact(ArrayList agents){ | |
if(time()==0){ //only in the first time | |
for(int i=0; i < agents.size(); i++){ | |
if(agents.get(i) instanceof LineAgent){ | |
LineAgent lineAgent = (LineAgent)agents.get(i); | |
if(lineAgent!=this){ //agents include "this" | |
if(lineAgent.parent!=null && lineAgent.pos().dist(pos()) < pos().dist(parent.pos())*2){ | |
IVec intxn = IVec.intersectSegment(lineAgent.parent.pos(),lineAgent.pos(),parent.pos(),pos()); | |
if( intxn != null && !intxn.eq(parent.pos()) && !lineAgent.isColliding ){ | |
isColliding = true; | |
return; | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
void update(){ | |
if( isColliding ){ | |
del(); | |
} | |
else{ | |
if(time()==0 && alive()){ | |
if(parent!=null && parent.alive()){ | |
ISpringLine ln = new ISpringLine(this, parent,100); | |
double t = -cos(IG.time()*0.015)*0.5+0.5; | |
ln.hsb( 0.7-t*0.2, 1, 0.8-t*0.2, 0.5); // color by time | |
if(parent.parent!=null && parent.parent.alive()){ | |
IStraightenerCurve st = | |
new IStraightenerCurve(this,parent,parent.parent).tension(100); | |
st.hsb( 0.7-t*0.2, 1, 0.8-t*0.2, 0.5); | |
} | |
} | |
} | |
if(time()==4){ | |
IVec dir2 = dir.cp(); | |
double angle = PI*0.12 ; | |
if( IRand.pct(50) ){ | |
dir.rot(angle); | |
dir2.rot(-angle); | |
} | |
else{ | |
dir.rot(-angle); | |
dir2.rot(angle); | |
} | |
new LineAgent(this, dir); | |
if( IRand.pct(20) ){ // 20% branching probability | |
new LineAgent(this,dir2); | |
} | |
} | |
} | |
} | |
} | |
void keyPressed() { | |
if (key=='R');{ | |
endRecord(); | |
exit(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment