-
Notifications
You must be signed in to change notification settings - Fork 0
/
OldBillyShape.pde
128 lines (117 loc) · 3.04 KB
/
OldBillyShape.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
class OldBillyNormalShape extends Shape {
float time;
float energy;
ArrayList <CalmWave> calmWaves;
OldBillyNormalShape(NodesBase nodesBase, int[] scope, int[] locate){
super(nodesBase, scope, locate);
time = frameCount;
energy = 1.0;
calmWaves = new ArrayList<CalmWave>();
calmWaves.add(new CalmWave(new PVector(this.scope[0], this.scope[1] / 0.2)));
}
void addWaves(){
translate(this.scope[0], this.scope[1] / 2, -200);
translate(-this.scope[0], -this.scope[1] / 2, 0);
for (int x=0; x<this.scope[0]; x++) {
for (int y=0; y<this.scope[1]; y++) {
PVector p = new PVector(x, y);
pushMatrix();
float z = 0;
for(CalmWave cw: calmWaves){
z += cw.getValue(p);
this.nodes[x][y].add(0, 0, z*0.1);
}
translate(x, y, z);
popMatrix();
}
}
ArrayList<CalmWave> nextCalmWaves = new ArrayList<CalmWave>();
for(CalmWave cw: calmWaves){
if(cw.energy >= 0.01){
nextCalmWaves.add(cw);
}
}
calmWaves = nextCalmWaves;
}
void motion(){
addWaves();
}
}
class OldBillyInteractShape extends Shape {
float time;
float energy;
ArrayList <ComingWave> comingWaves;
OldBillyInteractShape(NodesBase nodesBase, int[] scope, int[] locate){
super(nodesBase, scope, locate);
time = frameCount;
energy = 1.0;
comingWaves = new ArrayList<ComingWave>();
comingWaves.add(new ComingWave(new PVector(this.scope[0], this.scope[1])));
}
void addWaves(){
for (int x=0; x<this.scope[0]; x++) {
for (int y=0; y<this.scope[1]; y++) {
PVector p = new PVector(x, y);
pushMatrix();
float z = 0;
for(ComingWave cw: comingWaves){
z += cw.getValue(p);
this.nodes[x][y].add(0, 0, z*0.1);
}
translate(x, y, z);
popMatrix();
}
}
for(ComingWave cw: comingWaves){
cw.update();
}
ArrayList<ComingWave> nextComingWaves = new ArrayList<ComingWave>();
for(ComingWave cw: comingWaves){
if(cw.energy >= 0.01){
nextComingWaves.add(cw);
}
}
comingWaves = nextComingWaves;
}
void motion(){
addWaves();
}
}
class CalmWave{
float maxAmp = 20;
float maxDistance = 400;
PVector loc;
float time;
float energy;
CalmWave(PVector _loc){
loc = _loc;
time = frameCount;
energy = 1.0;
}
float getValue(PVector p){
float d = loc.dist(p);
float amp = maxAmp * energy * ((maxDistance - d) / maxDistance);
return map(sin(d * PI / 10 - (frameCount - time) * 0.1), -1, 1, -amp, amp);
}
}
class ComingWave{
float maxAmp = 20;
float maxDistance = 400;
PVector loc;
float time;
float energy;
ComingWave(PVector _loc){
loc = _loc;
time = frameCount;
energy = 1.0;
}
void update(){
//energy *= 0.995;
energy *= 1.0;
}
float getValue(PVector p){
float d = loc.dist(p);
float amp = maxAmp * energy * ((maxDistance - d) / maxDistance);
return map(sin(d * PI / 10 - (frameCount - time) * 0.1), -1, 1, -amp, amp);
}
}