Skip to content

Commit d389321

Browse files
committed
sketch shows how to do basic vector math
1 parent df220ed commit d389321

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
PVector[] wings = new PVector[900];
2+
3+
void setup() {
4+
size(700, 700);
5+
int index = 0;
6+
7+
for (int y = 0; y < 30; y++) {
8+
for (int x = 0; x < 30; x++) {
9+
float posX = map(x, 0, 29, 100, width - 100);
10+
float posY = map(y, 0, 29, 100, height - 100);
11+
12+
wings[index] = new PVector(posX, posY);
13+
index = index + 1;
14+
}
15+
}
16+
}
17+
18+
void draw() {
19+
background(255);
20+
PVector look = new PVector(mouseX, mouseY);
21+
for (int i=0; i < wings.length; i++) {
22+
PVector start = wings[i];
23+
PVector end = new PVector(start.x, start.y + 20);
24+
25+
PVector t = PVector.sub(look, start);
26+
float rotation = t.heading2D();
27+
28+
PVector v = PVector.sub(end, start);
29+
v.rotate(rotation + PI / 2.0);
30+
PVector newEnd = PVector.sub(start, v);
31+
32+
line(start.x, start.y, newEnd.x, newEnd.y);
33+
}
34+
}

0 commit comments

Comments
 (0)