# How to write Morse code into Plot Dashing?

How can we define a dashing pattern in a plot such that it reads arbitrary text in Morse code?

For instance

Graphics[{DotDashed, Line[{{0, 0}, {5, 0}}]}]


this could be interpreted as ".-" that is "a" in Morse code.

Proper spacing would be desirable in order to distinguish ".-" (a) from "-." (n).

(Inspired by @rcollyer's comment to my answer to this question.)

• I can't properly express how amused I am that my flippant remark has resulted in this. +1 to both. Nov 21, 2014 at 23:34

First define the Morse code (from rosettacode.org with corrections by @evanb)

morsecode = (#1 -> Characters[#2]) & @@@ {
{"a", ".-"}, {"b", "-..."}, {"c", "-.-."},
{"d", "-.."}, {"e", "."}, {"f", "..-."},
{"g", "--."}, {"h", "...."}, {"i", ".."},
{"j", ".---"}, {"k", "-.-"}, {"l", ".-.."},
{"m", "--"}, {"n", "-."}, {"o", "---"},
{"p", ".--."}, {"q", "--.-"}, {"r", ".-."},
{"s", "..."}, {"t", "-"}, {"u", "..-"},
{"v", "...-"}, {"w", ".--"}, {"x", "-..-"},
{"y", "-.--"}, {"z", "--.."}, {"0", "-----"},
{"1", ".----"}, {"2", "..---"}, {"3", "...--"},
{"4", "....-"}, {"5", "....."}, {"6", "-...."},
{"7", "--..."}, {"8", "---.."}, {"9", "----."}
};


Use AbsoluteDashing and define dots as short dashed, lines as long dashes and include proper spacing between symbols and characters.

morserule =  Append[(#[[1]] -> Append[Riffle[#[[2]], 3], 12]) & /@ (morsecode /. {"." -> 2 , "-" -> 7}), " " -> {0, 17}];

toMorseDash[s_String] :=  Flatten[Characters[ToLowerCase@s] /. morserule]


Now we can test in a simple line.

Graphics[{Thickness[0.02], AbsoluteDashing[toMorseDash[" Morse Code "]], Line[{{0, 0}, {15, 0}}]}]


For plots, use PlotStyle-> AbsoluteDashing[toMorseDash["text"]]

Plot[Sin[t], {t, 0, 4 Pi}, PlotStyle -> {Thick, AbsoluteDashing[toMorseDash[" Sine Wave"]]}]


• NB: the original post had the same encodings for 1-4 as 6-9. This is now fixed. Nov 21, 2014 at 22:41
• Or WolframAlpha["Morse code \"Dot/Dash Pattern\"",{{"MorseCodeTranslation", 1}, "Plaintext"}] :) Nov 22, 2014 at 7:21
• The only thing missing at this point is the corresponding sound with the "di"'s and "da"'s... :D Feb 17, 2016 at 17:07