Approach to drawing the Indian flag
- First, we need to create a 300X600X3 matrix and fill it with white. 300 — the number of lines, and 600 — number of columns. Color image requires 3 channels, so 3 represents the RGB (red, green, blue) channel.
img = uint8 (zeros (300, 600, 3))
- Divide the matrix by three pieces (0-100) rows for saffron color, (101-200) rows for white and Ashoka chakra, (201-300) rows for green.
- Fill in the matrix with saffron color (255, 153 , 51) from the 1st row to the 100th row.
img (1: 100, 1: 600, 1) = 255; img (1: 100, 1: 600, 2) = 153; img (1: 100; 1: 600, 3) = 51;
- Fill the matrix with green (19, 136, 8) from line 201 to 300.
img (201: 300, 1: 600, 1) = 19; img (201: 300, 1: 600, 2) = 136; img (201: 300, 1: 600, 3) = 8;
- To make the Ashoka chakra, first we need to understand the equation of distance between two given coordinates.
(distance) 2 = (x2-x1) 2 + (y2-y1) 2
(x1, y1) and (x2, y2) — two given coordinates.
- Using the above equation, we can make a circle of the ashok chakra. The coordinates of the center of the matrix and the circle (150, 300). To draw a circle, the inner radius is 40 and the outer radius is 45.
- The angle between two adjacent spokes of the ashoka chakra is (360 / n) = 15 o , where n (number of spokes) = 24. atand — this is a MATLAB function used to determine the angle.
|
|
The implementation is shown below:
|
Output: