角度(旋转的指挥棒)

2022-04-25  本文已影响0人  大龙10

书名:代码本色:用编程模拟自然系统
作者:Daniel Shiffman
译者:周晗彬
ISBN:978-7-115-36947-5
目录

3.1 角度

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;
}

程序开始运行时,指挥棒并没有转动,随着旋转加速,它的转动速度也越来越快。

上一篇 下一篇

猜你喜欢

热点阅读