Help with function that plots a specific shape and fills with specific color

6 views (last 30 days)
Create a MATLAB function called drawShape() that performs the following:
a. Displays a numbered list of shapes as shown below
b. Uses the inbuilt MATLAB function input()to request the user to
i. select a shape from this list, and
ii. a letter to indicate the color to fill the shape (for example: `r’ for red)
You should decide the dimensions of the shapes.
1. Right angled Triangle
2. Circle
3. Square
for example, drawShape(2,g) should plot a green circle.
The only thing I'm struggling with is ,for example, in drawShape(a,b) , how can the function be written for "a" to pull the specific shape plot, and "b" to fill the shape with a specific color.

Answers (2)

Walter Roberson
Walter Roberson on 8 Feb 2014
A shape with N sides can be built by taking points 360/N degrees apart on a circle.
When you create a shape, the operation you use will probably have a FaceColor property.

Image Analyst
Image Analyst on 8 Feb 2014
A triangle can be plotted with plot() or line().
A square can be plotted with plot(), line() or rectangle().
For any of them, you can use fill() or patch() to get solid shapes instead of just the perimeter.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!