{"id":348,"date":"2009-07-17T05:04:10","date_gmt":"2009-07-17T12:04:10","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=1778"},"modified":"2009-07-17T05:04:10","modified_gmt":"2009-07-17T12:04:10","slug":"another-matrixtransformpoint","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=348","title":{"rendered":"Another Matrix.transformPoint()"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\n&#x5B;SWF(width = 628, height=500)]\r\nvar trans:Matrix = new Matrix();\r\nvar pnt:Point = new Point();\r\nx = stage.stageWidth \/ 2;\r\ny = stage.stageHeight \/ 2;\r\naddEventListener(Event.ENTER_FRAME, onLoop);\r\nfunction onLoop(evt:Event):void {\r\n\tgraphics.clear();\r\n\tgraphics.lineStyle(10, 0x000000, 1, false, LineScaleMode.NORMAL, CapsStyle.SQUARE);\r\n\tpnt.x = 0;\r\n\tpnt.y = 0;\r\n\ttrans.identity();\r\n\ttrans.translate(15,15);\r\n\ttrans.rotate(mouseX\/10 * Math.PI \/ 180);\r\n\tgraphics.moveTo(pnt.x, pnt.y);\r\n\tfor (var i:int = 0; i&lt;12; i++){\r\n\t\tpnt = trans.transformPoint(pnt);\r\n\t\tgraphics.lineTo(pnt.x, pnt.y);\r\n\t}\r\n}\r\n<\/pre>\n<p>I was thinking about processing and OpenGL today&#8230; I always really enjoyed using matrix stuff, working with the matrix stack, using push() and pop() etc&#8230; Understanding how to use matrices is pretty important when your doing advanced graphics in actionscript. If you haven&#8217;t messed with matrices, this snippet is a good place to start. It uses Matrix.transformPoint() to draw a series of connected lines that are controlled by the x location of the mouse. Back before flash 8, this kind of thing was usually done using trig or MovieClip nesting&#8230;<\/p>\n<p>I posted <a href=\"https:\/\/actionsnippet.com\/?p=446\">another snippet<\/a> on this topic awhile back.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#x5B;SWF(width = 628, height=500)] var trans:Matrix = new Matrix(); var pnt:Point = new Point(); x = stage.stageWidth \/ 2; y = stage.stageHeight \/ 2; addEventListener(Event.ENTER_FRAME, onLoop); function onLoop(evt:Event):void { graphics.clear(); graphics.lineStyle(10, 0x000000, 1, false, LineScaleMode.NORMAL, CapsStyle.SQUARE); pnt.x = 0; pnt.y = 0; trans.identity(); trans.translate(15,15); trans.rotate(mouseX\/10 * Math.PI \/ 180); graphics.moveTo(pnt.x, pnt.y); for (var i:int = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[118,13],"tags":[],"class_list":["post-348","post","type-post","status-publish","format-standard","hentry","category-matrix","category-motion"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/348","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=348"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/348\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=348"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=348"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=348"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}