Matlab学习中的betsy ross 问题。用matlab函数画1777年的美国国旗。

五角星绘制部分是自己想出来的方法去画上的。具体代码参考如下。

先是绘制矩形的函数

 function DrawRect(a,b,L,W,c)
%Adda a Rectangle to the current window .Assumes hold is on.
%The Rectangle has vertices (a,b),(a+L,b),(a,b+W),(a+L,b+W)
%The c is color which is in the form of 'rgb vector' or one of the built-in
%clolors such as 'r','g','y','b'
x=[a,a+L,a+L,a];
y=[b,b,b+W,b+W];
fill(x,y,c);

然后是绘制五角星的代码

 function DrawStar(x1,y1,dr,c)
%the center of the five-stars is at (x1,y1)
%the radius of five-stars
%the color of the five-star
dtheta=*pi/;
hold on
axis equal off
j=:;
%外部五个点
x=x1+dr*cos(j*dtheta+pi/);
y=y1+dr*sin(j*dtheta+pi/);
%内部五个点
xl=x1+dr*cos(j*dtheta+*pi/)/;
yl=y1+dr*sin(j*dtheta+*pi/)/;
%Seperately take the ten points into vector
X=[x(),xl(),x(),xl(),x(),xl(),x(),xl(),x(),xl()];
Y=[y(),yl(),y(),yl(),y(),yl(),y(),yl(),y(),yl()];
%then draw it.
fill(X,Y,c);

然后调用上面的两个函数,绘制整个旗帜

 function DrawFlag(a,b,L1,W1,L2,r1,r2)
%Adds a -star,-stripe Colonial flag to the current
%Figure window.Assumes hold id on
%The flag is L1-by-W1 with lower left corner at(a,b).
%The length fo the blue area is L2.The ring of stars has radius r1 and its
%center is the center of the blue area
%the radius of the individual stars is r2
clc
close all
figure
hold on
s=W1/;
axis equal off
for k=:
%Draw the kth stripe
bk=b+(k-)*s;
if rem(k,)==&&k<=
DrawRect(a,bk,L1,s,'r');
elseif rem(k,)==&&k<=
DrawRect(a,bk,L1,s,'w');
elseif rem(k,)==&&k>=
DrawRect(a+L2,bk,L1-L2,s,'r');
else DrawRect(a+L2,bk,L1-L2,s,'w');
end
end
DrawRect(a,b+*s,L2,*s,'b');
%draw star
theta=*pi/;
xc=(a+L2)/;
yc=9.5*s;
for k=:
xr=xc+r1*cos(k*theta+pi/);
yr=yc+r1*sin(k*theta+pi/);
DrawStar(xr,yr,r2,'w');
end
hold off

最新文章

  1. Java读取xml配置文件
  2. 一个C++宏定义与枚举定义重复的编译错误
  3. 邮件发送工具类 SendMail.java
  4. 黑客白皮书:如何成为一名黑客(附FAQ)
  5. hdu4035(概率dp)
  6. Ansible playbook循环实践总结&lt;一&gt;
  7. apache和tomcat公用80端口
  8. 如何排查CPU飙升的Java问题
  9. Java 集合系列(四)—— ListIterator 源码分析
  10. spring boot项目中处理Schedule定时任务
  11. windows server 2003产生的 Minidmp蓝屏文件分析求助
  12. shop++改造之Filter类
  13. ProtocolError: &lt;ProtocolError for 127.0.0.1/RPC2: 401 Unauthor.
  14. Scala之List,Set及Map基本操作
  15. python 全栈开发,Day87(ajax登录示例,CSRF跨站请求伪造,Django的中间件,自定义分页)
  16. Linux命令: 向文件写内容,编辑文件,保存文件,查看文件,不保存文件
  17. Zxing图片拉伸解决 Android 二维码扫描
  18. java_Observer Design Pattern
  19. Spring入门(一)— IOC、DI
  20. 分布式架构核心RPC原理

热门文章

  1. [redis] 几种redis数据导出导入方式
  2. No.11_功能规格说明书
  3. 5337朱荟潼Java实验报告一
  4. 关于‘1001.A+B Format (20)’的解题报告
  5. 我是一名IT小小鸟
  6. Teamwork(The second day of the team)
  7. InputStreamReader &amp; OutputStreamWriter
  8. Hadoop到底能做什么?怎么用hadoop?
  9. “四则运算生成程序——GUI支持和部分功能改进”链接
  10. CMD命令去导出文件下的文件名称到EXCEL