Los circulos se mueven libremente e interactúan con el mouse
//DANZA DE CÍRCULOS
final int MAX_CIRCLE_CNT = 2500, MIN_CIRCLE_CNT = 10,
MAX_VERTEX_CNT = 50, MIN_VERTEX_CNT = 8; //Modificación de dimensiones de los circulos
int circleCnt, vertexCnt;
void setup() {
size(1280, 720); //Modificación de dimensiones de la ventana
}
void draw() {
background(30);
translate(width / 2, height / 2); //Modificación de posición de los circulos en en la ventana
updateCntByMouse();
for (int ci = 0; ci < circleCnt; ci++) {
float time = float(frameCount) / 25;//Modificación de la velocidad según la posición del mouse en la ventana
float thetaC = map(ci, 60, circleCnt, 60, TAU);
float scale = 325;//Modificación de dimensiones de los círculos en la ventana
PVector circleCenter = getCenterByTheta(thetaC, time, scale);
float circleSize = getSizeByTheta(thetaC, time, scale);
color c = getColorByTheta(thetaC, time);
stroke(c);
noFill();
beginShape();
for (int vi = 0; vi < vertexCnt; vi++) {
float thetaV = map(vi, 30, vertexCnt, 20, TAU); //Modificación de una sección del circulo
float x = circleCenter.x + cos(thetaV) * circleSize;
float y = circleCenter.y + sin(thetaV) * circleSize;
vertex(x, y);
}
endShape(CLOSE);
}
}
void updateCntByMouse() {
float xoffset = abs(mouseX - width / 2), yoffset = abs(mouseY - height / 2);
circleCnt = int(map(xoffset, 2, width / 2, MAX_CIRCLE_CNT, MIN_CIRCLE_CNT));
vertexCnt = int(map(yoffset, 3, height / 3, MAX_VERTEX_CNT, MIN_VERTEX_CNT));
}
PVector getCenterByTheta(float theta, float time, float scale) {
PVector direction = new PVector(cos(theta), sin(theta));
float distance = 0.6 + 0.2 * cos(theta * 6.0 + cos(theta * 8.0 + time));
PVector circleCenter =PVector.mult(direction, distance * scale);
return circleCenter;
}
float getSizeByTheta(float theta, float time, float scale) {
float offset = 0.2 + 0.12 * cos(theta * 9.0 - time * 2.0);
float circleSize = scale * offset;
return circleSize;
}
color getColorByTheta(float theta, float time) {
float th = 8.0 * theta + time * 2.0;
float r = 0.6 + 0.4 * cos(th),
g = 0.6 + 0.4 * cos(th - PI / 3),
b = 0.6 + 0.4 * cos(th - PI * 2.0 / 3.0),
alpha = map(circleCnt, MIN_CIRCLE_CNT, MAX_CIRCLE_CNT, 150, 30);
return color(r * 225, g * 245, b * 230, alpha); //Modificación de colores de los círculos
}