void setup() {
size(600, 600);
colorMode(RGB, 255);
strokeWeight(15);
}
float speed = 0.03;// 运动速度
float bgColor = 200;//背景颜色
float lineU = 150; // x方向幅度
float lineV = 50; // y方向幅度
float lineHead = 0, lineLength = 0;
float pointColor, x, y;
float rotationAngle = 0; // 初始旋转角度
void draw() {
background(bgColor);
pointColor = bgColor;
lineHead = lineHead + speed;
lineLength = lineHead;
// 每一帧增加旋转角度,可以调整增量以改变旋转速度
rotationAngle += 0.02;
while (pointColor >= 0) {
lineLength += 0.03; // 控制线长度
pointColor -= 1;
stroke(pointColor);
// 计算未旋转的点位置
float originalX = lineU * sin(lineLength);
float originalY = lineV * sin(2 * lineLength);
// 应用旋转矩阵
float rotatedX = originalX * cos(rotationAngle) - originalY * sin(rotationAngle);
float rotatedY = originalX * sin(rotationAngle) + originalY * cos(rotationAngle);
// 将旋转后的点居中
x = rotatedX + width / 2;
y = rotatedY + height / 2;
point(x, y);
}
}
size(600, 600);
colorMode(RGB, 255);
strokeWeight(15);
}
float speed = 0.03;// 运动速度
float bgColor = 200;//背景颜色
float lineU = 150; // x方向幅度
float lineV = 50; // y方向幅度
float lineHead = 0, lineLength = 0;
float pointColor, x, y;
float rotationAngle = 0; // 初始旋转角度
void draw() {
background(bgColor);
pointColor = bgColor;
lineHead = lineHead + speed;
lineLength = lineHead;
// 每一帧增加旋转角度,可以调整增量以改变旋转速度
rotationAngle += 0.02;
while (pointColor >= 0) {
lineLength += 0.03; // 控制线长度
pointColor -= 1;
stroke(pointColor);
// 计算未旋转的点位置
float originalX = lineU * sin(lineLength);
float originalY = lineV * sin(2 * lineLength);
// 应用旋转矩阵
float rotatedX = originalX * cos(rotationAngle) - originalY * sin(rotationAngle);
float rotatedY = originalX * sin(rotationAngle) + originalY * cos(rotationAngle);
// 将旋转后的点居中
x = rotatedX + width / 2;
y = rotatedY + height / 2;
point(x, y);
}
}