Created
March 16, 2018 15:19
-
-
Save KrabCode/ad9287a401f44ca4623cc821809bd45e to your computer and use it in GitHub Desktop.
l-systems yeah boii
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(2); | |
| frameRate(30); | |
| createLine(); | |
| drawLines(); | |
| } | |
| public void draw(){ | |
| //background(0); | |
| applyLine(); | |
| drawLines(); | |
| } | |
| void createLine(){ | |
| lines.add(new Line(new PVector(width/2, height/2), new PVector(width/2+1, height/2))); | |
| } | |
| void applyLine(){ | |
| Line last = lines.get(lines.size()-1); | |
| float size = last.origin.dist(last.target); | |
| float angle = getAngle(last.origin, last.target); | |
| println(angle); | |
| PVector newTarget = getPVectorAtAngle(last.target, size+1, angle-90/3); | |
| lines.add(new Line(last.target, newTarget)); | |
| if(size < 1 || size > width*2){ | |
| noLoop(); | |
| } | |
| } | |
| 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), -180, 180, 0, 255), 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