Skip to content

Instantly share code, notes, and snippets.

@KrabCode
Last active December 26, 2018 15:15
Show Gist options
  • Select an option

  • Save KrabCode/3d0507a2c6a585d50264cd68200ce120 to your computer and use it in GitHub Desktop.

Select an option

Save KrabCode/3d0507a2c6a585d50264cd68200ce120 to your computer and use it in GitHub Desktop.
ArrayList<Line> lines = new ArrayList<Line>();
public void setup(){
size(800,800);
colorMode(HSB);
background(0);
strokeWeight(1);
frameRate(30);
createLine();
drawLines();
}
public void draw(){
//background(0);
applyLine();
drawLines();
}
void createLine(){
lines.add(new Line(new PVector(0, 0), new PVector(0,width)));
}
void applyLine(){
Line last = lines.get(lines.size()-1);
float size = last.origin.dist(last.target);
float angle = getAngle(last.origin, last.target);
PVector newTarget = getPVectorAtAngle(last.target, size-1, angle-89);
lines.add(new Line(last.target, newTarget));
}
void drawLines(){
for(Line l : lines){
l.draw();
}
}
class Line{
PVector origin, target;
public Line(PVector origin, PVector target){
this.origin = origin;
this.target = target;
}
void draw(){
stroke(map(getAngle(origin, target), 0, 360, 0, 200), 255,255);
line(origin.x, origin.y, target.x, target.y);
}
}
public PVector getPVectorAtAngle(PVector center, float radius, float angle) {
return new PVector(center.x + radius * cos(angle * PI / 180), center.y + radius * sin(angle * PI / 180));
}
public float getAngle(PVector origin, PVector end) {
return degrees(atan2(end.y - origin.y, end.x - origin.x));
}
@KrabCode
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment