Calendar: Difference between revisions

3,065 bytes added ,  2 years ago
Line 4,816:
20 21 22 23 24 25 26
27 28 29 30 31 </pre>
 
At this point we have everything we need to generate a calendar. Since ASCII art is just a matrix of characters, we could trivially handle the display of the Snoopy banner. To make things more interesting, let's instead just display a magnified version of the calendar year as a banner.
 
FractalChars takes a string and rasterizes each character and then replaces each black pixel with the original character. The output is a matrix of characters suitable as a datum in the argument to DataGrid.
 
<lang Mathematica>FractalChars[rasterSize_,font_,char_String/;1==StringLength[char]]:=
ReplaceAll[ImageData[ImageCrop[Binarize[Rasterize[Style[char,FontFamily->font],RasterSize->rasterSize]]]],{1->" ",0->char}];
FractalChars[rasterSize_,font_,word_String]:=FractalChars[rasterSize,font,#]&/@Characters[word];
 
(*And here's the convenience function that ultimately calls DataGrid.*)
BannerGrid[finalSpacings_,finalBorderWidths_,finalOptions_,charGridder_Function,rasterSize_,text_String]:=
With[
{charData=FractalChars[rasterSize,"Courier",text]},
DataGrid[{1,StringLength@text},finalSpacings,finalBorderWidths,finalOptions,charGridder/@List/@charData]];
 
(*An example banner.*)
BannerGrid[{0,5},{{1,1},{0,0}},<|"border"->"X"|>,DataGrid[{1,1},{0,0},{{1,1},{0,0}},<||>,#]&,20,"1969"]//AsString</lang>
 
{{out}}
<pre>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
11 9999 666666 9999
1111111 99999999 66666666 99999999
11111111 9999999999 66666666 9999999999
11111111 9999 9999 6666 9999 9999
111 9999 999 6666 9999 999
111 999 999 666 999 999
111 999 999 6666 999 999
111 999 999 666 999 999
111 999 9999 666 66666 999 9999
111 9999 9999 66666666666 9999 9999
111 9999 99999 666666666666 9999 99999
111 99999999999 66666 6666 99999999999
111 9999999999 6666 666 9999999999
111 99 999 6666 666 99 999
111 9999 6666 666 9999
111 999 6666 666 999
111 9999 666 666 9999
111 9999 6666 6666 9999
11111111111 99999 6666 6666 99999
111111111111 99999999 6666666666 99999999
111111111111 99999999 6666666 99999999
99 6 99
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</pre>
 
=={{header|Nim}}==
23

edits