User:Brhaspati/indflag
Appearance
This is a temporary page to get a good representation of the Flag of India.
Sources
[edit]This implementation is based on a combination of FOTW description and the image on the GOI directory. The non-intuitive part of the code is in drawing the chakra, for which I used the FOTW figure as a guide.
Bugs
[edit]Current problems with the figure produced by this code:
- Figure needs to be anti-aliased.
- Chakra looks too blue in the center and too white in the edges. Looks a little like some sort of bacterium, especially at reduced sizes. This needs to be rectified.
Code
[edit]% indflag.m % Written by [[User:Brhaspati]], 2005. % Code should work in most versions of MATLAB. % Released under GPL. % % MATLAB is a trademark of MathWorks Inc. % clear all; close all; clc; % Define colors (cite source if possible) saffron = [251 119 0] ./ 255; % GOI uses this. FOTW uses [255 204 0]. white = [255 255 255] ./ 255; green = [ 19 136 8] ./ 255; % GOI uses this. FOTW uses [51 153 51]. navyblue = [ 0 0 128] ./ 255; radius = 1; % Any positive real number should do - everything else is scaled to this. ratio = 0.75; % ratio of diameter of Ashok chakra to the width of the white band. % This is 75% of the width. Though is misused by flag makers. npoints = 5000; % Use more points for better circles and slower rendering. twopi = pi + pi; % self-explanatory r = 5 * pi / 72; % radius of the small circles around the rim of the Ashok chakra rim = 5 * (1 + pi/72); % radius of the rim y = 6 * radius / ratio; % (1/6) of the height of the flag. x = 4.5 * y; % width of the flag, keeping the specified 3:2 width:height ratio. figure; hold on; axis equal; axis ([-x x -3*y 3*y]); axis off; % Top band, saffron. X = [-x x x -x]; Y = [y y 3*y 3*y]; fill (X, Y, saffron, 'EdgeColor', saffron); % Middle band, white. X = [-x x x -x]; Y = [y y -y -y]; fill (X, Y, white, 'EdgeColor', white); % middle band % Bottom band, green. X = [-x x x -x]; Y = [-y -y -3*y -3*y]; fill (X, Y, green, 'EdgeColor', green); % bottom band % Begin drawing the navy blue Ashok chakra. % Using FOTW description for shape and ratio of the chakra. % blue rim [X,Y] = pol2cart (linspace (0, twopi, npoints), ones (1, npoints) * 6 * radius); fill (X, Y, navyblue, 'EdgeColor', navyblue); % white annulus. Spokes will go here later. [X,Y] = pol2cart (linspace (0, twopi, npoints), ones (1, npoints) * rim * radius); fill (X, Y, white, 'EdgeColor', navyblue); % blue core [X,Y] = pol2cart (linspace (0, twopi, npoints), ones (1, npoints) * radius); fill (X, Y, navyblue, 'EdgeColor', navyblue); % 24 spokes for theta = 0:15:359 % calculate some angles t = theta * pi / 180.0; t1 = (theta + 3.75) * pi / 180.0; t2 = (theta - 3.75) * pi / 180.0; t11 = (theta + 7.5) * pi / 180.0; t22 = (theta - 7.5) * pi / 180.0; % draw a spoke. The spoke is a very thin pentagon, with its base resting on the core and the apex on the inner edge of the rim. X = [radius*cos(t1) radius*cos(t1)+radius*cos(t11) rim*radius*cos(t) radius*cos(t2)+radius*cos(t22) radius*cos(t2)]; Y = [radius*sin(t1) radius*sin(t1)+radius*sin(t11) rim*radius*sin(t) radius*sin(t2)+radius*sin(t22) radius*sin(t2)]; fill (X, Y, navyblue, 'EdgeColor', navyblue); % draw the small blue circles around the inner edge of the rim. [X,Y] = pol2cart (linspace (0, twopi, npoints), ones (1, npoints) * r * radius); X = X + rim*radius*cos(t11); Y = Y + rim*radius*sin(t11); fill (X, Y, navyblue, 'EdgeColor', navyblue); end