![見出し画像](https://assets.st-note.com/production/uploads/images/101741560/rectangle_large_type_2_d17c64a7dc5525847f79e8d098037ed0.png?width=1200)
水族館(すいぞくかん)
水族館のアニメーションを SVG で作ってみました。
![](https://assets.st-note.com/img/1680315457619-jkyqz9cc6v.png?width=1200)
JavaScript のプログラムで三角関数(cos)を使って魚の幅を縮小させています。
/**
* moveFish function
* @since 0.1
*/
const moveFish = function() {
for (i = 0; i < max; i++) {
a[i] += da[i];
if (a[i] > 2 * Math.PI) {
a[i] -= 2 * Math.PI;
}
_x = x + Math.round((width * 0.4) * Math.cos(a[i])) + width * 0.5;
use[i].move(_x - fish.width() / 2, fy[i] - fish.height() / 2);
use[i].transform({scaleX: -Math.round(Math.sin(a[i]) * 1000) / 1000});
}
}
詳しいことはブログ「JavaScript (56) 水族館」をご覧ください。