MATLAB Community

MATLAB, community & more

Flag Math on Bastille Day

Let me start with a graphical riddle. In what sense is the following equivalence true?

To learn the answer, read on!

I recently came across Nick Higham’s fun post on one-liners in MATLAB. That piece and the approach of Bastille Day on July 14th made me think of another one-line program.

image([3 2 1]);colormap(flag)

Pretty impressive, considering that it’s only 29 characters long. Is this the shortest flag program we can write?

As I thought about flags and MATLAB, I gave myself the following task. Using only the colormap “flag” and images of vectors, how many national flags can we construct? Probably more than you might guess. Let’s go on a little tour.

Tidying Up the Flag

Proper flags shouldn’t have numbers running their edges, so I’d like to hide the tick marks and labels. Since I plan to do this multiple times in the script below, I’m going to use an anonymous function for compactness. It’s not necessary, but I like how it keeps the code tidy.

notick = @(ax) set(ax,'XTick',[],'YTick',[])
notick = 
    @(ax)set(ax,'XTick',[],'YTick',[])


France

In honor of Bastille Day, we start with France.

france = [3 2 1]
france = 

     3     2     1

image(france)
title('Vive la France!')
notick(gca)

France is the only red, white, and blue tricolor with vertical bars. But if we look at horizontal patterns, we find many more.

Netherlands

Netherlands is a rotated version of France.

netherlands = rot90(france)
netherlands = 

     1
     2
     3

image(netherlands);
title('The Netherlands')
notick(gca)

Luxembourg

Luxembourg, next door to the Netherlands, uses essentially the same flag. A pedantic Luxembourger or professional vexillologist may protest that the colors are slightly lighter and the aspect ratio is slightly different. We will gloss over these details.

luxembourg = netherlands
luxembourg = 

     1
     2
     3

image(luxembourg)
title('Luxembourg')
notick(gca)

Thailand

thailand = [netherlands; flipud(netherlands)]
thailand = 

     1
     2
     3
     3
     2
     1

image(thailand)
title('Thailand')
notick(gca)

Now we see the significance of the graphical riddle that we listed at the top of this post.

Russia

Russia’s flag is a variant on the three horizontal bands. We’ll use circshift to do a circular permutation of the colors in the Netherlands flag.

russia = circshift(netherlands,2)
russia = 

     2
     3
     1

image(russia)
title('Russia')
notick(gca)

Austria

austria = netherlands([1 2 1])
austria = 

     1
     2
     1

image(austria)
title('Austria')
notick(gca)

Indonesia

indonesia = netherlands(1:2)
indonesia = 

     1
     2

image(indonesia)
title('Indonesia')
notick(gca)

Monaco

monaco = indonesia
monaco = 

     1
     2

image(monaco);
title('Monaco')
notick(gca)

Poland

poland = flipud(monaco)
poland = 

     2
     1

image(poland);
title('Poland')
notick(gca)

There you have it. A veritable Tour d’Image. I count nine separate vector flags using only red, white, or blue. Did I miss any?

As an exercise for the reader, express all flags in terms of the vector “france”.

Addendum #1: Costa Rica

In the comments, Matt Tearle points out another flag that fits the model. It’s a kind of dual to Thailand. I am now convinced that vexillology conventions should always occur in the Netherlands, its flag being the indispensable element at the center of all flag alchemy.

costarica = [flipud(netherlands); netherlands]
costarica = 

     3
     2
     1
     1
     2
     3

image(costarica);
title('Costa Rica')
notick(gca)

flags_12

Addendum #2

And Richard Alcock from MathWorks UK writes in to give us this timely and poignant example.

reflex_blue = [0 51 153]/255;
yellow = [255 204 0]/255;
[x, y] = pol2cart(linspace(0, 2*pi, 13), 1/3); plot(x, y, 'p', 'MarkerSize', 20, ...
    'MarkerEdgeColor', yellow, 'MarkerFaceColor', yellow); axis('equal'); set(gca, 'Color', reflex_blue,  ...
    'XTick', [], 'YTick', [], ...
    'Xlim', [-.75 .75], 'Ylim', [-.5, .5])

flags_13


Addendum #3: Yemen

Sean de Wolski reminded me that black is one of the four colors of the “flag” colormap, thereby letting us add the Yemeni flag to our list. I thought the addition of black might give us a few more flags, but Yemen seems to be the end of it.

yemen = [1; 2; 4];
image(yemen)
title('Yemen')
notick(gca)

flags_14

|
  • print

댓글

댓글을 남기려면 링크 를 클릭하여 MathWorks 계정에 로그인하거나 계정을 새로 만드십시오.