-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCircleItem.pde
169 lines (94 loc) · 3.17 KB
/
CircleItem.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
class CircleItem{
// Contador pasos
public int counter = 0;
// Posicion actual
public int xPos = 0;
public int yPos = 0;
public float angulo = 0;
// Centro orbita
public float centroX = 0;
public float centroY = 0;
public float radio = 0;
// Saltos
public float saltoH = 0;
// Colores
private float c;
private float cEnd;
private float cInit;
// Posicion actual del circulo
private int posicion = 0;
// Comprobante si ya hizo la transicion
public boolean check = true;
// Para dibujar cada circulo
public CircleItem(int xPos, int yPos, float c){
this.xPos = xPos;
this.yPos = yPos;
this.c = c+1-1;
this.cInit = c+1-1;
items.add(this);
this.posicion = items.indexOf(this);
}
public void display(){
float vol = analyzer.analyze();
noStroke();
fill(this.c, saturation, brightness);
circle(this.xPos, this.yPos, 40 + vol*50);
}
public void setFinal(float centroX, float centroY, float new_c){
this.cEnd = new_c+1-1;
this.centroX = centroX;
this.centroY = centroY;
this.angulo = atan2(this.yPos - this.centroY, this.xPos - this.centroX);
this.radio = dist(this.xPos, this.yPos, this.centroX, this.centroY);
this.check = true;
this.saltoH = (this.cEnd - this.c) / (speed);
}
public void actualizaColor(){
if (this.c != this.cEnd){
if (this.c < this.cEnd && this.c + this.saltoH > this.cEnd) {
this.c = this.cEnd;
}
else if (this.c > this.cEnd && this.c + this.saltoH < this.cEnd) {
this.c = this.cEnd;
}
else {
this.c += this.saltoH;
}
}
//this.c = lerpColor(color(this.cInit, saturation, brightness), color(this.cEnd, saturation, brightness), this.counter*this.saltoH/100);
}
// Calcula la pos de X y Y actuales
public void actualizaPosicion(){
this.angulo += PI/speed;
this.xPos = int(this.centroX + this.radio*cos(this.angulo));
this.yPos = int(this.centroY + this.radio*sin(this.angulo));
}
public void actualiza(){
this.actualizaColor();
this.actualizaPosicion();
this.counter ++;
if (this.counter == speed){
this.counter = 0;
this.check = false;
this.ajustaPosicion();
}
}
public void ajustaPosicion(){
int xCercano = this.xPos;
int yCercano = this.yPos;
float distCercana = radio;
int indexCercano = 0;
for (int i=0; i<posicionesIniciales.length; i++){
float distActual = dist(this.xPos, this.yPos, posicionesIniciales[i][0], posicionesIniciales[i][1]);
if (distActual < distCercana || distActual == 0){
distCercana = distActual;
xCercano = posicionesIniciales[i][0];
yCercano = posicionesIniciales[i][1];
indexCercano = i;
}
}
this.xPos = xCercano;
this.yPos = yCercano;
this.posicion = indexCercano;
}
}