{"id":346,"date":"2015-10-19T11:50:26","date_gmt":"2015-10-19T02:50:26","guid":{"rendered":"http:\/\/www.takaya-com.jp\/archives\/?p=346"},"modified":"2015-10-19T17:36:41","modified_gmt":"2015-10-19T08:36:41","slug":"svg_transform_sp2","status":"publish","type":"post","link":"https:\/\/takaya-com.jp\/archives\/2015\/10\/svg_transform_sp2\/","title":{"rendered":"JavaScript\u3067HTML5 SVG\u306ematrix\u3092\u76f4\u63a5\u64cd\u4f5c\u3057transform\u3055\u305b\u308b"},"content":{"rendered":"<p>\tSVGTransform\u5185\u306b\u7528\u610f\u3055\u308c\u3066\u3044\u308bmatrix\u306e\u5024\u3092\u76f4\u63a5\u64cd\u4f5c\u3059\u308b\u3053\u3068\u3067\u3001SVG\u306b\u3082\u3068\u3068\u3082\u7528\u610f\u3055\u308c\u3066\u3044\u308b<br \/>\nrotate()\u3001translate()\u3001scale()\u306a\u3069\u306e\u547d\u4ee4\u3068\u540c\u7b49\u306e\u51e6\u7406\u3092\u884c\u3044\u307e\u3059\u3002\n<\/p>\n<p>  <!--more--><\/p>\n<p>\n\t\u6ce8\u610f\uff1a\u4f55\u304b\u51e6\u7406\u3092\u3057\u305f\u3042\u3068\u3001\u307b\u304b\u306e\u30dc\u30bf\u30f3\u3092\u62bc\u3059\u3068\u3001\u610f\u56f3\u3057\u305f\u52d5\u4f5c\u306b\u306a\u3089\u306a\u3044\u3068\u304d\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n\t\uff08matrix\u306b\u524d\u306e\u8a08\u7b97\u306b\u3064\u304b\u3063\u305f\u5024\u304c\u6b8b\u3063\u3066\u3044\u308b\u6a21\u69d8\uff09<br \/>\n\t\u65e2\u5b58\u306e\u547d\u4ee4\u3067\u5bfe\u5fdc\u3067\u304d\u308b\u5834\u5408\u306f\u7121\u7406\u306bmatrix\u3092\u3044\u3058\u3089\u306a\u3044\u307b\u3046\u304c\u624b\u3063\u53d6\u308a\u65e9\u304f\u3066\u304a\u52e7\u3081\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002\n<\/p>\n<p>\n\t\u306a\u304a\u3001console.log()\u306b\u3066SVGTransform\u306a\u3069\u3092\u51fa\u529b\u3057\u3066\u3044\u308b\u306e\u3067\u8208\u5473\u306e\u3042\u308b\u304b\u305f\u306f\u30d6\u30e9\u30a6\u30b6\u306e\u958b\u767a\u30c4\u30fc\u30eb\u306a\u3069\u3067\u3054\u3089\u3093\u304f\u3060\u3055\u3044\u3002<br \/>\n\u2193\u4ee5\u4e0b\u304c\u5b9f\u969b\u306e\u30bd\u30fc\u30b9\u30b5\u30f3\u30d7\u30eb\u3067\u3059\u3002<\/p>\n<p>\u25bcJavaScript<\/p>\n<pre class=\"lang:js decode:true \" title=\"JavaScript\" >\r\n&lt;script&gt;\r\n\t\/\/\tsvg\u306e\u8981\u7d20\u3092\u53d6\u5f97\r\n\tvar SVG_1 = document.getElementById(\"box_1\");\r\n\tconsole.log(SVG_1);\r\n\t\/\/\tsvg\u306bSVGTransform\u3092\u751f\u6210\u3059\u308b\r\n\tvar Transform = SVG_1.createSVGTransform();\r\n\tconsole.log(Transform);\r\n\t\/\/\t\u751f\u6210\u3055\u308c\u305fTransform\u5185\u306ematrix\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092Matrix\u306b\u53c2\u7167\r\n\tvar Matrix = Transform.matrix;\r\n\tconsole.log(Matrix);\r\n\t\/\/\t\u4eca\u56de\u306f\u7279\u306b\u4f7f\u308f\u306a\u3044\u3067\u3059\u304cx,y,height,width\u304c\u53d6\u5f97\u3067\u304d\u308bgetBBox\u3092\u30e1\u30e2\r\n\tconsole.log(SVG_1.getBBox());\r\n\r\n\tvar Group_1 = document.getElementById(\"g_1\");\r\n\tvar box1=(\tSVG_1.getBBox());\r\n\r\nfunction M_rotate(deg){\r\n\tGroup_1.transform.baseVal.appendItem(Transform);\r\n\tvar rad=deg\/180*Math.PI;\r\n\tcos_r=Math.cos(rad);\r\n\tsin_r=Math.sin(rad);\r\n\tMatrix.a=cos_r;\r\n\tMatrix.c=-sin_r;\r\n\tMatrix.e=0;\r\n\tMatrix.b=sin_r;\r\n\tMatrix.d=cos_r;\r\n\tMatrix.f=0;\r\nconsole.log(Transform);\r\n}\r\n\r\nfunction M_translate(x,y){\r\n\tGroup_1.transform.baseVal.appendItem(Transform);\r\n\tMatrix.a=1;\r\n\tMatrix.c=0;\r\n\tMatrix.e=x;\r\n\tMatrix.b=0;\r\n\tMatrix.d=1;\r\n\tMatrix.f=y;\r\n}\r\n\r\nfunction M_scale_origin(x,y){\r\n\tGroup_1.transform.baseVal.appendItem(Transform);\r\n\tMatrix.a=x;\r\n\tMatrix.c=0;\r\n\tMatrix.e=0;\r\n\tMatrix.b=0;\r\n\tMatrix.d=y;\r\n\tMatrix.f=0;\r\n}\r\n&lt;\/script&gt;\r\n\r\n<\/pre>\n<p>\u25bcCSS<\/p>\n<pre class=\"lang:css decode:true \" title=\"CSS\" >\r\n<style>\r\nsvg{\r\n\twidth:500px;\r\n\theight:500px;\r\n}\r\n<\/style>\r\n<\/pre>\n<p>\u25bcHTML<\/p>\n<pre class=\"lang:xhtml decode:true \" title=\"XHTML\" >\r\n<input id=\"button01\" type=\"button\" value=\"matrix_rotate_\u6642\u8a08\u56de\u308a45\u5ea6\" onClick=\"M_rotate(45);\" \/>\r\n<input id=\"button02\" type=\"button\" value=\"Matrix_translate_\u53f3\u4e0b\" onClick=\"M_translate(11,11);\" \/>\r\n<input id=\"button02\" type=\"button\" value=\"Matrix_translate_\u5de6\u4e0a\" onClick=\"M_translate(-11,-11);\" \/>\r\n<input id=\"button03\" type=\"button\" value=\"Matrix_scale_\u62e1\u5927\" onClick=\"M_scale_origin(11\/10,11\/10);\" \/>\r\n<input id=\"button03\" type=\"button\" value=\"Matrix_scale_\u7e2e\u5c0f\" onClick=\"M_scale_origin(10\/11,10\/11);\" \/>\r\n<div>\r\n<svg id=\"box_1\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" version=\"1.1\" viewBox=\"-200 -200 600 600\">\r\n\t<g id=\"g_1\">\r\n\t\t<rect id=\"rect_1\" height=\"200\" width=\"200\" x=\"0\" y=\"0\" fill=\"red\" stroke=\"black\" stroke-width=\"5\" \/>\r\n\t\t<circle cx=\"0\" cy=\" 0\" r=\"10\" fill=\" blue\" \/>\r\n\t<\/g>\r\n<\/svg>\r\n<\/div>\r\n<\/pre>\n<p><a href=\"http:\/\/www.takaya-com.jp\/archives\/demo\/svg_transform_sp2\/\" target=\"_blank\">\u30c7\u30e2\u30da\u30fc\u30b8\u306f\u3001\u3053\u3061\u3089<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>SVGTransform\u5185\u306b\u7528\u610f\u3055\u308c\u3066\u3044\u308bmatrix\u306e\u5024\u3092\u76f4\u63a5\u64cd\u4f5c\u3059\u308b\u3053\u3068\u3067\u3001SVG\u306b\u3082\u3068\u3068\u3082\u7528\u610f\u3055\u308c\u3066\u3044\u308b rotate()\u3001translate()\u3001scale()\u306a\u3069\u306e\u547d\u4ee4\u3068\u540c\u7b49\u306e\u51e6\u7406\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1,3],"tags":[],"_links":{"self":[{"href":"https:\/\/takaya-com.jp\/archives\/wp-json\/wp\/v2\/posts\/346"}],"collection":[{"href":"https:\/\/takaya-com.jp\/archives\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/takaya-com.jp\/archives\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/takaya-com.jp\/archives\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/takaya-com.jp\/archives\/wp-json\/wp\/v2\/comments?post=346"}],"version-history":[{"count":9,"href":"https:\/\/takaya-com.jp\/archives\/wp-json\/wp\/v2\/posts\/346\/revisions"}],"predecessor-version":[{"id":355,"href":"https:\/\/takaya-com.jp\/archives\/wp-json\/wp\/v2\/posts\/346\/revisions\/355"}],"wp:attachment":[{"href":"https:\/\/takaya-com.jp\/archives\/wp-json\/wp\/v2\/media?parent=346"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/takaya-com.jp\/archives\/wp-json\/wp\/v2\/categories?post=346"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/takaya-com.jp\/archives\/wp-json\/wp\/v2\/tags?post=346"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}