need help on a line
in
Programming Questions
•
1 year ago
Please run the code below and then read further.
Are arc's for example good for this or is it better to use a curve or something?
I know i can check for being a value lower then wright code to flip for example but i need also to check if it's on the same axis to write a line and it seems that it get's fast more complex then it should be.
(once again it's not that important since my target is always on the left side, it's just curiosity with a combination of no time to dig it out).
- void setup() {
- size(600, 600);
- noFill();
- }
- void draw() {
- background(255);
- drawConectionLine(mouseX, mouseY, 100, height-100, 100);
- }
- void drawConectionLine(float startX, float startY, float endX, float endY, float maxRadius) {
- int hDist = (int) abs(startX-endX);
- int vDist = (int) abs(startY-endY);
- // is it larger then the maxRadius
- if (hDist >= maxRadius && vDist >= maxRadius) {
- // use maxRadius
- pushStyle();
- ellipseMode(CORNER);
- arc(min(startX, endX), min(startY, endY), maxRadius*2, maxRadius*2, PI, TWO_PI-HALF_PI);
- line(min(startX, endX)+maxRadius, min(startY, endY), max(startX, endX), min(startY, endY));
- line(min(startX, endX), min(startY, endY)+maxRadius, min(startX, endX), max(startY, endY));
- popStyle();
- }
- else {
- // draw with the smallest radius
- drawConectionLine(startX, startY, endX, endY, min(hDist, vDist));
- }
- }
Are arc's for example good for this or is it better to use a curve or something?
I know i can check for being a value lower then wright code to flip for example but i need also to check if it's on the same axis to write a line and it seems that it get's fast more complex then it should be.
(once again it's not that important since my target is always on the left side, it's just curiosity with a combination of no time to dig it out).
1