FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

a new proposed example demonstrating morphing from one shape to another · studioijeoma/processing@d179ff8 · GitHub

Repository navigation

Commit d179ff8

Browse files
committed
a new proposed example demonstrating morphing from one shape to another
1 parent b12c1d9 commit d179ff8

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* Morph.
3+
*
4+
* Changing one shape into another by interpolating
5+
* vertices from one to another
6+
*/
7+
8+
ArrayList<PVector> circle = new ArrayList<PVector>();
9+
ArrayList<PVector> square = new ArrayList<PVector>();
10+
11+
ArrayList<PVector> morph = new ArrayList<PVector>();
12+
13+
boolean state = false;
14+
15+
void setup() {
16+
size(640, 360);
17+
18+
for (int angle = 0; angle < 360; angle += 9) {
19+
PVector v = PVector.fromAngle(radians(angle-135));
20+
v.mult(100);
21+
circle.add(v);
22+
morph.add(new PVector());
23+
}
24+
25+
for (int x = -50; x < 50; x += 10) {
26+
square.add(new PVector(x, -50));
27+
}
28+
for (int y = -50; y < 50; y += 10) {
29+
square.add(new PVector(50, y));
30+
}
31+
for (int x = 50; x > -50; x -= 10) {
32+
square.add(new PVector(x, 50));
33+
}
34+
for (int y = 50; y > -50; y -= 10) {
35+
square.add(new PVector(-50, y));
36+
}
37+
}
38+
39+
void draw() {
40+
background(51);
41+
42+
for (int i = 0; i < circle.size(); i++) {
43+
PVector v1;
44+
if (state) v1 = circle.get(i);
45+
else v1 = square.get(i);
46+
PVector v2 = morph.get(i);
47+
v2.lerp(v1, 0.1);
48+
float d = PVector.dist(v1, v2);
49+
if (d < 0.01) {
50+
state = !state;
51+
}
52+
}
53+
54+
translate(width/2, height/2);
55+
beginShape();
56+
noFill();
57+
stroke(255);
58+
for (PVector v : morph) {
59+
vertex(v.x, v.y);
60+
}
61+
endShape(CLOSE);
62+
}
63+

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL