processing动态海报代码
时间: 2023-09-12 13:13:24 浏览: 78
以下是一个简单的 Processing 动态海报代码:
```processing
int numCircles = 50;
float[] x = new float[numCircles];
float[] y = new float[numCircles];
float[] speedX = new float[numCircles];
float[] speedY = new float[numCircles];
float[] radius = new float[numCircles];
color[] colors = new color[numCircles];
void setup() {
size(500, 500);
smooth();
noStroke();
// 初始化圆的位置、速度、半径和颜色
for (int i = 0; i < numCircles; i++) {
x[i] = random(width);
y[i] = random(height);
speedX[i] = random(-2, 2);
speedY[i] = random(-2, 2);
radius[i] = random(10, 50);
colors[i] = color(random(255), random(255), random(255), 100);
}
}
void draw() {
background(0);
// 移动圆的位置
for (int i = 0; i < numCircles; i++) {
x[i] += speedX[i];
y[i] += speedY[i];
// 碰到边缘反弹
if (x[i] < 0 || x[i] > width) {
speedX[i] *= -1;
}
if (y[i] < 0 || y[i] > height) {
speedY[i] *= -1;
}
}
// 绘制圆
for (int i = 0; i < numCircles; i++) {
fill(colors[i]);
ellipse(x[i], y[i], radius[i], radius[i]);
}
}
```
代码中使用了 Processing 的基本绘图函数,通过不断更新圆的位置和颜色实现了一个简单的动态海报效果。你可以根据需求调整圆的数量、大小、颜色等参数,增加更多的交互和动画效果。