Created
January 5, 2017 22:56
-
-
Save elektrowolle/6c18ce3295832ade71e7fa31d7aa0432 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
class Path{ | |
Path followingPath; | |
PVector start; | |
PVector end; | |
Float startAngle; | |
Float endAngle; | |
Path(PVector start, PVector end, Float startAngle, Float endAngle){ | |
this.start = start; | |
this.end = end; | |
this.startAngle = startAngle; | |
this.endAngle = endAngle; | |
} | |
public void draw(){ | |
stroke(255); | |
//Line between points | |
float mStart = tan(startAngle); | |
float mEnd = tan(endAngle); | |
// y = m * x + b | |
// b = y - m * x | |
float bStart = start.y - mStart * start.x; | |
float bEnd = end .y - mEnd * end .x; | |
float x = (bEnd -bStart) / (mStart-mEnd); | |
float y = bStart + mStart*x; | |
stroke(255,0,0); | |
point(x,bStart + mStart*x); | |
noFill(); | |
bezier( | |
start.x, start.y, | |
x, y, x, y, | |
end.x, end.y | |
); | |
if(followingPath != null){ | |
followingPath.draw(); | |
} | |
} | |
public void addToEnd(float x, float y){ | |
end.add(x,y); | |
} | |
public void setEnd(float x, float y){ | |
end.set(x,y); | |
} | |
public void addToEndRotation(float rot){ | |
endAngle += rot; | |
println(endAngle); | |
} | |
public Path createChild(){ | |
followingPath = new Path(end, end.copy(), endAngle, endAngle + 1); | |
return followingPath; | |
} | |
} |
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
Path path; | |
Path selected; | |
void setup(){ | |
size(400,400); | |
path = new Path( | |
new PVector(100,100), | |
new PVector(300,300), | |
radians(30), | |
radians(250) | |
); | |
selected = path; | |
} | |
void draw(){ | |
background(0); | |
if(!mousePressed && (mouseX + mouseY) < (width + height)) | |
selected.setEnd(mouseX, mouseY); | |
path.draw(); | |
} | |
void mouseDragged(){ | |
selected.addToEndRotation(radians(pmouseX - mouseX + pmouseY - mouseY)); | |
} | |
void mouseClicked(){ | |
selected = selected.createChild(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment