アニメーションの生成と更新
// 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 関数によって変換されます。
- 内側のループの 2 番目の部分
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 関数を使用して、生成された点を画面上に描画します。