在MatLab中畫彩虹

思路

  1. 畫8個不同半徑的圓
  2. 定義8中不同的填充顏色
  3. 利用fill填色,從半徑最大的開始,由外往內,這樣做可以讓後面填色的覆蓋之前填色

具體代碼

<code>figure;
pause(5);
t=0:0.001:pi;
x=8*cos(t);
y=8*sin(t);
fill(x,y,'r');
hold on;
x=7*cos(t);
y=7*sin(t);
patch(x,y,[1 0.5 0]);
hold on;
x=6*cos(t);
y=6*sin(t);
fill(x,y,'y');
hold on;
x=5*cos(t);
y=5*sin(t);
fill(x,y,'g');
hold on;
x=4*cos(t);
y=4*sin(t);
patch(x,y,[ 0.5843 0.8157 0.9882]);
hold on;
x=3*cos(t);
y=3*sin(t);
fill(x,y,'b');
hold on;
x=2*cos(t);
y=2*sin(t);
patch(x,y,[0.4039 0.0078 0.3686]);
t=0:0.01:pi;
x=cos(t);
y=sin(t);
fill(x,y,'w');
plot([-1 1],[0 0],'w');
axis equal;/<code>

結果展示


在MatLab中畫彩虹

Matlab畫彩虹


分享到:


相關文章: