Joe Riel

9660 Reputation

23 Badges

20 years, 15 days

MaplePrimes Activity


These are replies submitted by Joe Riel

Use Windows File Explorer and look in that directory.  Is mayan.mla really there?  Did you unzip the Stupid.zip file?

Use Windows File Explorer and look in that directory.  Is mayan.mla really there?  Did you unzip the Stupid.zip file?

If you unpack mayan.mla from the zip file that I linked to on a preceding page, then you don't need to use the code that I posted. The code is only useful for creating mayan.mla (and for showing what I did).  If you want to create your own mla file, rather than the one I provided, then yes, you will need to change the argument in the LibraryTools:-Save command.

If you unpack mayan.mla from the zip file that I linked to on a preceding page, then you don't need to use the code that I posted. The code is only useful for creating mayan.mla (and for showing what I did).  If you want to create your own mla file, rather than the one I provided, then yes, you will need to change the argument in the LibraryTools:-Save command.

I'll probably add a blog entry for the next update, which includes glyphs for the mayan calendar,using the 260 day cycle.

I'll probably add a blog entry for the next update, which includes glyphs for the mayan calendar,using the 260 day cycle.

Use a semicolon rather than a colon when you do the assignment, then you may see what is wrong.  Backslashes in strings must be escaped (doubled).  Usually you can use forward slashes, but there are exceptions.  Here is what you want

libname := "C:\\Documents and Settings\\CasperYC\\Desktop\\mayan.mla", libname;

 

Use a semicolon rather than a colon when you do the assignment, then you may see what is wrong.  Backslashes in strings must be escaped (doubled).  Usually you can use forward slashes, but there are exceptions.  Here is what you want

libname := "C:\\Documents and Settings\\CasperYC\\Desktop\\mayan.mla", libname;

 

Here is a zip file containing a single Maple archive, mayan.mla, that includes the images, so you don't need to set imagedir.  However, after unzipping this file you will need to modify libname (in Maple) so that Maple can find it. That is, if you put the unzipped file at c:\MyPrograms\MyMaple\mayan.mla then, in a Maple session, you would do

libname := "c:\\MyPrograms\\MyMaple\\mayan.mla", libname:
mayan(123);

By the way, the name of the zip file is "84_Stupid.zip".  Sorry for the poor name, but the MaplePrimes upload tool does not distinguish extensions, apparently, and I was a bit frustrated.

Here is the updated code.  I changed the option name to 'image', when true it returns the image, the default (fault) causes the image to appear in a maplet.  The option stackheight sets the maximum height (number of glyphs) in a column. 

mayan := module()
export ModuleApply;
local glyph, blank;

    ModuleApply := proc(n :: nonnegint
                        , {image :: truefalse := false
                           , stackheight :: posint := 3
                          }
                        , $ )
    local img, imgs,m;
    description "convert a nonnegative integer to an image of the mayan representation";
    uses ImageTools,ListTools;

        if n = 0 then
            img := glyph[0];
        else
            imgs := [seq(glyph[m], m in convert(n,'base',20))];
            imgs := [LengthSplit(imgs, stackheight, 'pad' = blank)];
            imgs := map(Reverse,imgs);
            img := Stack(map(Stack,imgs,'vertical'),'horizontal','valign=bottom');
        end if;

        return `if`(image
                    , img
                    , View(img)
                   );
    end proc;

    use ImageTools in
        glyph := Array(0..19, m -> ToGrayscale(Read(sprintf("images/%d.jpg", m))));
        blank := Create((Height,Width)(glyph[0]), 'background=white');
    end use;

end module:

LibraryTools:-Save(mayan, "/home/joe/maple/lib/mayan.mla"):

Here is a zip file containing a single Maple archive, mayan.mla, that includes the images, so you don't need to set imagedir.  However, after unzipping this file you will need to modify libname (in Maple) so that Maple can find it. That is, if you put the unzipped file at c:\MyPrograms\MyMaple\mayan.mla then, in a Maple session, you would do

libname := "c:\\MyPrograms\\MyMaple\\mayan.mla", libname:
mayan(123);

By the way, the name of the zip file is "84_Stupid.zip".  Sorry for the poor name, but the MaplePrimes upload tool does not distinguish extensions, apparently, and I was a bit frustrated.

Here is the updated code.  I changed the option name to 'image', when true it returns the image, the default (fault) causes the image to appear in a maplet.  The option stackheight sets the maximum height (number of glyphs) in a column. 

mayan := module()
export ModuleApply;
local glyph, blank;

    ModuleApply := proc(n :: nonnegint
                        , {image :: truefalse := false
                           , stackheight :: posint := 3
                          }
                        , $ )
    local img, imgs,m;
    description "convert a nonnegative integer to an image of the mayan representation";
    uses ImageTools,ListTools;

        if n = 0 then
            img := glyph[0];
        else
            imgs := [seq(glyph[m], m in convert(n,'base',20))];
            imgs := [LengthSplit(imgs, stackheight, 'pad' = blank)];
            imgs := map(Reverse,imgs);
            img := Stack(map(Stack,imgs,'vertical'),'horizontal','valign=bottom');
        end if;

        return `if`(image
                    , img
                    , View(img)
                   );
    end proc;

    use ImageTools in
        glyph := Array(0..19, m -> ToGrayscale(Read(sprintf("images/%d.jpg", m))));
        blank := Create((Height,Width)(glyph[0]), 'background=white');
    end use;

end module:

LibraryTools:-Save(mayan, "/home/joe/maple/lib/mayan.mla"):

Here's a small procedure that, per Scott's suggestion, uses ImageTools to convert the jpeg images to an appropriate tableau.

mayan := module()
export ModuleApply;
local glyph, imagedir, maxheight, blank;

    maxheight := 3;
    imagedir := "images";

    ModuleApply := proc(n :: nonnegint, {view :: truefalse := false})
    local img, imgs;
    uses ImageTools,ListTools;

        if n = 0 then
            img := glyph(0);
        else
            imgs := map(glyph, convert(n,'base',20));
            imgs := [LengthSplit(imgs, maxheight, 'pad' = blank)];
            imgs := map(Reverse,imgs);
            img := ToGrayscale(Stack(map(Stack,imgs,'vertical'),'horizontal','valign=bottom'));
        end if;

        if view then
            View(img)
        else
            img;
        end if;

    end proc;

    glyph := proc(n :: nonnegint)
    option cache;
    uses ImageTools;
        ToGrayscale(Read(sprintf("%s/%d.jpg", imagedir,n)));
    end proc;

    use ImageTools in
        blank := Create((Height,Width)(glyph(0)), 'background=white');
    end use;

end module:

Here is what it does

allglyphs := convert([seq(0..19)],'base',20,20^20)[];       
                   allglyphs := 104567135734072022160664820
mayan(allglyphs, 'view');

Note: I edited code to handle 0, insert a blank glyph in the tableau, and provided a 'view' option. You will need to unpack the file of images (see previous posting) and modify the assignment of 'imagedir' accordingly.

 

Here's a small procedure that, per Scott's suggestion, uses ImageTools to convert the jpeg images to an appropriate tableau.

mayan := module()
export ModuleApply;
local glyph, imagedir, maxheight, blank;

    maxheight := 3;
    imagedir := "images";

    ModuleApply := proc(n :: nonnegint, {view :: truefalse := false})
    local img, imgs;
    uses ImageTools,ListTools;

        if n = 0 then
            img := glyph(0);
        else
            imgs := map(glyph, convert(n,'base',20));
            imgs := [LengthSplit(imgs, maxheight, 'pad' = blank)];
            imgs := map(Reverse,imgs);
            img := ToGrayscale(Stack(map(Stack,imgs,'vertical'),'horizontal','valign=bottom'));
        end if;

        if view then
            View(img)
        else
            img;
        end if;

    end proc;

    glyph := proc(n :: nonnegint)
    option cache;
    uses ImageTools;
        ToGrayscale(Read(sprintf("%s/%d.jpg", imagedir,n)));
    end proc;

    use ImageTools in
        blank := Create((Height,Width)(glyph(0)), 'background=white');
    end use;

end module:

Here is what it does

allglyphs := convert([seq(0..19)],'base',20,20^20)[];       
                   allglyphs := 104567135734072022160664820
mayan(allglyphs, 'view');

Note: I edited code to handle 0, insert a blank glyph in the tableau, and provided a 'view' option. You will need to unpack the file of images (see previous posting) and modify the assignment of 'imagedir' accordingly.

 

No, but the names are fairly expressive and if you make yourself familar with the available options (in Tools -> Options) you can guess most of them.

No, but the names are fairly expressive and if you make yourself familar with the available options (in Tools -> Options) you can guess most of them.

Go to the Recent Posts section (click on link in upper left hand panel of MapleSoft home).  Then select the "My Recent Posts" tab, which is just to the right of the one that opens.

First 151 152 153 154 155 156 157 Last Page 153 of 195