-
Notifications
You must be signed in to change notification settings - Fork 0
/
spineCalc.pde
132 lines (90 loc) · 2.76 KB
/
spineCalc.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
class spineCalc {
PVector anchorLeft = new PVector(50,300);
PVector anchorRight = new PVector(750,300);
PVector handleLeft = new PVector(anchorLeft.x,anchorLeft.y);
PVector handleRight = new PVector(anchorRight.x,anchorRight.y);
float duration = 5.0;
PVector[] screen = new PVector[10];
float[] target = new float[5];
spineCalc() {
rectMode(CENTER);
for (int i = 0; i < screen.length; i++) {
screen[i] = new PVector();
}
target[0] = 300;
target[1] = 300;
target[2] = 300;
target[3] = 300;
}
void calcScreens() {
/*anchorLeft.y = target[0];
anchorRight.y = target[1];
handleLeft.y = target[2];
handleRight.y = target[3];*/
for (int i = 0; i < screen.length; i++) {
float t = map(i, 0, screen.length -1, 0, 1);
float x = map(i, 0, screen.length -1, anchorLeft.x, anchorRight.x);
float y = bezierPoint(anchorLeft.y, handleLeft.y, handleRight.y, anchorRight.y, t);
screen[i].set(x,y);
}
}
void display() {
background(0);
// Draw screens
int multiplier = 8;
for (PVector s : screen) {
stroke(255);
noFill();
//draw tv rectangle
rect(s.x, s.y, 9*multiplier, 16*multiplier);
//draw anchor point
line(s.x-5,s.y,s.x+5,s.y);
line(s.x,s.y-5,s.x,s.y+5);
//draw vinch wire
line(s.x,s.y-8*multiplier,s.x,0);
//draw y coord text
noStroke();
fill(255);
text("y:"+round(s.y),s.x-2*multiplier,s.y+6*multiplier);
}
// Draw bezier curve
stroke(255);
noFill();
bezier(anchorLeft.x, anchorLeft.y, handleLeft.x, handleLeft.y, handleRight.x, handleRight.y, anchorRight.x, anchorRight.y);
// Draw handle lines
stroke(255);
line(anchorLeft.x-multiplier, anchorLeft.y, handleLeft.x-multiplier, handleLeft.y);
line(anchorRight.x+multiplier, anchorRight.y, handleRight.x+multiplier, handleRight.y);
//draw floor
line(0,500,800,500);
//draw target text
noStroke();
fill(255);
for (int i = 0; i < 4; i++) {
text("target["+i+"]: " + round(target[i]),20,530 + i*16);
}
}
void setTarget(int t, float v) {
target[t] = v;
switch(t) {
case 0:
Ani.to(anchorLeft, duration, "y", v, Ani.SINE_IN_OUT);
break;
case 1:
Ani.to(anchorRight, duration, "y", v, Ani.SINE_IN_OUT);
break;
case 2:
Ani.to(handleLeft, duration, "y", v, Ani.SINE_IN_OUT);
break;
case 3:
Ani.to(handleRight, duration, "y", v, Ani.SINE_IN_OUT);
break;
}
}
void setRightHandle(int y) {
handleRight.set(anchorRight.x,y);
}
void setLeftHandle(int y) {
handleLeft.set(anchorLeft.x,y);
}
}