夏天
processing吧
全部回复
仅看楼主
level 4
qof3990 楼主
// 声明并初始化一个ArrayList来保存多个Fly实例
ArrayList<Fly> flies = new ArrayList<Fly>();
void setup() {
size(600, 600);
stroke(120);
strokeWeight(5);
// 添加多个Fly实例到ArrayList中,每个实例使用不同的种子
for (int i = 0; i < 20; i++) { // 创建i个实例
flies.add(new Fly(int(random(500))));
}
}
void draw() {
background(60, 60, 90);
// 使用for循环遍历ArrayList并更新每个Fly实例
for (Fly fly : flies) {
fly.update();
}
}
//定义类
class Fly {
float x, y, r1, r2, r3, angle, angle1, scale, scale1, lineLength, interval;
Fly(int seed) {
randomSeed(seed);
r1 = r2 = random(300); // 初始运动半径
scale = 0;
r3 = 0.1; // 初始旋转速度,越大越快
angle = 0;
interval = random(900, 2000); // 伸缩速度,越小越快
}
void update() {
if (scale >= 1) {
r1 = r2;
r2 = random(300); // 更新运动半径
scale = 0;
r3 = random(0.01, 0.05); // 更新旋转速度
}
scale += frameRate / interval;
scale1 = scale;
angle += r3;
angle1 = angle;
for (int i=0; i<20; i++) {
scale1 += frameRate / interval/10;
angle1 += r3/10;
lineLength = lerp(r1, r2, scale1);
x = lineLength * sin(angle1) + width / 2;
y = lineLength * cos(angle1) + height / 2;
point(x, y);
}
}
}
2024年12月10日 12点12分 1
level 4
qof3990 楼主
// 声明并初始化一个ArrayList来保存多个Fly实例
ArrayList<Fly> flies = new ArrayList<Fly>();
void setup() {
size(600, 600);
stroke(120);
strokeWeight(5);
// 添加多个Fly实例到ArrayList中,每个实例使用不同的种子
for (int i = 0; i < 20; i++) { // 创建i个实例
flies.add(new Fly(int(random(500))));
}
}
void draw() {
background(60, 60, 90);
// 使用for循环遍历ArrayList并更新每个Fly实例
for (Fly fly : flies) {
fly.update();
}
}
//定义类
class Fly {
float x, y, r1, r2, r3, angle, angle1, scale, scale1, lineLength,
length1, interval, sin1, cos1;
Fly(int seed) {
randomSeed(seed);
noiseSeed(seed);
r1 = r2 = random(300); // 初始运动半径
scale = 0;
r3 = 0; // 初始旋转速度,越大越快
angle = random(100);
interval = random(900, 2000); // 伸缩速度,越小越快
}
void update() {
if (scale >= 1) {
r1 = r2;
r2 = random(300); // 更新运动半径
scale = 0;
r3 = int(random(1, 5)); // 更新旋转速度
}
scale += frameRate / interval;
scale1 = scale;
angle += radians(r3);
angle1 = angle;
for (int i=0; i<20; i++) {
scale1 += frameRate / interval/10;
angle1 += radians(r3)/10;
//lineLength = lerp(r1, r2, scale1);
length1 = noise(angle1)*0.02;//轨迹分瓣数n*2),同时控制飞虫速度
lineLength = sin(length1*angle1/10)*300;
//后面加的cos和sin是为了避免轨迹都过中心
x = lineLength * sin(angle1) + width / 2 + cos(angle1)*30;
y = lineLength * cos(angle1) + height / 2 + sin(angle1)*30;
point(x, y);
}
println(millis());
}
}
=================================================
点的运动会越来越快。怀疑是三角函数的周期造成的。
2024年12月11日 04点12分 2
level 4
qof3990 楼主
找到问题了。原来是:
lineLength = sin(length1*angle1/10)*300;
这行,我不知为啥给length1放括号里了。放外面就好了。
================================================
// 声明并初始化一个ArrayList来保存多个Fly实例
ArrayList<Fly> flies = new ArrayList<Fly>();
void setup() {
size(600, 600);
stroke(120);
strokeWeight(5);
// 添加多个Fly实例到ArrayList中,每个实例使用不同的种子
for (int i = 0; i < 20; i++) { // 创建i个实例
flies.add(new Fly(int(random(500))));
}
}
void draw() {
background(60, 60, 90);
// 使用for循环遍历ArrayList并更新每个Fly实例
for (Fly fly : flies) {
fly.update();
}
}
//定义类
class Fly {
float x, y, r1, r2, r3, angle, angle1, scale, scale1, lineLength,
length1, interval, sin1, cos1;
Fly(int seed) {
randomSeed(seed);
noiseSeed(seed);
r1 = r2 = random(300); // 初始运动半径
scale = 0;
r3 = 0; // 初始旋转速度,越大越快
angle = random(100);
interval = random(900, 2000); // 伸缩速度,越小越快
}
void update() {
if (scale >= 1) {
r1 = r2;
r2 = random(300); // 更新运动半径
scale = 0;
r3 = int(random(1, 3)); // 更新旋转速度
}
scale += frameRate / interval;
scale1 = scale;
angle += radians(r3);
angle1 = angle;
//print(r3,"\t",radians(r3),"\t",angle1,"\t");
for (int i=0; i<20; i++) {
scale1 += frameRate / interval/10;
angle1 += radians(r3)/10;
//lineLength = lerp(r1, r2, scale1);
length1 = noise(angle1);
lineLength = length1*sin(angle1*(2+r3/10))*300;//sin内控制飞行速度,越大越快
//后面加的cos和sin是为了避免轨迹都过中心
x = lineLength * sin(angle1) + width / 2 + cos(angle1)*50;
y = lineLength * cos(angle1) + height / 2 + sin(angle1)*50;
point(x, y);
}
println(degrees(angle1%TWO_PI),"\t",length1,"\t",lineLength);
}
}
2024年12月11日 13点12分 3
1