gpt4 book ai didi

vector - 使用 Raphael JS 在屏幕上 float 形状

转载 作者:行者123 更新时间:2023-12-04 07:04:25 24 4
gpt4 key购买 nike

我正在努力让一些形状随机漂浮在屏幕上。最终它们将相互交互,并具有 onclick 功能。我可以让圆圈在屏幕上呈现,但我无法让它们运动。似乎 .animate() 函数不是我在这里需要的。

有谁知道我会怎么做?

这是我所拥有的:

jQuery(function ($) {

// Global Vars
var items = 30,
width = window.innerWidth,
height = window.innerHeight,
paper = Raphael("galaxy", width, height),
frameRate = 100,
i,
galaxy = [],
star = [],
stars = [];

// Do some variants for each item
for (i = 0; i<items; i++ ) {
stars[i] = {
x : Math.random() * width,
y : Math.random() * height,
r : Math.random()*255,
g : Math.random()*255,
b : Math.random()*255,
size : Math.random() * 20
}
}

// Creates canvas 320 × 200 at 10, 50
// Creates circle at x = 50, y = 40, with radius 10
for (i = 0; i<items; i++ ) {
star[i] = paper.circle(stars[i].x, stars[i].y, stars[i].size);
star[i].attr("fill", "rgb("+stars[i].r+", "+stars[i].g+", "+stars[i].b+")");
star[i].attr("stroke", "none");

}//end for

});

最佳答案

它可以与 animate() 一起使用。如果你例如将其添加到上述函数中:

(function anim() {
for (i = 0; i<items; i++ ) {
newX = Math.random() * width;
newY = Math.random() * height;
star[i].animate({cx: newX, cy: newY}, 1000);
}
setTimeout(anim, 1000);
})();

你的圈子飞来飞去。当然,让它们真正 float 甚至互动还有很长的路要走,但这可能是一个起点。

关于vector - 使用 Raphael JS 在屏幕上 float 形状,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1344176/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com