processing中5个运用三角函数的动画案例代码
时间: 2024-03-21 11:43:04 浏览: 25
以下是5个运用三角函数的动画案例的代码:
1. 环形动画
```
float angle = 0;
float radius = 100;
void setup() {
size(500, 500);
}
void draw() {
background(255);
float x = width/2 + cos(angle) * radius;
float y = height/2 + sin(angle) * radius;
ellipse(x, y, 20, 20);
angle += 0.05;
}
```
2. 波浪动画
```
float angle = 0;
float amplitude = 100;
float frequency = 0.02;
void setup() {
size(500, 500);
}
void draw() {
background(255);
float y = height/2 + sin(angle) * amplitude;
for (int x = 0; x < width; x += 10) {
ellipse(x, y, 10, 10);
}
angle += frequency;
}
```
3. 旋转动画
```
float angle = 0;
float radius = 100;
void setup() {
size(500, 500);
}
void draw() {
background(255);
translate(width/2, height/2);
rotate(angle);
ellipse(radius, 0, 20, 20);
angle += 0.05;
}
```
4. 弹跳动画
```
float angle = 0;
float amplitude = 100;
float frequency = 0.02;
void setup() {
size(500, 500);
}
void draw() {
background(255);
float y = height/2 + abs(sin(angle) * amplitude);
ellipse(width/2, y, 20, 20);
angle += frequency;
}
```
5. 变形动画
```
float angle = 0;
float amplitude = 100;
float frequency = 0.02;
void setup() {
size(500, 500);
}
void draw() {
background(255);
float x = width/2 + cos(angle) * amplitude * sin(angle);
float y = height/2 + sin(angle) * amplitude;
ellipse(x, y, 20, 20);
angle += frequency;
}
```
以上代码都可以在processing中直接运行,可以通过调整参数来改变动画的效果。