2017年4月19日水曜日

月の自転・公転周期デモ

月の自転・公転周期の説明デモ。動いているのはこちら。意図せずもドラoもんカラー。
float theta=0;
int n=0;

void setup()
{
  size(1000, 1000);
  background(255);
  noLoop();
}

void draw()
{
  float r=width/3;
  float re=width/8;
  float rm=width/10;

  background(255);
  stroke(100);
  fill(0, 0, 255);
  ellipse(width/2, height/2, re, re);
  stroke(0);

  fill(255, 255, 0);

  ellipse(width/2+r*cos(theta), height/2+r*sin(theta), rm, rm);
  fill(255, 0, 0);

  ellipse(width/2+r*cos(theta)+0.35*rm*cos(PI+1*theta), height/2+r*sin(theta)+0.35*rm*sin(PI+1*theta), rm*0.2, rm*0.2);
  theta+=PI/200;
}

void mousePressed() {
  if (n==0) {
    loop();
    n=1;
  } else {
    noLoop();
    n=0;
  }
}