{"id":4460,"date":"2013-03-29T09:00:56","date_gmt":"2013-03-29T13:00:56","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=4460"},"modified":"2013-03-22T20:14:52","modified_gmt":"2013-03-23T00:14:52","slug":"generate-a-smile-maybe","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2013\/03\/29\/generate-a-smile-maybe\/","title":{"rendered":"Generate a Smile&#8230;Maybe"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <introduction><\/introduction>\r\n   <p><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/911\">Brett<\/a>'s Pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/40371-randomfacegenerator\">\"Random Face Generator\"<\/a>, by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/269973\">Joseph Hollmann<\/a>.\r\n   <\/p>\r\n   <p>I wrote today's post in advance. I fully expect that, when this goes live on Friday morning, I will be sitting on a tropical\r\n      beach in the Dominican Republic, sipping umbrella drinks and contemplating the crystal clear cerulean water.\r\n   <\/p>\r\n   <p>So, in the spirit of Spring Break and focusing on family fun, a bit of frivolity for today's Pick.<\/p>\r\n   <p>Joseph's submission doesn't really do anything of a practical nature, but it <i>does<\/i> make you smile. As he says in the preamble to his code, <tt>randomfacegenerator<\/tt> \"generates a randomly created face and plots it....nothing else.\"\r\n   <\/p>\r\n   <p>I have one suggestion for improvement. Calling the <tt>figure<\/tt> command in the function is probably unnecessary; you can easily end up with many open figures before you know it. I would\r\n      suggest replacing the lines:\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">figure;\r\nset(gcf,<span style=\"color: #A020F0\">'name'<\/span>,<span style=\"color: #A020F0\">'Your New Face'<\/span>);<\/pre><p>with a call to <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/18220-create-and-activate-figures-by-name\"><tt>togglefig<\/tt><\/a>:\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">togglefig(<span style=\"color: #A020F0\">'Your New Face'<\/span>)<\/pre><p>(That is, if a figure named \"Your New Face\" exists, activate and reuse it. Otherwise, create it.) No inputs required:<\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\"><span style=\"color: #0000FF\">while<\/span> ~strcmp(get(gcf,<span style=\"color: #A020F0\">'currentcharacter'<\/span>),<span style=\"color: #A020F0\">'s'<\/span>)\r\nrandomfacegenerator\r\npause(0.5);\r\n<span style=\"color: #0000FF\">end<\/span><\/pre><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/RandomFaces.gif\"> <\/p>\r\n   <p>Thanks for putting me in vacation mode a day early, Joseph!<\/p>\r\n   <p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/smile.png\"> <\/p>\r\n   <p>As always, I welcome your <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=4460#respond\">thoughts and comments<\/a>. Or leave feedback for Joseph <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/40371-randomfacegenerator#comments\">here<\/a>.\r\n   <\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_f1a450ebddb1442dbafa70f139c72019() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='f1a450ebddb1442dbafa70f139c72019 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' f1a450ebddb1442dbafa70f139c72019';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        author = 'Brett Shoelson';\r\n        copyright = 'Copyright 2013 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n      \r\n      d.title = title + ' (MATLAB code)';\r\n      d.close();\r\n      }   \r\n      \r\n-->\r\n<\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_f1a450ebddb1442dbafa70f139c72019()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n            the MATLAB code \r\n            <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2013a<br><\/p>\r\n<\/div>\r\n<!--\r\nf1a450ebddb1442dbafa70f139c72019 ##### SOURCE BEGIN #####\r\n%% Generate a Smile...Maybe\r\n%% \r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/911 Brett>'s Pick this week is\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/40371-randomfacegenerator \"Random Face Generator\">, by\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/269973 Joseph Hollmann>.\r\n\r\n%%\r\n% I wrote today's post in advance. I fully expect that, when this goes live\r\n% on Friday morning, I will be sitting on a tropical beach in the Dominican\r\n% Republic, sipping umbrella drinks and contemplating the crystal clear\r\n% cerulean water.\r\n\r\n%%\r\n% So, in the spirit of Spring Break and focusing on family fun, a bit of\r\n% frivolity for today's Pick.\r\n\r\n%%\r\n% Joseph's submission doesn't really do anything of a practical nature, but it\r\n% _does_ make you smile. As he says in the preamble to his code,\r\n% |randomfacegenerator| \"generates a randomly created face and plots\r\n% it....nothing else.\"\r\n\r\n%% \r\n% I have one suggestion for improvement. Calling the |figure| command in\r\n% the function is probably unnecessary; you can easily end up with many\r\n% open figures before you know it. I would suggest replacing the lines:\r\n\r\n%%\r\n% \r\n%   figure; \r\n%   set(gcf,'name','Your New Face');\r\n\r\n%%\r\n% with a call to <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/18220-create-and-activate-figures-by-name |togglefig|>:\r\n%%\r\n%\r\n%   togglefig('Your New Face')\r\n\r\n%%\r\n% (That is, if a figure named \"Your New Face\" exists, activate and reuse\r\n% it. Otherwise, create it.) No inputs required:\r\n\r\n%%\r\n%   while ~strcmp(get(gcf,'currentcharacter'),'s')\r\n%   randomfacegenerator\r\n%   pause(0.5);\r\n%   end\r\n\r\n%%\r\n% \r\n% <<https:\/\/blogs.mathworks.com\/pick\/files\/RandomFaces.gif>>\r\n% \r\n\r\n%%\r\n% Thanks for putting me in vacation mode a day early, Joseph!\r\n\r\n%%\r\n% \r\n% <<https:\/\/blogs.mathworks.com\/pick\/files\/smile.png>>\r\n% \r\n\r\n\r\n%% \r\n% As always, I welcome your\r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=4460#respond thoughts and comments>.\r\n% Or leave feedback for Joseph <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/40371-randomfacegenerator#comments here>.\r\n##### SOURCE END ##### f1a450ebddb1442dbafa70f139c72019\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/RandomFaces.gif\" onError=\"this.style.display ='none';\" \/><\/div><p>\r\n   \r\n   Brett's Pick this week is \"Random Face Generator\", by Joseph Hollmann.\r\n   \r\n   I wrote today's post in advance. I fully expect that, when this goes live on Friday morning, I will be... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2013\/03\/29\/generate-a-smile-maybe\/\">read more >><\/a><\/p>","protected":false},"author":34,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/4460"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/34"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=4460"}],"version-history":[{"count":15,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/4460\/revisions"}],"predecessor-version":[{"id":4478,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/4460\/revisions\/4478"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=4460"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=4460"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=4460"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}