Skip to content

Instantly share code, notes, and snippets.

@takahashilabo
Last active December 27, 2017 13:23
Show Gist options
  • Save takahashilabo/81b7f22b4ecee1fa5d84393ab670ef99 to your computer and use it in GitHub Desktop.
Save takahashilabo/81b7f22b4ecee1fa5d84393ab670ef99 to your computer and use it in GitHub Desktop.
draw an arrow method for Processing
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);
}
@iamerroralpha
Copy link

This will be really helpful! Thank you!

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