Last active
December 27, 2017 13:23
-
-
Save takahashilabo/81b7f22b4ecee1fa5d84393ab670ef99 to your computer and use it in GitHub Desktop.
draw an arrow method for Processing
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
void setup() { | |
size(400, 400); | |
stroke(255); | |
noLoop(); | |
} | |
void draw() { | |
background(255); | |
stroke(255, 0, 0); | |
fill(255, 0, 0); | |
for (int i = 0; i < 100; i++) { | |
drawArrow(width / 2, height / 2, (float)random(width), (float)random(height)); | |
} | |
} | |
void drawArrow(float x1, float y1, float x2, float y2) { | |
float a = dist(x1, y1, x2, y2) / 50; | |
pushMatrix(); | |
translate(x2, y2); | |
rotate(atan2(y2 - y1, x2 - x1)); | |
triangle(- a * 2 , - a, 0, 0, - a * 2, a); | |
popMatrix(); | |
line(x1, y1, x2, y2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This will be really helpful! Thank you!