mirror of
https://github.com/processing/processing4.git
synced 2026-02-07 15:49:17 +01:00
22 lines
692 B
Plaintext
22 lines
692 B
Plaintext
void drawVector(PVector v, PVector loc, float scayl) {
|
|
pushMatrix();
|
|
float arrowsize = 4;
|
|
// Translate to location to render vector
|
|
translate(loc.x,loc.y);
|
|
stroke(0);
|
|
// Call vector heading function to get direction (note that pointing up is a heading of 0) and rotate
|
|
rotate(v.heading2D());
|
|
// Calculate length of vector & scale it to be bigger or smaller if necessary
|
|
float len = v.mag()*scayl;
|
|
// Draw three lines to make an arrow (draw pointing up since we've rotate to the proper direction)
|
|
line(0,0,len,0);
|
|
line(len,0,len-arrowsize,+arrowsize/2);
|
|
line(len,0,len-arrowsize,-arrowsize/2);
|
|
popMatrix();
|
|
}
|
|
|
|
|
|
void mousePressed() {
|
|
showVectors = !showVectors;
|
|
}
|