{"id":9953,"date":"2018-08-10T09:00:32","date_gmt":"2018-08-10T13:00:32","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=9953"},"modified":"2018-08-06T08:54:26","modified_gmt":"2018-08-06T12:54:26","slug":"string-art","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2018\/08\/10\/string-art\/","title":{"rendered":"String Art II"},"content":{"rendered":"<div class=\"content\">\n<p><a href=\"http:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/3208495\">Sean<\/a>&#8216;s pick this week is also\u00a0<a href=\"http:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/68252\">stringart<\/a> by <a href=\"http:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/870394\">Giuseppe Cardillo<\/a>.\u00a0 Jiro picked this <a href=\"https:\/\/blogs.mathworks.com\/pick\/2018\/08\/03\/string-art-2\/\">last week;<\/a>\u00a0I&#8217;d already written this post; this may be our first blog race condition in history.<\/p>\n<h3>Contents<\/h3>\n<div>\n<ul>\n<li><a href=\"#1\">String Art<\/a><\/li>\n<li><a href=\"#4\">Live Controls<\/a><\/li>\n<li><a href=\"#5\">Function Signatures<\/a><\/li>\n<li><a href=\"#6\">Writing Function Signatures<\/a><\/li>\n<li><a href=\"#7\">Comments<\/a><\/li>\n<\/ul>\n<\/div>\n<h3>String Art<a name=\"1\"><\/a><\/h3>\n<p>This is a fun program for creating string or thread art. Giuseppe gives more information on the theory and history in the<br \/>\nFEX post. Let&#8217;s see the default. Note if you run it, you&#8217;ll see the lines animating.<\/p>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid #c8c8c8;\">stringart<\/pre>\n<p><img decoding=\"async\" src=\"http:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainStringArt\/defaults.gif\" hspace=\"5\" vspace=\"5\" \/><\/p>\n<p>We can also adjust the number of sides, density, crossings and color.<\/p>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid #c8c8c8;\">stringart(<span style=\"color: #a020f0;\">'Sides'<\/span>, 5, <span style=\"color: #a020f0;\">'Density'<\/span>, 20, <span style=\"color: #a020f0;\">'Crossed'<\/span>, 1, <span style=\"color: #a020f0;\">'Color'<\/span>, rand(1, 3))<\/pre>\n<p><img decoding=\"async\" src=\"http:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainStringArt\/sides5.gif\" hspace=\"5\" vspace=\"5\" \/><\/p>\n<h3>Live Controls<a name=\"4\"><\/a><\/h3>\n<p>Now, if you&#8217;re thinking that&#8217;s a lot of knobs to turn. This could be a good place for <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/matlab_prog\/add-interactive-controls-to-a-live-script.html\">Live Controls<\/a> in a <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/matlab_prog\/what-is-a-live-script-or-function.html\">Live Script<\/a>. That way we can interactively adjust those parameters.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainStringArt\/SlidersMoving.gif\" hspace=\"5\" vspace=\"5\" \/><\/p>\n<p>The live script can be downloaded from <a href=\"http:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainStringArt\/StringArtSliders.mlx\">here<\/a> so you can play with it. R2018a or newer is required.<\/p>\n<h3>Function Signatures<a name=\"5\"><\/a><\/h3>\n<p>Okay, that was fun. But what if you didn&#8217;t know which options string art has? Giuseppe has given us four name-value pairs<br \/>\nto tune the behavior of the <tt>stringart<\/tt>. Starting in R2018a, we can write <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/matlab_prog\/customize-code-suggestions-and-completions.html\">code suggestions<\/a> that will allow the live editor or tab-complete to provide information on these name-value pairs.<\/p>\n<p>I added it for string art so now you can see what happens as I type.<\/p>\n<p>In the live editor:<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainStringArt\/SignaturesInAction.gif\" hspace=\"5\" vspace=\"5\" \/><\/p>\n<p>Tab-complete at the command line or in a plain code file.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainStringArt\/tabkey.png\" hspace=\"5\" vspace=\"5\" \/><\/p>\n<h3>Writing Function Signatures<a name=\"6\"><\/a><\/h3>\n<p>In order to create function signatures, you need to define a <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/matlab_prog\/customize-code-suggestions-and-completions.html\"><i>functionSignatures.json<\/i><\/a> file and write the input schema. Here it is for <tt>stringart<\/tt>. I defined the type based on the attribute validation for each name-value pair.<\/p>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid #c8c8c8;\">{\r\n<span style=\"color: #a020f0;\">\"_schemaVersion\"<\/span>: <span style=\"color: #a020f0;\">\"1.0.0\"<\/span>,\r\n<span style=\"color: #a020f0;\">\"stringart\"<\/span>:\r\n{\r\n   <span style=\"color: #a020f0;\">\"inputs\"<\/span>:\r\n   [\r\n      {<span style=\"color: #a020f0;\">\"name\"<\/span>:<span style=\"color: #a020f0;\">\"Sides\"<\/span>, <span style=\"color: #a020f0;\">\"kind\"<\/span>:<span style=\"color: #a020f0;\">\"namevalue\"<\/span>, <span style=\"color: #a020f0;\">\"type\"<\/span>:[ <span style=\"color: #a020f0;\">\"numeric\"<\/span>, <span style=\"color: #a020f0;\">\"scalar\"<\/span>, <span style=\"color: #a020f0;\">\"real\"<\/span>, <span style=\"color: #a020f0;\">\"integer\"<\/span>,<span style=\"color: #a020f0;\">\"&gt;=3\"<\/span>],<span style=\"color: #a020f0;\">\"purpose\"<\/span>:<span style=\"color: #a020f0;\">\"Number of polygon sides\"<\/span>},\r\n      {<span style=\"color: #a020f0;\">\"name\"<\/span>:<span style=\"color: #a020f0;\">\"Crossed\"<\/span>, <span style=\"color: #a020f0;\">\"kind\"<\/span>:<span style=\"color: #a020f0;\">\"namevalue\"<\/span>, <span style=\"color: #a020f0;\">\"type\"<\/span>:[ <span style=\"color: #a020f0;\">\"numeric\"<\/span>, <span style=\"color: #a020f0;\">\"scalar\"<\/span>, <span style=\"color: #a020f0;\">\"real\"<\/span>, <span style=\"color: #a020f0;\">\"integer\"<\/span>,<span style=\"color: #a020f0;\">\"&lt;=1\"<\/span>],<span style=\"color: #a020f0;\">\"purpose\"<\/span>:<span style=\"color: #a020f0;\">\"Crossed or not\"<\/span>},\r\n      {<span style=\"color: #a020f0;\">\"name\"<\/span>:<span style=\"color: #a020f0;\">\"Density\"<\/span>, <span style=\"color: #a020f0;\">\"kind\"<\/span>:<span style=\"color: #a020f0;\">\"namevalue\"<\/span>, <span style=\"color: #a020f0;\">\"type\"<\/span>:[ <span style=\"color: #a020f0;\">\"numeric\"<\/span>, <span style=\"color: #a020f0;\">\"scalar\"<\/span>, <span style=\"color: #a020f0;\">\"real\"<\/span>, <span style=\"color: #a020f0;\">\"integer\"<\/span>,<span style=\"color: #a020f0;\">\"&gt;=10\"<\/span>],<span style=\"color: #a020f0;\">\"purpose\"<\/span>:<span style=\"color: #a020f0;\">\"Number of pins per side\"<\/span>},\r\n      {<span style=\"color: #a020f0;\">\"name\"<\/span>:<span style=\"color: #a020f0;\">\"Color\"<\/span>, <span style=\"color: #a020f0;\">\"kind\"<\/span>:<span style=\"color: #a020f0;\">\"namevalue\"<\/span>, <span style=\"color: #a020f0;\">\"type\"<\/span>:[ <span style=\"color: #a020f0;\">\"numeric\"<\/span>,<span style=\"color: #a020f0;\">\"row\"<\/span>,<span style=\"color: #a020f0;\">\"real\"<\/span>,<span style=\"color: #a020f0;\">\"ncols=3\"<\/span>,<span style=\"color: #a020f0;\">\"&gt;=0\"<\/span>,<span style=\"color: #a020f0;\">\"&lt;=1\"<\/span>],<span style=\"color: #a020f0;\">\"purpose\"<\/span>:<span style=\"color: #a020f0;\">\"Color - RGB Triplet\"<\/span>}\r\n   ]\r\n}\r\n}<\/pre>\n<p><b>Note<\/b>: I typically edit these in a third party editor which correctly highlights the JSON; in this case Visual Studio.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainStringArt\/vsfsjson.png\" hspace=\"5\" vspace=\"5\" \/><\/p>\n<h3>Comments<a name=\"7\"><\/a><\/h3>\n<p>Do you have a use for live controls, function signatures, or a new hobby of making string art where simulating or prototyping<br \/>\nit with software would be faster than laying down pins?<\/p>\n<p>Give it a try and let us know what you think <a href=\"http:\/\/blogs.mathworks.com\/pick\/?p=9953#respond\">here<\/a> or leave a <a href=\"http:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/68252#comments\">comment<\/a> for Giuseppe.<\/p>\n<p><script language=\"JavaScript\">\n<!--\n\n    function grabCode_58852a3e3b7d400bab75beb81da076c9() {\n        \/\/ Remember the title so we can use it in the new page\n        title = document.title;\n\n        \/\/ Break up these strings so that their presence\n        \/\/ in the Javascript doesn't mess up the search for\n        \/\/ the MATLAB code.\n        t1='58852a3e3b7d400bab75beb81da076c9 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 58852a3e3b7d400bab75beb81da076c9';\n    \n        b=document.getElementsByTagName('body')[0];\n        i1=b.innerHTML.indexOf(t1)+t1.length;\n        i2=b.innerHTML.indexOf(t2);\n \n        code_string = b.innerHTML.substring(i1, i2);\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\n\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \n        \/\/ in the XML parser.\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\n        \/\/ doesn't go ahead and substitute the less-than character. \n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\n\n        author = 'Sean de Wolski';\n        copyright = 'Copyright 2018 The MathWorks, Inc.';\n\n        w = window.open();\n        d = w.document;\n        d.write('<\/p>\n\n\n\n\n<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\n\n\n\n<p>\\n');\n      \n      d.title = title + ' (MATLAB code)';\n      d.close();\n      }   \n      \n-->\n<\/script><\/p>\n<p style=\"text-align: right; font-size: xx-small; font-weight: lighter; font-style: italic; color: gray;\">\n<a><span style=\"font-size: x-small; font-style: italic;\">Get<br \/>\nthe MATLAB code<br \/>\n<noscript>(requires JavaScript)<\/noscript><\/span><\/a><\/p>\n<p>Published with MATLAB\u00ae R2018a<\/p>\n<\/div>\n<p><!--\n58852a3e3b7d400bab75beb81da076c9 ##### SOURCE BEGIN #####\n%% String Art\n%\n% <http:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/3208495 Sean>'s pick this week is\n% <http:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/68252 stringart> by\n% <http:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/870394 Giuseppe Cardillo>.\n%\n\n%% String Art\n%\n% This is a fun program for creating string or thread art.  Giuseppe gives\n% more information on the theory and history in the FEX post.  Let's see\n% the default.  Note if you run it, you'll see the lines animating.\n\nstringart\n\n%%\n%\n% <<defaults.gif>>\n%\n% We can also adjust the number of sides, density, crossings and color.\n\nstringart('Sides', 5, 'Density', 20, 'Crossed', 1, 'Color', rand(1, 3))\n\n%%\n%\n% <<sides5.gif>>\n\n%% Live Controls\n%\n% Now, if you're thinking that's a lot of knobs to turn.  This could be a\n% good place for\n% <https:\/\/www.mathworks.com\/help\/matlab\/matlab_prog\/add-interactive-controls-to-a-live-script.html % Live Controls> in a\n% <https:\/\/www.mathworks.com\/help\/matlab\/matlab_prog\/what-is-a-live-script-or-function.html % Live Script>.  That way we can interactively adjust those parameters.\n%\n% <<SlidersMoving.gif>>\n%\n% The live script can be downloaded from <FIXME here> so you can play with\n% it.  R2018a or newer is required.\n%\n\n%% Function Signatures\n%\n% Okay, that was fun.  But what if you didn't know which options string art\n% has?  Giuseppe has given us four name-value pairs to tune the behavior of\n% the |stringart|.  Starting in R2018a, we can write\n% <https:\/\/www.mathworks.com\/help\/matlab\/matlab_prog\/customize-code-suggestions-and-completions.html % code suggestions> that will allow the live editor or tab-complete to\n% provide information on these name-value pairs.\n%\n% I added it for string art so now you can see what happens as I type.\n%\n% In the live editor:\n%\n% <<SignaturesInAction.gif>>\n%\n% Tab-complete at the command line or in a plain code file.\n%\n% <<tabkey.png>>\n\n%% Writing Function Signatures\n%\n% In order to create function signatures, you need to define a\n% <https:\/\/www.mathworks.com\/help\/matlab\/matlab_prog\/customize-code-suggestions-and-completions.html % _functionSignatures.json_> file and write the input schema.  Here it is\n% for |stringart|.  I defined the type based on the attribute validation\n% for each name-value pair.\n%\n%   {\n%   \"_schemaVersion\": \"1.0.0\",\n%   \"stringart\":\n%   {\n%      \"inputs\":\n%      [\n%         {\"name\":\"Sides\", \"kind\":\"namevalue\", \"type\":[ \"numeric\", \"scalar\", \"real\", \"integer\",\">=3\"],\"purpose\":\"Number of polygon sides\"},\n%         {\"name\":\"Crossed\", \"kind\":\"namevalue\", \"type\":[ \"numeric\", \"scalar\", \"real\", \"integer\",\"<=1\"],\"purpose\":\"Crossed or not\"}, % {\"name\":\"Density\", \"kind\":\"namevalue\", \"type\":[ \"numeric\", \"scalar\", \"real\", \"integer\",\">=10\"],\"purpose\":\"Number of pins per side\"},\n%         {\"name\":\"Color\", \"kind\":\"namevalue\", \"type\":[ \"numeric\",\"row\",\"real\",\"ncols=3\",\">=0\",\"<=1\"],\"purpose\":\"Color - RGB Triplet\"}\n%      ]\n%   }\n%   }\n%\n% *Note*: I typically edit these in a third party editor which correctly\n% highlights the JSON; in this case Visual Studio.\n%\n% <<vsfsjson.png>>\n\n%% Comments\n%\n% Do you have a use for live controls, function signatures, or a new hobby\n% of making string art where simulating or prototyping it with software\n% would be faster than laying down pins?\n%\n% Give it a try and let us know what you think\n% <http:\/\/blogs.mathworks.com\/pick\/?p=9953#respond here> or leave a\n% <http:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/68252#comments % comment> for Giuseppe.\n%\n\n##### SOURCE END ##### 58852a3e3b7d400bab75beb81da076c9\n--><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/pick\/files\/livecontrols.png\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div>\n<p>\nSean&#8216;s pick this week is also\u00a0stringart by Giuseppe Cardillo.\u00a0 Jiro picked this last week;\u00a0I&#8217;d already written this post; this may be our first blog race condition in&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2018\/08\/10\/string-art\/\">read more >><\/a><\/p>\n","protected":false},"author":87,"featured_media":9973,"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\/9953"}],"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\/87"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=9953"}],"version-history":[{"count":4,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/9953\/revisions"}],"predecessor-version":[{"id":9989,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/9953\/revisions\/9989"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media\/9973"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=9953"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=9953"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=9953"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}