The Art of Coding by Ursyn Anna; Wyeld Theodor; al-Rifaie Mohammad Majid

The Art of Coding by Ursyn Anna; Wyeld Theodor; al-Rifaie Mohammad Majid

Author:Ursyn, Anna; Wyeld, Theodor; al-Rifaie, Mohammad Majid
Language: eng
Format: epub
Publisher: CRC Press LLC
Published: 2020-02-07T00:00:00+00:00


3.3.4.5Under the hood

The complete design pattern application consists of more than two dozen MATLAB functions. There is no need to study this code in order to use the application successfully; however, a curious user might want to look at the overall sequence of steps that xshapes must go through to produce a picture. The internal comments identify the role each function plays.

3.3.4.6Challenges and projects

Look at the MATLAB help for the plot function (enter help plot). Do you see how you can change the line colour or line style of xshapes pictures? Hint: Look at definition of the Mplot function in the SHAPES folder.

Look at the MATLAB help for the fill function (enter help fill). Do you see how you can use it to fill closed areas of an xshapes picture with colour? Hint: Look at the Mfill function in the SHAPES folder. Un-comment the call to Mfill in xshapes and comment out the other display functions (i.e., put a “%” sign at the beginning of a line in the program to comment it out; remove the “%” at the beginning of the line you want to be executed.) What kinds of pictures do you get now? NB. The MATLAB fill function cannot handle some of the more complex figures that xshapes can generate, so only try this exercise with fairly simple figures. Use small values for length (≤ 8).

After you complete #2, try the sfill function. It takes the same four inputs as xshapes. Use small values for length (≤ 8). What problems arise when length is 16 or greater?

If you have access to an image-processing program (e.g., GIMP), see if you can smooth out the pixelised character of xshapes images with a blur or anti-aliasing function.

Try to add background and fill colours to an xshapes image with, e.g.: MS Paint, Paint 3D, etc. First save the image in a file format supported by the other program: .bmp, .png, or .jpg for example.

In the definition of xshapes, comment out the call to Mplot and un-comment the call to Mpoints. When you now run xshapes or autoxshapes, what kinds of pictures do you get? Hint: See Figure 3.12.

If you do #5, save a hard copy of the picture. Play “connect the dots” with pencil and paper and see if you can come up with an interesting figure.

With a compass draw a circle. Then, with a protractor, mark off five equally spaced points on the circle (i.e., put the points 72o apart). Now, going either clockwise or counter-clockwise around the circle, connect each point with a straight line to the point after its neighbour until you get back to the starting point. What shape do you get? The result should suggest how the function rcoord makes interesting shapes from points that lie on a circle.

After you have run autoxshapes or xshapes many times, you will probably notice that certain shapes appear very often. Perhaps the most obvious one is the star with different numbers of points. What other shapes appear frequently? Are



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.