Betsy Ross Problem
2024-09-22 07:14:37
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
最新文章
- Java读取xml配置文件
- 一个C++宏定义与枚举定义重复的编译错误
- 邮件发送工具类 SendMail.java
- 黑客白皮书:如何成为一名黑客(附FAQ)
- hdu4035(概率dp)
- Ansible playbook循环实践总结<;一>;
- apache和tomcat公用80端口
- 如何排查CPU飙升的Java问题
- Java 集合系列(四)—— ListIterator 源码分析
- spring boot项目中处理Schedule定时任务
- windows server 2003产生的 Minidmp蓝屏文件分析求助
- shop++改造之Filter类
- ProtocolError: <;ProtocolError for 127.0.0.1/RPC2: 401 Unauthor.
- Scala之List,Set及Map基本操作
- python 全栈开发,Day87(ajax登录示例,CSRF跨站请求伪造,Django的中间件,自定义分页)
- Linux命令: 向文件写内容,编辑文件,保存文件,查看文件,不保存文件
- Zxing图片拉伸解决 Android 二维码扫描
- java_Observer Design Pattern
- Spring入门(一)— IOC、DI
- 分布式架构核心RPC原理
热门文章
- [redis] 几种redis数据导出导入方式
- No.11_功能规格说明书
- 5337朱荟潼Java实验报告一
- 关于‘1001.A+B Format (20)’的解题报告
- 我是一名IT小小鸟
- Teamwork(The second day of the team)
- InputStreamReader &; OutputStreamWriter
- Hadoop到底能做什么?怎么用hadoop?
- “四则运算生成程序——GUI支持和部分功能改进”链接
- CMD命令去导出文件下的文件名称到EXCEL