正在加载图片...
4.Stars and Stripes forever At the end of this problem description,parts of a script M-file are given.This program may be used to draw the US flag.The US flag has 13 horizontal rows,alternating with red and white.Row 1 is red, row 2 is white,and so on,for 7 red rows and 6 white ones.A solid blue rectangle occupies the upper left corner,from rows 7 to 13 and it is half the width of the flag.There are 50 white stars arranged in the blue patch. Here's how you complete the code to finish the flag program. ·Write a function flag createFlagStrips O that will make the stripes and the blue patch.(Red value 0.15,blue has value 0.4,and white has value 0.0.)Plotted as indicated it should look like: Read through the rest of the MATLAB code and understand what it is trying to do.The bottom part is for placing the stars. Write the function plotStar(x,y,r).x and y are the points that define the center of the star,and r is its radius.Notice that the 5 points on a star are all located on a circle centered at x and y with radius r.If you drew lines from the center to the points of the star,those lines would be separated by 72 degrees,(72=360/5).To draw the star,imagine that the top point of the star is numbered 1, the one to its right 2,ands o on.You can make a star easily by drawing a line from point 1,to 4,to 2,to 5,to 3 and back to 1.Here's an example of plotStar(1,3,2). You might find it useful to use the sin (and cos (functions.The argument to these functions should be expressed in radians.In MATLAB,the conversion from degrees to radians is given by: rads=pi*a/180,where a is an angle in degrees and rads is the same angle expressed in radians. You should use the plot (function using white solid lines.Here are the details: PLOT Linear plot.PLOT(X,Y)plots vector Y versus vector X.4. Stars and Stripes forever At the end of this problem description, parts of a script M-file are given. This program may be used to draw the US flag. The US flag has 13 horizontal rows, alternating with red and white. Row 1 is red, row 2 is white, and so on, for 7 red rows and 6 white ones. A solid blue rectangle occupies the upper left corner, from rows 7 to 13 and it is half the width of the flag. There are 50 white stars arranged in the blue patch. Here’s how you complete the code to finish the flag program. • Write a function flag = createFlagStrips () that will make the stripes and the blue patch. (Red value 0.15, blue has value 0.4, and white has value 0.0.) Plotted as indicated it should look like: • Read through the rest of the MATLAB code and understand what it is trying to do. The bottom part is for placing the stars. • Write the function plotStar (x, y, r). x and y are the points that define the center of the star, and r is its radius. Notice that the 5 points on a star are all located on a circle centered at x and y with radius r. If you drew lines from the center to the points of the star, those lines would be separated by 72 degrees, (72 = 360/5). To draw the star, imagine that the top point of the star is numbered 1, the one to its right 2, ands o on. You can make a star easily by drawing a line from point 1, to 4, to 2, to 5, to 3 and back to 1. Here’s an example of plotStar (1, 3, 2). • You might find it useful to use the sin () and cos () functions. The argument to these functions should be expressed in radians. In MATLAB, the conversion from degrees to radians is given by: rads = pi*a/180, where a is an angle in degrees and rads is the same angle expressed in radians. • You should use the plot () function using white solid lines. Here are the details: PLOT Linear plot. PLOT(X,Y) plots vector Y versus vector X
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有