用processing画李萨如曲线
李萨如曲线
有没有对示波器上变化曲线产生过兴趣,它叫做李萨如曲线:
数学上,利萨茹(Lissajous)曲线(又称利萨茹图形、李萨如图形或鲍迪奇(Bowditch)曲线)是两个沿着互相垂直方向的正弦振动的合成的轨迹
(参见http://zh.wikipedia.org/wiki/%E5%88%A9%E8%90%A8%E8%8C%B9%E6%9B%B2%E7%BA%BF)
代码
1: //int n=4;
2: int p=17;
3: int q=15;
4:
5: int a = displayWidth /2 ;
6: int b = a;//displayHeight /2 ;
7:
8: int radius = 2;
9: float miu = 0;//PI / 2 / p;
10: float miu_max = TWO_PI;
11: float miu_delta = miu_max / 100;
12:
13: public void setup() {
14: size(displayWidth, displayHeight);
15: background(0);
16: frameRate(2);
17:
18: a = displayWidth / 5 ;
19: b = a ;
20: }
21:
22: public void draw() {
23:
24: miu += miu_delta;
25: if (miu >= miu_max)
26: miu = 0;
27: // if (miu >= miu_max)
28: // {
29: // miu_delta = -miu_delta;
30: // miu += miu_delta;
31: // }
32: // else if (miu < 0)
33: // {
34: // miu_delta = -miu_delta;
35: // miu += miu_delta;
36: // }
37:
38: fill(0,0,0,250);
39: rect(-1,-1, displayWidth+1, displayHeight+1);
40:
41: int last_x = -1;
42: int last_y = -1;
43:
44: for (float theta=0;theta<TWO_PI;theta+=TWO_PI/360)
45: {
46: int x = (int) (a * sin(p * theta)) + displayWidth /2;
47: int y = (int) (b * sin(q * theta + (miu))) + displayHeight /2;
48:
49: colorMode(HSB, 255);
50: stroke(90, 255, 255);
51: fill(90, 255, 255);
52:
53: if (last_x != -1 >> last_y != -1)
54: {
55: line(last_x, last_y, x, y);
56: line(last_x-1, last_y, x-1, y);
57: }
58:
59: last_x = x;
60: last_y = y;
61:
62: //ellipse(x, y, radius, radius);
63: }
64:
65: }
截图