애니메이션 생성 및 업데이트
// Inside the create_data() function
int points_size = index;
for (int frame = 0; frame < frames; ++frame) {
for (index = 0; index < points_size; ++index) {
// The position of the calculated point is increased and the coordinates are updated
double x = points[index].x, y = points[index].y;
double distance = sqrt(pow(x, 2) + pow(y, 2));
double distance_increase = -0.0009 * distance * distance + 0.35714 * distance + 5;
double x_increase = distance_increase * x / distance / frames;
double y_increase = distance_increase * y / distance / frames;
points[index].x += x_increase;
points[index].y += y_increase;
// Draw points using XSetForeground and XFillArc
XSetForeground(display, gc, points[index].color);
XFillArc(display, win, gc, screen_x(points[index].x), screen_y(points[index].y), 2, 2, 0, 360 * 64);
}
for (double size = 17; size < 23; size += 0.3) {
for (index = 0; index < quantity; ++index) {
// Randomly generate the coordinates and color of the point according to the condition, and draw the point using XSetForeground and XFillArc
if ((create_random(0, 100) / 100.0 > 0.6 && size >= 20) || (size < 20 && (double)create_random(0, 100) / 100.0 > 0.95)) {
double x, y;
if (size >= 20) {
x = origin_points[index].x * size + create_random(-frame * frame / 5 - 15, frame * frame / 5 + 15);
y = origin_points[index].y * size + create_random(-frame * frame / 5 - 15, frame * frame / 5 + 15);
} else {
x = origin_points[index].x * size + create_random(-5, 5);
y = origin_points[index].y * size + create_random(-5, 5);
}
XSetForeground(display, gc, colors[create_random(0, 6)]);
XFillArc(display, win, gc, screen_x(x), screen_y(y), 2, 2, 0, 360 * 64);
}
}
}
}
-
points_size는 현재 애니메이션 프레임의 점 개수를 얻는 데 사용되며, 이전 코드 섹션에서 계산됩니다. index는 이전에 생성된 점의 수입니다.
-
외부 루프 for (int frame = 0; frame < frames; ++frame)는 애니메이션의 각 프레임을 반복하는 데 사용되며, frames는 총 프레임 수를 지정합니다.
-
내부 루프 for (index = 0; index < points_size; ++index)는 현재 프레임의 각 점을 처리하는 데 사용됩니다. 각 프레임에서 다음을 수행합니다.
- 먼저, 각 점의 새로운 위치를 계산합니다. 이는 다음 공식을 사용하여 수행됩니다.
double x = points[index].x, y = points[index].y;
double distance = sqrt(pow(x, 2) + pow(y, 2));
double distance_increase = -0.0009 * distance * distance + 0.35714 * distance + 5;
double x_increase = distance_increase * x / distance / frames;
double y_increase = distance_increase * y / distance / frames;
points[index].x += x_increase;
points[index].y += y_increase;
이러한 계산은 애니메이션에서 점의 움직임을 달성하기 위해 점의 x 및 y 좌표를 업데이트하는 데 사용됩니다. distance_increase는 점의 원래 위치로부터의 거리에 따라 달라지는 점의 이동 속도를 제어합니다.
XSetForeground 및 XFillArc 함수를 사용하여 점을 그립니다. 이는 화면에 점을 그리는 것으로, XSetForeground는 페인트 색상을 설정하고, XFillArc는 채워진 점을 그리며, 원의 중심 좌표는 screen_x 및 screen_y 함수에 의해 변환됩니다.
- 내부 루프의 두 번째 부분
for (double size = 17; size < 23; size += 0.3)는 현재 프레임에서 추가 점을 생성하는 데 사용됩니다. 이 루프에서 각 점은 생성, 색상 지정 및 화면에 그려집니다.
- 새로운 점의 좌표와 색상은 다음 조건에 따라 무작위로 생성됩니다.
size >= 20이고 난수가 0.6보다 크거나, size < 20이고 난수가 0.95보다 크면 새로운 점이 생성됩니다.
- 생성된 점의 x 및 y 좌표는 원래 점의 위치와 일부 무작위 오프셋에서 계산됩니다.
double x, y;
if (size >= 20) {
x = origin_points[index].x * size + create_random(-frame * frame / 5 - 15, frame * frame / 5 + 15);
y = origin_points[index].y * size + create_random(-frame * frame / 5 - 15, frame * frame / 5 + 15);
} else {
x = origin_points[index].x * size + create_random(-5, 5);
y = origin_points[index].y * size + create_random(-5, 5);
}
- 마지막으로,
XSetForeground 및 XFillArc 함수를 사용하여 생성된 점을 이전 점과 마찬가지로 화면에 그립니다.