Betsy Ross Problem
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的更多相关文章
- 1199 Problem B: 大小关系
求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...
- 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 ...
- C - NP-Hard Problem(二分图判定-染色法)
C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:262144 ...
- Time Consume Problem
I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...
- Programming Contest Problem Types
Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...
- hdu1032 Train Problem II (卡特兰数)
题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能. (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...
- BZOJ2301: [HAOI2011]Problem b[莫比乌斯反演 容斥原理]【学习笔记】
2301: [HAOI2011]Problem b Time Limit: 50 Sec Memory Limit: 256 MBSubmit: 4032 Solved: 1817[Submit] ...
- [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 ...
- [LeetCode] The Skyline Problem 天际线问题
A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...
随机推荐
- API验证
API验证说明 API验证: a. 发令牌: 静态 PS: 隐患 key被别人获取 b. 动态令牌 PS: (问题越严重)用户生成的每个令牌被黑客获取到,都会破解 c. 高级版本 PS: 黑客网速快, ...
- js备忘录5
函数的全解析 原文链接: http://mp.weixin.qq.com/s?src=11×tamp=1509672643&ver=491&signature=9fD ...
- 对视频播放软件KMplayer的评价
刚进入大一的时候接触到了KMplayer,由于当时收集了不同格式的电影视频却没有合适的播放器播放出来,后来在网上知道了所谓的万能播放器的KMplayer,下载用了过后,才知道这的确是一款万能播放器. ...
- 20162328蔡文琛 week09 大二
20162328蔡文琛 大二week09 教材学习内容总结 堆是一棵完全二叉树,其中每个元素大于等于其所有子节点的值. 向堆中添加一个元素的方法是,首先将这个元素添加为叶节点然后将其向上移动到合适的位 ...
- wcf的DataContractAttribute与DataMenmberAttribute
文章:序列化和反序列化的几种方式(DataContractSerializer)(二) 介绍了序列化控制细节.哪些字段可以序列化,序列化后这些字段的名字.
- 索引超出了数组界限。 在 System.Collections.Generic.Dictionary`2.Resize
博问:Dictionary 超出了数组界限 异常: Exception type: IndexOutOfRangeException Exception message: 索引超出了数组界限. 在 S ...
- Python库moviepy
目录 介绍和下载安装 视频截取和拼接 视频加水印
- 类似jq的即点即改
<?php namespace app\controllers; use Yii;use yii\filters\AccessControl;use yii\web\Controller;use ...
- rocketmq 主机负载异常飙高问题的解决
最近在部署rocketmq到物理机时, 发现并解决了一个主机Load异常飙高的问题, 觉得有必要记录一下. 我们采用了rocketmq(https://github.com/alibaba/Rocke ...
- Windows系统下搭建Appium自动化测试框架
简介 一种开源的测试框架(http://appium.io/) 能够用来测试原生Android/iOS应用.混合应用以及webapp 通过webdriver协议来操作应用,其核心是一个web服务器,接 ...