基本的lissajous图形

啥都看不见请换火狐.


操作:(先鼠标点一下图片)
q增加x方向振幅,w减小x方向振幅
e增加x方向频率,r减小x方向频率
t增加y方向频率,y减小y方向频率
u增加y方向相位
9重置,0清屏

lissajous图形是由两个方向垂直的正弦运动共同作用产生的.比如这个图,它的x,y方向运动方程是
$$x = A_1 sin(\omega_1 t)\\
y = A_2 sin(\omega_2 t + \theta)$$

改变\( \theta \)可以产生很多漂亮的图形,我Processing太烂暂时没做出来…以后补.

[lissajous1.pde][http://www.openprocessing.org/sketch/162070]
1
float nx = 1, ny = 1, theta_x = 0, theta_y = 12;
float Ax = 100, Ay = 100;
float x;
float p_x;
float p_y;
void setup(){
  size(400, 400);
  background(255);
  noFill();
  frameRate(100);
  x = 0;
  smooth();
}

void draw(){
  //horithon
  x += 1;
  p_x = sin(radians(nx * x) + theta_x) * Ax + height / 2;
  //vertical
  p_y = sin(radians(ny * x) + theta_y) * Ay + height / 2;
  //draw
  point(p_x, p_y);
  //update
  theta_y += 0.01;
}
void keyPressed(){
  if( key == 'q' || key == 'Q' ) {
    Ax += 2;
  }
  else if( key == 'w' || key == 'W' ){
    Ax -= 2;
  }
  else if( key == 'e' || key == 'E' ){
    nx += .01;
  }
  else if( key == 'r' || key == 'R' ){
    nx -= .01;
  } 
  else if( key == 't' || key == 'T' ){
    ny += .01;
  }
  else if( key == 'y' || key == 'Y' ){
    ny -= .01;
  }
  else if( key == 'u' || key == 'U' ){
    theta_y++;
  }
  else if( key == '9'){
    nx = 1;
    ny = 1;
    Ax = 100;
    Ay = 100;
    theta_y = 2;
    background(255);
  } 
  else if( key == '0'){
    background(255);
  }      
}