{"id":272,"date":"2009-05-02T07:49:29","date_gmt":"2009-05-02T14:49:29","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=1272"},"modified":"2009-05-02T07:49:29","modified_gmt":"2009-05-02T14:49:29","slug":"command-draw-source","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=272","title":{"rendered":"Command Draw Source"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\n&#x5B;SWF(width = 600, height = 500, frameRate=30, background = 0xFFFFFF)]\r\n\r\nvar cmd:String = &quot;1000 small orange circles, 9000 black lines,3 large white circles&quot;\r\n\/\/ try some of these commands:\r\n\/\/&quot;300 small red triangles and 2 big orange circle 3 big black lines&quot;;\r\n\/\/&quot;100 big black triangles, ten small white rectangles 1 big white circle and 1 big gray poly&quot;;\r\n\/\/ &quot;300 small red triangles and 2 big orange circle 3 big black lines&quot;;\r\n\/\/&quot;10 big black circles 1000 big white lines 100 small white rects 1 big red circle and 1 green poly&quot;\r\nstage.align = &quot;TL&quot;\r\nvar msk:Shape = new Shape();\r\nwith(msk.graphics) beginFill(0x00FF00), drawRect(0,0,600, 400);\r\nthis.mask = msk;\r\nvar amount:Number;\r\nvar color:uint = 0;\r\nvar shape:String;\r\n\r\nvar hexLookup:Object = {red:0xFF0000, green:0x00FF00, blue:0x0000FF, yellow:0xFFFF00, orange:0xFFCC00, white:0xFFFFFF, gray:0xCCCCCC, grey:0xCCCCCC, black:0x000001};\r\nvar sizeLookup:Object = {large:true, big:true, small:true, tiny:true};\r\nvar defaultSize:Number = 50;\r\nvar size:Number = defaultSize;\r\nvar halfSize:Number = size \/ 2;\r\nvar circles:Function = circle;\r\nvar ovals:Function = oval, ellipse:Function = oval;\r\nvar rects:Function = rect, rectangle:Function = rect, rectangles:Function = rect;\r\nvar lines:Function = line;\r\nvar triangles:Function = triangle;\r\nvar polygon:Function = poly, polygons:Function = poly;\r\nvar large:Function = big;\r\nvar tiny:Function = small;\r\n\r\nparse();\r\nfunction parse():void {\r\n\tamount = 1;\r\n\tcolor = 0x000000;\r\n\tshape = &quot;circle&quot;;\r\n\tvar words:Array = cmd.split(\/&#x5B;W]+\/g)\r\n\tfor (var i:int = 0; i&lt;words.length; i++){\r\n\t\tvar w:* = words&#x5B;i];\r\n\t\tif (isNaN(Number(w))){\r\n\t\t\tif (hexLookup&#x5B;w]){\r\n\t\t\t\tcolor = hexLookup&#x5B;w];\r\n\t\t\t\ttrace(w, &quot;color&quot;);\r\n\t\t\t}else\r\n\t\t\tif (sizeLookup&#x5B;w]){\r\n\t\t\t\tthis&#x5B;w]();\r\n\t\t\t}else\r\n\t\t\tif (this&#x5B;w]){\r\n\t\t\t\tfor (var j:int = 0; j&lt;amount; j++){\r\n\t\t\t\t   this&#x5B;w]();\r\n\t\t\t\t}\r\n\t\t\t\tcolor = 0x000000;\r\n\t\t\t\tsize = defaultSize;\r\n\t\t\t\ttrace(w, &quot;command&quot;);\r\n\t\t\t}\r\n\t\t}else{\r\n\t\t\ttrace(w, &quot;number&quot;);\r\n\t\t\tamount = w;\r\n\t\t}\r\n\t}\r\n}\r\nfunction makeShape(p:Array):void{\r\n\t\tvar s:Shape = Shape(addChild(new Shape()));\r\n\t\t for (var i:int = 0; i&lt;p.length; i++) {\r\n\t\t    s.graphics&#x5B;p&#x5B;i]&#x5B;0]].apply(graphics,p&#x5B;i].splice(1));\r\n\t     }\r\n\t\ts.rotation = Math.random() * 360;\r\n\t\ts.x = Math.random() * stage.stageWidth;\r\n\t\ts.y = Math.random() * stage.stageHeight;\r\n}\r\n\r\nfunction circle():void{\r\n\t  makeShape(&#x5B;&#x5B;&quot;beginFill&quot;,color], &#x5B;&quot;drawCircle&quot;,0,0,Math.random() * halfSize + halfSize]]);\r\n}\r\nfunction oval():void{\r\n\t  makeShape(&#x5B;&#x5B;&quot;beginFill&quot;,color],&#x5B;&quot;drawEllipse&quot;, 0,0,Math.random() * size + halfSize]]);  \r\n}\r\nfunction square():void{\r\n\t\tvar s:Number = Math.random() * halfSize + halfSize;\r\n\t\tvar p:Number = -s\/2;\r\n\t\tmakeShape(&#x5B;&#x5B;&quot;beginFill&quot;,color],&#x5B;&quot;drawRect&quot;, p, p, s, s]]);  \r\n}\r\nfunction rect():void{\r\n\t\tvar w:Number = Math.random() * halfSize + halfSize;\r\n\t\tvar h:Number = Math.random() * halfSize + halfSize;\r\n\t\tmakeShape(&#x5B;&#x5B;&quot;beginFill&quot;,color],&#x5B;&quot;drawRect&quot;, -w\/2, -h\/2, w, h]]);\r\n}\r\nfunction line():void{\r\n\tvar s:Number = size * 2;\r\n\tmakeShape(&#x5B;&#x5B;&quot;lineStyle&quot;,Math.random()*3, color],&#x5B;&quot;lineTo&quot;, Math.random()*s - size, Math.random()*s - size]])\r\n}\r\nfunction triangle():void {\r\n\t var s:Number = size * 2;\r\n\t makeShape(&#x5B;&#x5B;&quot;beginFill&quot;,color],&#x5B;&quot;lineTo&quot;, Math.random()*s - size, Math.random()*s - size], &#x5B;&quot;lineTo&quot;, Math.random()*s - size, Math.random()*s - size]]);\r\n}\r\nfunction poly():void {\r\n\t var s:Number = size * 2;\r\n\t var cmds:Array = &#x5B;&#x5B;&quot;beginFill&quot;,color]]\r\n\t var num:Number = int(Math.random()*8) + 2;\r\n\t for (var i:int = 0; i&lt;num; i++){\r\n\t\t  cmds.push(&#x5B;&quot;lineTo&quot;, Math.random()*s - size, Math.random()*s - size]);\r\n\t }\r\n\t makeShape(cmds);\r\n}\r\nfunction big():void{\r\n\tsize = 100 + Math.random() * 40;\r\n\thalfSize = size \/ 2;\r\n}\r\nfunction small():void {\r\n\tsize = 3 + Math.random() * 20;\r\n\thalfSize = size \/ 2;\r\n}\r\n<\/pre>\n<p>I&#8217;ve been meaning to post this source for a long time. It&#8217;s a project I created for <a href=\"http:\/\/www.shapevent.com\" target=\"blank\">shapevent<\/a> called Command Draw. It allows you to use simple sentence structure to create textures and patterns. <\/p>\n<p>See it in action <a href=\"http:\/\/shapevent.com\/projects\/command_drawing\/\" target=\"blank\">here<\/a> (this one has some minimal UI and uses flashvars for the command string).<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/actionsnippet.com\/imgs\/cmd_5.jpeg\" \/><br \/>\n<img decoding=\"async\" src=\"https:\/\/actionsnippet.com\/imgs\/cmd_four.jpeg\" \/><\/p>\n<p><i>As a side note, this is the 200th post on ActionSnippet.com<\/i><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#x5B;SWF(width = 600, height = 500, frameRate=30, background = 0xFFFFFF)] var cmd:String = &quot;1000 small orange circles, 9000 black lines,3 large white circles&quot; \/\/ try some of these commands: \/\/&quot;300 small red triangles and 2 big orange circle 3 big black lines&quot;; \/\/&quot;100 big black triangles, ten small white rectangles 1 big white circle and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,33,21],"tags":[3,4],"class_list":["post-272","post","type-post","status-publish","format-standard","hentry","category-dynamic","category-graphics","category-strings","tag-actionscript","tag-flash"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/272","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=272"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/272\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=272"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=272"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=272"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}