书名:代码本色:用编程模拟自然系统
1、弧度和度数
图3-3
2、将度数转化为弧度
3、函数
4、绕着自己的中心旋转的指挥棒float angle = 0;
float aVelocity = 0;
float aAcceleration = 0.001;
void setup() {
size(200,200);
}
void draw() {
background(255);
fill(175);
stroke(0);
rectMode(CENTER);
translate(width / 2,height / 2);
rotate(angle);
line(-50,0,50,0);
ellipse(50,0,8,8);
ellipse(-50,0,8,8);
aVelocity += aAcceleration;
angle += aVelocity;
}
程序开始运行时,指挥棒并没有转动,随着旋转加速,它的转动速度也越来越快。 |
|