Last active
December 26, 2018 15:15
-
-
Save KrabCode/3d0507a2c6a585d50264cd68200ce120 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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)); | |
| } |
Author
KrabCode
commented
Mar 16, 2018

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