{"id":338,"date":"2009-07-07T09:44:57","date_gmt":"2009-07-07T16:44:57","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=1715"},"modified":"2009-07-07T09:44:57","modified_gmt":"2009-07-07T16:44:57","slug":"variable-line-resolution","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=338","title":{"rendered":"Variable Line Resolution"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nvar loc:Vector.&lt;Point&gt; = new Vector.&lt;Point&gt;();\r\nvar lifts:Vector.&lt;int&gt; = new Vector.&lt;int&gt;();\r\nvar index:int = 0;\r\nvar resolution:int = 1;\r\nvar down:Boolean;\r\nstage.addEventListener(MouseEvent.MOUSE_DOWN, onDown);\r\nstage.addEventListener(MouseEvent.MOUSE_UP, onUp);\r\nstage.addEventListener(KeyboardEvent.KEY_UP, onKeyReleased);\r\naddEventListener(Event.ENTER_FRAME, onLoop);\r\nfunction onKeyReleased(evt:KeyboardEvent):void{\r\n\tif (evt.keyCode == Keyboard.RIGHT){\r\n\t\tresolution -= 1;\r\n\t\tif (resolution &lt; 1) resolution = 1;\r\n\t}else \r\n\tif (evt.keyCode == Keyboard.LEFT){\r\n\t\tresolution += 1;\r\n\t}\r\n}\r\nfunction onDown(evt:MouseEvent):void{\r\n\tdown = true;\r\n\tlifts.push(index);\r\n}\r\nfunction onUp(evt:MouseEvent):void{\r\n\tdown = false;\r\n}\r\nfunction onLoop(evt:Event):void {\r\n\tif (down){\r\n\t\tloc&#x5B;index] = new Point(mouseX, mouseY);\r\n\t\tindex++;\r\n\t}\r\n\tgraphics.clear();\r\n\tgraphics.lineStyle(0,0x000000);\r\n\tvar liftIndex:int = 0;\r\n\tfor (var i:int = 0; i&lt;loc.length; i++){\r\n\t\tif (liftIndex == lifts.length) liftIndex = 0;\r\n\t\tif (i == lifts&#x5B;liftIndex]){\r\n\t\t\tgraphics.moveTo(loc&#x5B;i].x, loc&#x5B;i].y);\r\n\t\t    liftIndex++;\r\n\t\t}else{\r\n\t\t\tif (i % resolution == 1 || resolution == 1){\r\n\t\t\t\tgraphics.lineTo(loc&#x5B;i].x, loc&#x5B;i].y);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n<\/pre>\n<p>This snippet shows a simple approach to creating variable resolution graphics. <\/p>\n<p>Below is a drawing done using this snippet. The left arrow key is used to decrease resolution and the right arrow key is used to increase resolution:<\/p>\n<p><a data-asruffle-linked=\"true\" href=\"https:\/\/actionsnippet.com\/swfs\/resoline.html\" target=\"blank\"><br \/>\nClick to view swf&#8230;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/actionsnippet.com\/wp-content\/line_res.gif\" \/><\/a> <span class=\"asruffle-link\" data-swf=\"{&quot;url&quot;:&quot;https:\\\/\\\/actionsnippet.com\\\/swfs\\\/resoline.swf&quot;,&quot;title&quot;:&quot;resoline&quot;,&quot;width&quot;:800,&quot;height&quot;:600,&quot;missing&quot;:false,&quot;allowScriptAccess&quot;:false,&quot;backgroundColor&quot;:&quot;#ffffff&quot;}\"><button type=\"button\" hidden aria-expanded=\"false\">Play demo<span class=\"screen-reader-text\">: resoline<\/span><\/button><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>var loc:Vector.&lt;Point&gt; = new Vector.&lt;Point&gt;(); var lifts:Vector.&lt;int&gt; = new Vector.&lt;int&gt;(); var index:int = 0; var resolution:int = 1; var down:Boolean; stage.addEventListener(MouseEvent.MOUSE_DOWN, onDown); stage.addEventListener(MouseEvent.MOUSE_UP, onUp); stage.addEventListener(KeyboardEvent.KEY_UP, onKeyReleased); addEventListener(Event.ENTER_FRAME, onLoop); function onKeyReleased(evt:KeyboardEvent):void{ if (evt.keyCode == Keyboard.RIGHT){ resolution -= 1; if (resolution &lt; 1) resolution = 1; }else if (evt.keyCode == Keyboard.LEFT){ resolution += 1; } } function [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33,79],"tags":[3,14,4],"class_list":["post-338","post","type-post","status-publish","format-standard","hentry","category-graphics","category-vector","tag-actionscript","tag-as3","tag-flash"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/338","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=338"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/338\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=338"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=338"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=338"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}