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

Betsy Ross Problem的更多相关文章

  1. 1199 Problem B: 大小关系

    求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...

  2. No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.

    Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...

  3. C - NP-Hard Problem(二分图判定-染色法)

    C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:262144 ...

  4. Time Consume Problem

    I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...

  5. Programming Contest Problem Types

        Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...

  6. hdu1032 Train Problem II (卡特兰数)

    题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能.    (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...

  7. BZOJ2301: [HAOI2011]Problem b[莫比乌斯反演 容斥原理]【学习笔记】

    2301: [HAOI2011]Problem b Time Limit: 50 Sec  Memory Limit: 256 MBSubmit: 4032  Solved: 1817[Submit] ...

  8. [LeetCode] Water and Jug Problem 水罐问题

    You are given two jugs with capacities x and y litres. There is an infinite amount of water supply a ...

  9. [LeetCode] The Skyline Problem 天际线问题

    A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...

随机推荐

  1. java控制台编译通过,运行出现找不到或无法加载主类的情况

    参考链接:http://www.knowsky.com/1046493.html 当建了一个包之后(假设建的包的名字为com),找到该java文件的com目录,发现编译能够通过,但是运行的时候出现了一 ...

  2. Beta版本互评

    基于NABCD评论作品,及改进建议 经过alpha发布之后,迫不及待的使用了psp daily这款软件,使用非常方便,基本的功能都可以实现,经过beta周之后,我对这款产品非常期待,希望能给我更友好的 ...

  3. 第十章I/O

    系统级i/o 开始进程时的三个标准: 标准输入(描述符0):STDIN_FILENO 标准输出(描述符1):STDOUT_FILENO 标准错误(描述符2):STDERR_FILENO 文件位置: 从 ...

  4. 20172321『Java程序设计』课程 结对编程练习_四则运算第二周阶段总结

    20172321『Java程序设计』课程 结对编程练习_四则运算第二周阶段总结 结对伙伴 学号 :20172324 姓名 :曾程 伙伴第一周博客地址: 对结对伙伴的评价:一个很优秀的同学,在这次项目中 ...

  5. c# bitmap和new bitmap(bitmap)及在System.Drawing.Image.get_RawFormat()报错“参数无效”

    问题情境: 给picturebox赋image属性,我用一下代码,出错: Bitmap theBitmap = convertCameraData.display(rawDataArray, heig ...

  6. XCODE的演变及使用经验分享

    IOS编程使用的是XCODE 编译器,安装XCODE你需要一台MAC(黑苹果也可以,个人不推荐,不稳定),然后直接去MAC上的APP STORE上下载安装就行,很简单,再次不做过多介绍... OK,那 ...

  7. 第一次spring冲刺第7天

    讨论成员:王俊凯.王逸辉.罗凯杰.马志磊 讨论问题:进行UI设计的详细讨论,虽然结果各有争议,但最终确定了较为简单的布局页面,并且开始收集精美页面的案例 冲刺尚未结束,同志还需努力,致力于最后.

  8. Software Defined Networking(Week 2, part 3)

    Control of Packet-switch Network 我们已经讨论过中心控制网络的原理,但主要是以电话网络做模型的.现在我们来看看对于分组交换网络的控制是如何改进的. Why Separa ...

  9. HDU 2106 母猪的故事

    http://acm.hdu.edu.cn/showproblem.php?pid=2160 Problem Description 话说现在猪肉价格这么贵,著名的ACBoy 0068 也开始了养猪生 ...

  10. 使用JavascriptExecutor改变页面元素

    如下如html的页面代码 <html> <body> <input type="text" name="text" value=& ...