Skip to content

Instantly share code, notes, and snippets.

@iamerroralpha
Forked from takahashilabo/drawArrow.pde
Created December 27, 2017 13:23
Show Gist options
  • Save iamerroralpha/b4d72cb17fc85c00d06f59c8d96dd20b to your computer and use it in GitHub Desktop.
Save iamerroralpha/b4d72cb17fc85c00d06f59c8d96dd20b 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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment