{"id":411,"date":"2009-09-18T14:21:32","date_gmt":"2009-09-18T21:21:32","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=2213"},"modified":"2009-09-18T14:21:32","modified_gmt":"2009-09-18T21:21:32","slug":"seamless-vector-texture","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=411","title":{"rendered":"Seamless Vector Texture"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\n&#x5B;SWF(width = 800, height = 450, backgroundColor=0xFFFFFF)]\r\n\r\ngraphics.beginFill(0xDEDEDE);\r\ngraphics.drawRect(0,0,400,400);\r\n\r\nvar container:Sprite = Sprite(addChild(new Sprite()));\r\ndraggable(rx(), ry(), 0x112233, 20);\r\ndraggable(rx(), ry(), 0x2266FF, 15);\r\ndraggable(rx(), ry(), 0x003299, 50, &quot;rect&quot;);\r\ndraggable(rx(), ry(), 0xFFFFFF, 30);\r\ndraggable(rx(), ry(), 0x00CCFF, 15);\r\ndraggable(rx(), ry(), 0x1188CC, 50, &quot;rect&quot;);\r\n\r\nfunction rx():Number{\r\n\treturn Math.random() * 200 + 100;\r\n}\r\nfunction ry():Number{\r\n\treturn Math.random() * 200 + 100;\r\n}\r\n\r\nvar guides:Shape = Shape(addChild(new Shape()));\r\nwith(guides.graphics){\r\n       lineStyle(0, 0x666666)\r\n       moveTo(200,0);\r\n       lineTo(200,400);\r\n       moveTo(0, 200);\r\n       lineTo(400, 200);\r\n       moveTo(400,0);\r\n\t   lineTo(400,400);\r\n\t   moveTo(0,400);\r\n\t   lineTo(800,400);\r\n}\r\n\r\nvar canvas:BitmapData = new BitmapData(200,200,true, 0x00000000);\r\nvar tex:BitmapData = new BitmapData(800,800,false, 0xFFFFFF);\r\n\r\nvar frame:Bitmap = Bitmap(addChild(new Bitmap(tex, &quot;auto&quot;, true)));\r\nframe.x = 401;\r\nframe.scaleX = frame.scaleY = 0.5;\r\n\r\nvar pnt:Point = new Point();\r\nvar m:Matrix = new Matrix();\r\n\r\naddEventListener(Event.ENTER_FRAME, onLoop);\r\nfunction onLoop(evt:Event):void {\r\n\tcanvas.fillRect(canvas.rect, 0x00000000);\r\n\tcanvas.draw(container);\r\n\tdrawQuadrant(-200,0)\r\n\tdrawQuadrant(-400,0)\r\n\tdrawQuadrant(0,-200)\r\n\tdrawQuadrant(-200,-200);\r\n\ttex.fillRect(tex.rect, 0xFFFFFF);\r\n\tfor (var i:int = 0; i&lt;16; i++){\r\n\t\tvar px:Number = i % 4;\r\n\t\tvar py:Number = int(i \/ 4);\r\n\t\tpnt.x = px * 200;\r\n\t\tpnt.y = py * 200;\r\n\t\ttex.copyPixels(canvas, canvas.rect, pnt, null, null, true);\r\n       }\r\n}\r\n\r\nfunction drawQuadrant(x:Number, y:Number):void{\r\n\t m.tx = x;\r\n\t m.ty = y;\r\n\t canvas.draw(container, m);\r\n}\r\n\r\n\/\/ draggable Sprite\r\nfunction draggable(xp:Number, yp:Number, col:uint = 0xFF0000,\r\nsize:Number=4, type:String=&quot;circle&quot;):Sprite {\r\n       var s:Sprite = Sprite(container.addChild(new Sprite()));\r\n       s.x = xp;\r\n       s.y = yp;\r\n       with(s.graphics){\r\n               beginFill(col)\r\n               if(type == &quot;circle&quot;){\r\n                 drawCircle(size,size,size);\r\n               }else if(type == &quot;rect&quot;){\r\n                 drawRect(0,0,size, size);\r\n               }\r\n       }\r\n       s.buttonMode = true;\r\n       s.addEventListener(MouseEvent.MOUSE_DOWN, onDrag);\r\n       return s;\r\n}\r\nfunction onDrag(evt:MouseEvent):void {\r\n\tvar w:Number = evt.currentTarget.width;\r\n\tvar h:Number = evt.currentTarget.height;\r\n\tevt.currentTarget.startDrag(false, new Rectangle(0,0,400 - w, 400 - h));\r\n}\r\nstage.addEventListener(MouseEvent.MOUSE_UP, onUp);\r\nfunction onUp(evt:MouseEvent):void{ stopDrag() }\r\n<\/pre>\n<p>This snippet creates a seamless texture from a few draggable vector shapes. BitmapData is used to combine four quadrants into one seamless tile.<\/p>\n<p><a data-asruffle-linked=\"true\" href=\"http:\/\/www.actionsnippet.com\/swfs\/seamless_vector_tiles.html\" target=\"blank\"><br \/>\nHave a look at the swf<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/actionsnippet.com\/wp-content\/seamless_vector.gif\" \/><\/a> <span class=\"asruffle-link\" data-swf=\"{&quot;url&quot;:&quot;https:\\\/\\\/actionsnippet.com\\\/swfs\\\/seamless_vector_tiles.swf&quot;,&quot;title&quot;:&quot;seamless vector tiles&quot;,&quot;width&quot;:800,&quot;height&quot;:450,&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\">: seamless vector tiles<\/span><\/button><\/span><\/p>\n<p>I created this snippet as a sketch for a new feature for my <a href=\"https:\/\/actionsnippet.com\/?p=1272\" target=\"blank\">command drawing<\/a> project.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#x5B;SWF(width = 800, height = 450, backgroundColor=0xFFFFFF)] graphics.beginFill(0xDEDEDE); graphics.drawRect(0,0,400,400); var container:Sprite = Sprite(addChild(new Sprite())); draggable(rx(), ry(), 0x112233, 20); draggable(rx(), ry(), 0x2266FF, 15); draggable(rx(), ry(), 0x003299, 50, &quot;rect&quot;); draggable(rx(), ry(), 0xFFFFFF, 30); draggable(rx(), ry(), 0x00CCFF, 15); draggable(rx(), ry(), 0x1188CC, 50, &quot;rect&quot;); function rx():Number{ return Math.random() * 200 + 100; } function ry():Number{ return Math.random() * 200 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24,33,94],"tags":[3,14,4],"class_list":["post-411","post","type-post","status-publish","format-standard","hentry","category-bitmapdata","category-graphics","category-misc","tag-actionscript","tag-as3","tag-flash"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/411","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=411"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/411\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=411"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=411"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=411"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}