{"id":251,"date":"2014-11-22T20:24:41","date_gmt":"2014-11-22T12:24:41","guid":{"rendered":"http:\/\/www.hightopo.com\/blog\/?p=251"},"modified":"2014-11-22T20:49:32","modified_gmt":"2014-11-22T12:49:32","slug":"ht-for-web%e5%9f%ba%e4%ba%8ehtml5%e7%9a%84%e5%9b%be%e5%83%8f%e6%93%8d%e4%bd%9c%ef%bc%88%e4%b8%80%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.hightopo.com\/blog\/251.html","title":{"rendered":"HT for Web\u57fa\u4e8eHTML5\u7684\u56fe\u50cf\u64cd\u4f5c\uff08\u4e00\uff09"},"content":{"rendered":"<p><a href=\"http:\/\/www.hightopo.com\/\">HT for Web<\/a>\u72ec\u521b\u7684<a href=\"http:\/\/www.hightopo.com\/blog\/194.html\">\u77e2\u91cf\u56fe\u7247\u8bbe\u8ba1\u67b6\u6784<\/a>\uff0c\u4f7f\u5176\u5177\u6709\u5f3a\u5927\u4e30\u5bcc\u7684\u52a8\u6001\u56fe\u5f62\u5448\u73b0\u80fd\u529b\uff0c\u4f46\u4ece\u6700\u8fd1\u77e5\u4e4e\u70ed\u8bae\u7684\u201c<a href=\"http:\/\/www.zhihu.com\/question\/26705971\">Adobe Photoshop \u662f\u5426\u5df2\u7ecf\u8fc7\u65f6\uff1f<\/a>\u201d\u7684\u8bdd\u9898\uff0c\u5927\u5bb6\u80fd\u4f53\u4f1a\u5230\u5f88\u591a\u60c5\u51b5\u4e0b\u5b9e\u9645\u9879\u76ee\u4e0d\u53ef\u80fd\u5b8c\u5168\u91c7\u7528\u77e2\u91cf\uff0c\u9879\u76ee\u4e2d\u8fd8\u662f\u6709\u5927\u91cf\u7684\u4f20\u7edf\u975e\u77e2\u91cf\u7684\u9759\u6001\u56fe\u7247\uff0c\u6bd5\u7adf\u5de5\u5177\u5f3a\u5927\u4e14\u73b0\u6709\u8d44\u6e90\u4e30\u5bcc\uff0c\u4f46\u4e3a\u4e86\u4f7f\u9759\u6001\u56fe\u7247\u5448\u73b0\u51fa\u66f4\u591a\u7684\u52a8\u6001\u6548\u679c\uff0c<a href=\"http:\/\/www.hightopo.com\/\">HT for Web<\/a>\u63d0\u4f9b\u4e86\u8f83\u591a\u6e32\u67d3\u65b9\u5f0f\uff0c\u4f8b\u5982\u5bf9<a href=\"http:\/\/www.hightopo.com\/\">HT for Web<\/a>\u7684\u56fe\u5143\u8bbe\u7f6e\u2018body.color\u2019\u7684style\u540e\u56fe\u5143\u5373\u53ef\u8fbe\u5230\u81ea\u52a8\u67d3\u8272\u7684\u6548\u679c\uff0c\u8fd9\u91cc\u5c06\u5bf9\u8fd9\u79cd\u67d3\u8272\u6280\u672f\u8fdb\u884c\u8bb2\u89e3\u3002<\/p>\n<p><a href=\"http:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/11\/Screen-Shot-2014-11-22-at-7.26.24-PM.png\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-252\" alt=\"Screen Shot 2014-11-22 at 7.26.24 PM\" src=\"http:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/11\/Screen-Shot-2014-11-22-at-7.26.24-PM.png\" width=\"1194\" height=\"510\" srcset=\"https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/11\/Screen-Shot-2014-11-22-at-7.26.24-PM.png 1194w, https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/11\/Screen-Shot-2014-11-22-at-7.26.24-PM-300x128.png 300w, https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/11\/Screen-Shot-2014-11-22-at-7.26.24-PM-1024x437.png 1024w, https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/11\/Screen-Shot-2014-11-22-at-7.26.24-PM-200x85.png 200w\" sizes=\"(max-width: 1194px) 100vw, 1194px\" \/><\/a><\/p>\n<p>\u4e0a\u56fe\u5448\u73b0\u4e86\u672c\u6587\u4f8b\u5b50\u6700\u7ec8\u7684\u5448\u73b0\u6548\u679c\uff0c\u4e2d\u95f4\u4e3a\u539f\u59cb\u56fe\u7247\u662f<a href=\"http:\/\/hightopo.com\/images\/banner.png\">http:\/\/hightopo.com\/images\/banner.png<\/a>\u00a0\uff0c\u5bf9\u5176\u5206\u522b\u8bbe\u7f6e\u4e86\u7ea2\u3001\u9ec4\u548c\u84dd\u4e09\u79cd\u989c\u8272\u540e\u7684\u67d3\u8272\u6548\u679c\uff0c\u5b8c\u5168\u57fa\u4e8e<a href=\"http:\/\/www.hightopo.com\/\">HT for Web<\/a>\u5b9e\u73b0\u8fd9\u4e48\u4e2a\u7b80\u5355\u62d3\u6251\u7684\u8bdd\u4ee3\u7801\u4e0d\u8fc7\u5341\u591a\u884c\uff0c\u4e0d\u8fc7\u4eca\u5929\u6211\u4eec\u4e0d\u501f\u52a9<a href=\"http:\/\/www.hightopo.com\/\">HT for Web<\/a>\u63d0\u4f9b\u7684\u2018body.color\u2019\u7684\u67d3\u8272\u529f\u80fd\uff0c\u6211\u4eec\u5c06\u91c7\u7528\u6700\u539f\u59cb\u7684\u65b9\u5f0f\u751f\u4ea7\u67d3\u8272\u56fe\u7247\u3002<\/p>\n<pre class=\"brush:javascript\">dataModel = new ht.DataModel();                   \r\n\tgraphView = new ht.graph.GraphView(dataModel); \r\n\tgraphView.addToDOM();\r\n\tvar root = new ht.Node();\r\n\troot.setImage('ht-for-web.png');\r\n\tdataModel.add(root);                                \r\n\t['blue', 'yellow', 'red'].forEach(function(color){\r\n\t\tvar node = new ht.Node();\r\n\t\tnode.setImage('ht-for-web.png');\r\n\t\tnode.s({ 'body.color': color });\r\n\t\tdataModel.add(node);             \r\n\t\tvar edge = new ht.Edge(root, node);\r\n\t\tedge.s({'edge.color': color});\r\n\t\tdataModel.add(edge);                    \r\n\t});<\/pre>\n<p>\u67d3\u8272\u7684\u539f\u7406\u5c31\u662f\u5bf9\u56fe\u7247\u50cf\u7d20\u5185\u5bb9\u7684\u64cd\u4f5c\uff0c\u53ef\u4ee5\u7406\u89e3\u4e3a\u4e00\u4e2a convertColor(r, c, rawColor, &#8230;)-&gt;finalColor \u7684\u50cf\u7d20\u51fd\u6570\u8f6c\u6362, \u5176\u4e2d\u7684r\u548cc\u5206\u522b\u4ee3\u8868\u50cf\u7d20\u6240\u5728\u884c\u548c\u5217\uff0crawColor\u4e3a\u539f\u59cb\u989c\u8272\u4fe1\u606f\uff0c&#8230;\u4ee3\u8868\u5176\u4ed6\u7684\u53c2\u6570\u4fe1\u606f\uff0c\u4f8b\u5982\u6211\u4eec\u8fdb\u884c\u67d3\u8840\u7684\u989c\u8272\u4fe1\u606f\uff0c\u6700\u7ec8\u901a\u8fc7convertColor\u5904\u7406\u8fd4\u56de\u7684finalColor\u4e3a\u8f6c\u6362\u540e\u7684\u50cf\u7d20\u503c\u3002<\/p>\n<p>\u56fe\u7247\u67d3\u8272\u64cd\u4f5c\u53ef\u4ee5\u8bf4\u662f\u6700\u7b80\u5355\u7684\u56fe\u50cf\u5904\u7406\u4e86\uff0c\u672c\u8d28\u5c31\u662frawColor * tintColor\uff0c\u8fd9\u91cc\u7684tintColor\u53ef\u4ee5\u7406\u89e3\u4e3a<a href=\"http:\/\/www.hightopo.com\/\">HT for Web<\/a>\u7684body.color\u503c\uff0c\u4e00\u822c\u8be5\u4fe1\u606f\u4ee3\u8868\u76d1\u63a7\u7cfb\u7edf\u7684\u544a\u8b66\u7ea7\u522b\u72b6\u6001\u7b49\u4fe1\u606f\uff0c\u901a\u8fc7\u67d3\u8272\u8ba9\u7528\u6237\u66f4\u76f4\u89c2\u7684\u89c2\u5bdf\u5230\u8bbe\u5907\u8fd0\u884c\u544a\u8b66\u72b6\u6001\u3002\u8fd9\u91cc\u7684rawColor * tintColor\u76f8\u4e58\u662f\u672c\u8d28\u662f\u5206\u522b\u5bf9\u4e24\u4e2a\u989c\u8272\u7684rgb\u8fdb\u884c\u76f8\u4e58\uff0c\u4e00\u822c\u60c5\u51b5\u4e0b\u6700\u540e\u7684alpha\u7684\u900f\u660e\u5ea6\uff0c\u4f1a\u4fdd\u6301\u539f\u59cbrawColor\u7684\u503c\u4e0d\u8fdb\u884c\u64cd\u4f5c\u5904\u7406\u3002<\/p>\n<pre class=\"brush:javascript\">\ttoRGBA = (function(){\r\n\t\tvar map = {}, \/\/ string - [128,128,128,255]\r\n\t\t\tcanvas;\r\n\t\treturn function(color){\r\n\t\t\tvar g, data = map[color];\r\n\t\t\tif (!data) {\r\n\t\t\t\tif(!canvas){\r\n\t\t\t\t\tcanvas = document.createElement('canvas'); \r\n\t\t\t\t\tcanvas.width = 1;\r\n\t\t\t\t\tcanvas.height = 1;\r\n\t\t\t\t}\r\n\t\t\t\tg = canvas.getContext('2d');\r\n\t\t\t\tg.clearRect(0, 0, 1, 1);          \r\n\t\t\t\tg.fillStyle = color;\r\n\t\t\t\tg.beginPath();\r\n\t\t\t\tg.rect(0, 0, 1, 1);\r\n\t\t\t\tg.fill();                                                \r\n\t\t\t\tdata = g.getImageData(0, 0, 1, 1).data;\r\n\t\t\t\tdata = map[color] = [data[0], data[1], data[2], data[3]];\r\n\t\t\t}\r\n\t\t\treturn data;           \r\n\t\t};\r\n\t})();            \r\n\r\n\tfunction init(){    \r\n\t\tvar image = new Image();\r\n\t\timage.src = 'banner.png';\/\/ 'ht-for-web.png';\r\n\t\timage.onload = function(){\r\n\t\t\tdataModel = new ht.DataModel();                   \r\n\t\t\tgraphView = new ht.graph.GraphView(dataModel); \r\n\t\t\tgraphView.addToDOM();\r\n\r\n\t\t\tvar root = new ht.Node();\r\n\t\t\troot.setImage(image);\r\n\t\t\tdataModel.add(root);  \r\n\r\n\t\t\t['blue', 'yellow', 'red'].forEach(function(color){\r\n\t\t\t\tvar node = new ht.Node();\r\n\t\t\t\tnode.setImage(createColorImage1(image, color));                        \r\n\t\t\t\tdataModel.add(node);             \r\n\t\t\t\tvar edge = new ht.Edge(root, node);\r\n\t\t\t\tedge.s({\r\n\t\t\t\t\t'edge.color': color\r\n\t\t\t\t});\r\n\t\t\t\tdataModel.add(edge);                    \r\n\t\t\t});                     \r\n\t\t};\r\n\t}\r\n\tfunction createColorImage1(image, color) {\r\n\t\tvar width = image.width;\r\n\t\tvar height = image.height;                \r\n\t\tvar canvas = document.createElement('canvas');\r\n\t\tvar context = canvas.getContext( \"2d\" );\r\n\t\tcanvas.width = width;\r\n\t\tcanvas.height = height;\r\n\t\tcontext.drawImage(image, 0, 0, width, height);                \r\n\t\tvar rgba = toRGBA(color);\r\n\t\tvar r = rgba[0]\/255, g = rgba[1]\/255, b = rgba[2]\/255;\r\n\t\tvar pixelData = context.getImageData(0, 0, width, height);\r\n\t\tvar pixels = pixelData.data;\r\n\t\tfor (var i = 0; i &lt; pixels.length; i += 4)\r\n\t\t{\r\n\t\t\tpixels[i+0] *= r;\r\n\t\t\tpixels[i+1] *= g;\r\n\t\t\tpixels[i+2] *= b;\r\n\t\t}\r\n\t\tcontext.putImageData(pixelData, 0, 0);\r\n\t\treturn canvas;\r\n\t}<\/pre>\n<p>\u4ee5\u4e0a\u4ee3\u7801\u4e3a\u5b9e\u73b0\u7684\u5168\u90e8\u903b\u8f91\uff0c\u6709\u4e24\u70b9\u9700\u8981\u6ce8\u610f\uff0c\u989c\u8272\u503c\u901a\u8fc7getImageData\u8fd4\u56de\u7684\u662f0~255\u7684\u503c\uff0c\u8fdb\u884c\u67d3\u8272\u76f8\u4e58\u6211\u4eec\u9700\u8981\u57fa\u4e8e0~1\u7684\u683c\u5f0f\uff0c\u56e0\u6b64\u9700\u8981\u5148\u9664\u4ee5255\u8f6c\u6362\u540e\u518d\u76f8\u4e58\u3002\u53e6\u5916\u4e00\u70b9\u4e3a\u4e86\u65b9\u4fbf\u7528\u6237\u5f00\u53d1\uff0c\u989c\u8272\u503c\u5141\u8bb8\u662f\u4efb\u610fhtml\u652f\u6301\u7684\u989c\u8272\u683c\u5f0f\uff0c\u6709\u53ef\u80fd\u8f93\u5165red\uff0crgba(255,125,128,0.1)\u7b49\u683c\u5f0f\uff0c\u4ee5\u4e0atoRGBA\u4ee3\u7801\u5728\u95ed\u5305\u4e2d\u8fd4\u56de\u4e86\u4e2a\u53ef\u6839\u636e\u8f93\u5165\u683c\u5f0f\u8fd4\u56de\u989c\u8272\u6570\u7ec4\u7684\u5de5\u5177\u51fd\u6570\uff0c\u5176\u501f\u52a9\u7684\u4e5f\u662f\u5728\u4e00\u4e2a\u50cf\u7d20\u7684canvas\u5185\u5b58\u4e2d\u52a8\u6001\u7ed8\u5236\uff0c\u518d\u901a\u8fc7getImageData\u6765\u51b3\u5b9a\u989c\u8272\u4fe1\u606f\uff0c\u518d\u901a\u8fc7map\u7f13\u5b58\u8ba1\u7b97\u7ed3\u679c\uff0c\u8fd9\u79cd\u65b9\u5f0f\u6bd4\u679a\u4e3e\u4e00\u5806\u989c\u8272\u6620\u5c04\u8868\u6765\u5f97\u7cbe\u7b80\u3002<\/p>\n<p>\u5f53\u7136\u91c7\u7528\u8fd9\u79cd\u67d3\u8272\u7b97\u6cd5\u5728\u56fe\u5143\u662f\u7eaf\u9ed1\u8272\u7684\u65f6\u5019\u662f\u6709\u95ee\u9898\u7684\uff0c\u56e0\u4e3a\u9ed1\u8272\u7684rgb\u503c\u90fd\u4e3a0\uff0c\u56e0\u6b64\u65e0\u8bba\u4e58\u4ee5\u4ec0\u4e48\u989c\u8272\u7ed3\u679c\u4e5f\u90fd\u4e3a0\uff0c\u5b9e\u9645\u5e94\u7528\u573a\u666f\u53ef\u4ee5\u8981\u6c42\u7f8e\u5de5\u907f\u514d\u505a\u7eaf\u9ed1\u8272\u7684\u56fe\u7247\uff0c\u6216\u8005\u4ee3\u7801\u5bf9\u7eaf\u9ed1\u8272\u7684\u56fe\u7247\u8fdb\u884c\u7279\u6b8a\u7684\u8fd0\u7b97\u5904\u7406\u3002<\/p>\n<p>\u4ee5\u4e0a\u65b9\u5f0f\u4ec5\u662f\u7b2c\u4e00\u79cd\u67d3\u8272\u65b9\u5f0f\uff0c\u56e0\u6b64\u4e3acreateColorImage1\uff0c\u4e0b\u7bc7\u5c06\u4ecb\u7ecd\u7b2c\u4e8c\u79cd\u67d3\u8272\u65b9\u5f0fcreateColorImage2\u3002<\/p>\n<p><a href=\"http:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/11\/Screen-Shot-2014-11-22-at-8.23.41-PM.png\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-253\" alt=\"Screen Shot 2014-11-22 at 8.23.41 PM\" src=\"http:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/11\/Screen-Shot-2014-11-22-at-8.23.41-PM.png\" width=\"965\" height=\"594\" srcset=\"https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/11\/Screen-Shot-2014-11-22-at-8.23.41-PM.png 965w, https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/11\/Screen-Shot-2014-11-22-at-8.23.41-PM-300x184.png 300w, https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/11\/Screen-Shot-2014-11-22-at-8.23.41-PM-200x123.png 200w\" sizes=\"(max-width: 965px) 100vw, 965px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p><a href=\"http:\/\/www.hightopo.com\/\">HT for Web<\/a>\u72ec\u521b\u7684<a href=\"http:\/\/www.hightopo.com\/blog\/194.html\">\u77e2\u91cf\u56fe\u7247\u8bbe\u8ba1\u67b6\u6784<\/a>\uff0c\u4f7f\u5176\u5177\u6709\u5f3a\u5927\u4e30\u5bcc\u7684\u52a8\u6001\u56fe\u5f62\u5448\u73b0\u80fd\u529b\uff0c\u4f46\u4ece\u6700\u8fd1\u77e5\u4e4e\u70ed\u8bae\u7684\u201c<a href=\"http:\/\/www.zhihu.com\/question\/26705971\">Adobe Photoshop \u662f\u5426\u5df2\u7ecf\u8fc7\u65f6\uff1f<\/a>\u201d\u7684\u8bdd\u9898\uff0c\u5927\u5bb6\u80fd\u4f53\u4f1a\u5230\u5f88\u591a\u60c5\u51b5\u4e0b\u5b9e\u9645\u9879\u76ee\u4e0d\u53ef\u80fd\u5b8c\u5168\u91c7\u7528\u77e2\u91cf\uff0c\u9879\u76ee\u4e2d\u8fd8\u662f\u6709\u5927\u91cf\u7684\u4f20\u7edf\u975e\u77e2\u91cf\u7684\u9759\u6001\u56fe\u7247\uff0c\u6bd5\u7adf\u5de5\u5177\u5f3a\u5927\u4e14\u73b0\u6709\u8d44\u6e90\u4e30\u5bcc\uff0c\u4f46\u4e3a\u4e86\u4f7f\u9759\u6001\u56fe\u7247\u5448\u73b0\u51fa\u66f4\u591a\u7684\u52a8\u6001\u6548\u679c\uff0c<a href=\"http:\/\/www.hightopo.com\/\">HT for Web<\/a>\u63d0\u4f9b\u4e86\u8f83\u591a\u6e32\u67d3\u65b9\u5f0f\uff0c\u4f8b\u5982\u5bf9<a href=\"http:\/\/www.hightopo.com\/\">HT for Web<\/a>\u7684\u56fe\u5143\u8bbe\u7f6e\u2018body.color\u2019\u7684style\u540e\u56fe\u5143\u5373\u53ef\u8fbe\u5230\u81ea\u52a8\u67d3\u8272\u7684\u6548\u679c\uff0c\u8fd9\u91cc\u5c06\u5bf9\u8fd9\u79cd\u67d3\u8272\u6280\u672f\u8fdb\u884c\u8bb2\u89e3\u3002<\/p>\n<p><a href=\"http:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/11\/Screen-Shot-2014-11-22-at-7.26.24-PM.png\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-252\" alt=\"Screen Shot 2014-11-22 at 7.26.24 PM\" src=\"http:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/11\/Screen-Shot-2014-11-22-at-7.26.24-PM.png\" width=\"1194\" height=\"510\" srcset=\"https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/11\/Screen-Shot-2014-11-22-at-7.26.24-PM.png 1194w, https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/11\/Screen-Shot-2014-11-22-at-7.26.24-PM-300x128.png 300w, https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/11\/Screen-Shot-2014-11-22-at-7.26.24-PM-1024x437.png 1024w, https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/11\/Screen-Shot-2014-11-22-at-7.26.24-PM-200x85.png 200w\" sizes=\"(max-width: 1194px) 100vw, 1194px\" \/><\/a><\/p>\n<p>\u4e0a\u56fe\u5448\u73b0\u4e86\u672c\u6587\u4f8b\u5b50\u6700\u7ec8\u7684\u5448\u73b0\u6548\u679c\uff0c\u4e2d\u95f4\u4e3a\u539f\u59cb\u56fe\u7247\u662f<a href=\"http:\/\/hightopo.com\/images\/banner.png\">http:\/\/hightopo.com\/images\/banner.png<\/a>\u00a0\uff0c\u5bf9\u5176\u5206\u522b\u8bbe\u7f6e\u4e86\u7ea2\u3001\u9ec4\u548c\u84dd\u4e09\u79cd\u989c\u8272\u540e\u7684\u67d3\u8272\u6548\u679c\uff0c\u5b8c\u5168\u57fa\u4e8e<a href=\"http:\/\/www.hightopo.com\/\">HT for Web<\/a>\u5b9e\u73b0\u8fd9\u4e48\u4e2a\u7b80\u5355\u62d3\u6251\u7684\u8bdd\u4ee3\u7801\u4e0d\u8fc7\u5341\u591a\u884c\uff0c\u4e0d\u8fc7\u4eca\u5929\u6211\u4eec\u4e0d\u501f\u52a9<a href=\"http:\/\/www.hightopo.com\/\">HT for Web<\/a>\u63d0\u4f9b\u7684\u2018body.color\u2019\u7684\u67d3\u8272\u529f\u80fd\uff0c\u6211\u4eec\u5c06\u91c7\u7528\u6700\u539f\u59cb\u7684\u65b9\u5f0f\u751f\u4ea7\u67d3\u8272\u56fe\u7247\u3002<\/p>\n<pre class=\"brush:javascript\">dataModel = new ht.DataModel();                   \r\n\tgraphView = new ht.graph.GraphView(dataModel); \r\n\tgraphView.addToDOM();\r\n\tvar root = new ht.Node();\r\n\troot.setImage('ht-for-web.png');\r\n\tdataModel.add(root);                                \r\n\t['blue', 'yellow', 'red'].forEach(function(color){\r\n\t\tvar node = new ht.Node();\r\n\t\tnode.setImage('ht-for-web.png');\r\n\t\tnode.s({ 'body.color': color });\r\n\t\tdataModel.add(node);             \r\n\t\tvar edge = new ht.Edge(root, node);\r\n\t\tedge.s({'edge.color': color});\r\n\t\tdataModel.add(edge);                    \r\n\t});<\/pre>\n<p>\u67d3\u8272\u7684\u539f\u7406\u5c31\u662f\u5bf9\u56fe\u7247\u50cf\u7d20\u5185\u5bb9\u7684\u64cd\u4f5c\uff0c\u53ef\u4ee5\u7406\u89e3\u4e3a\u4e00\u4e2a convertColor(r, c, rawColor, &#8230;)-&gt;finalColor \u7684\u50cf\u7d20\u51fd\u6570\u8f6c\u6362, \u5176\u4e2d\u7684r\u548cc\u5206\u522b\u4ee3\u8868\u50cf\u7d20\u6240\u5728\u884c\u548c\u5217\uff0crawColor\u4e3a\u539f\u59cb\u989c\u8272\u4fe1\u606f\uff0c&#8230;\u4ee3\u8868\u5176\u4ed6\u7684\u53c2\u6570\u4fe1\u606f\uff0c\u4f8b\u5982\u6211\u4eec\u8fdb\u884c\u67d3\u8840\u7684\u989c\u8272\u4fe1\u606f\uff0c\u6700\u7ec8\u901a\u8fc7convertColor\u5904\u7406\u8fd4\u56de\u7684finalColor\u4e3a\u8f6c\u6362\u540e\u7684\u50cf\u7d20\u503c\u3002<\/p>\n<p>\u56fe\u7247\u67d3\u8272\u64cd\u4f5c\u53ef\u4ee5\u8bf4\u662f\u6700\u7b80\u5355\u7684\u56fe\u50cf\u5904\u7406\u4e86\uff0c\u672c\u8d28\u5c31\u662frawColor * tintColor\uff0c\u8fd9\u91cc\u7684tintColor\u53ef\u4ee5\u7406\u89e3\u4e3a<a href=\"http:\/\/www.hightopo.com\/\">HT for Web<\/a>\u7684body.color\u503c\uff0c\u4e00\u822c\u8be5\u4fe1\u606f\u4ee3\u8868\u76d1\u63a7\u7cfb\u7edf\u7684\u544a\u8b66\u7ea7\u522b\u72b6\u6001\u7b49\u4fe1\u606f\uff0c\u901a\u8fc7\u67d3\u8272\u8ba9\u7528\u6237\u66f4\u76f4\u89c2\u7684\u89c2\u5bdf\u5230\u8bbe\u5907\u8fd0\u884c\u544a\u8b66\u72b6\u6001\u3002\u8fd9\u91cc\u7684rawColor * tintColor\u76f8\u4e58\u662f\u672c\u8d28\u662f\u5206\u522b\u5bf9\u4e24\u4e2a\u989c\u8272\u7684rgb\u8fdb\u884c\u76f8\u4e58\uff0c\u4e00\u822c\u60c5\u51b5\u4e0b\u6700\u540e\u7684alpha\u7684\u900f\u660e\u5ea6\uff0c\u4f1a\u4fdd\u6301\u539f\u59cbrawColor\u7684\u503c\u4e0d\u8fdb\u884c\u64cd\u4f5c\u5904\u7406\u3002<\/p>\n<pre class=\"brush:javascript\">\ttoRGBA = (function(){\r\n\t\tvar map = {}, \/\/ string - [128,128,128,255]\r\n\t\t\tcanvas;\r\n\t\treturn function(color){\r\n\t\t\tvar g, data = map[color];\r\n\t\t\tif (!data) {\r\n\t\t\t\tif(!canvas){\r\n\t\t\t\t\tcanvas = document.createElement('canvas'); \r\n\t\t\t\t\tcanvas.width = 1;\r\n\t\t\t\t\tcanvas.height = 1;\r\n\t\t\t\t}\r\n\t\t\t\tg = canvas.getContext('2d');\r\n\t\t\t\tg.clearRect(0, 0, 1, 1);          \r\n\t\t\t\tg.fillStyle = color;\r\n\t\t\t\tg.beginPath();\r\n\t\t\t\tg.rect(0, 0, 1, 1);\r\n\t\t\t\tg.fill();                                                \r\n\t\t\t\tdata = g.getImageData(0, 0, 1, 1).data;\r\n\t\t\t\tdata = map[color] = [data[0], data[1], data[2], data[3]];\r\n\t\t\t}\r\n\t\t\treturn data;           \r\n\t\t};\r\n\t})();            \r\n\r\n\tfunction init(){    \r\n\t\tvar image = new Image();\r\n\t\timage.src = 'banner.png';\/\/ 'ht-for-web.png';\r\n\t\timage.onload = function(){\r\n\t\t\tdataModel = new ht.DataModel();                   \r\n\t\t\tgraphView = new ht.graph.GraphView(dataModel); \r\n\t\t\tgraphView.addToDOM();\r\n\r\n\t\t\tvar root = new ht.Node();\r\n\t\t\troot.setImage(image);\r\n\t\t\tdataModel.add(root);  \r\n\r\n\t\t\t['blue', 'yellow', 'red'].forEach(function(color){\r\n\t\t\t\tvar node = new ht.Node();\r\n\t\t\t\tnode.setImage(createColorImage1(image, color));                        \r\n\t\t\t\tdataModel.add(node);             \r\n\t\t\t\tvar edge = new ht.Edge(root, node);\r\n\t\t\t\tedge.s({\r\n\t\t\t\t\t'edge.color': color\r\n\t\t\t\t});\r\n\t\t\t\tdataModel.add(edge);                    \r\n\t\t\t});                     \r\n\t\t};\r\n\t}\r\n\tfunction createColorImage1(image, color) {\r\n\t\tvar width = image.width;\r\n\t\tvar height = image.height;                \r\n\t\tvar canvas = document.createElement('canvas');\r\n\t\tvar context = canvas.getContext( \"2d\" );\r\n\t\tcanvas.width = width;\r\n\t\tcanvas.height = height;\r\n\t\tcontext.drawImage(image, 0, 0, width, height);                \r\n\t\tvar rgba = toRGBA(color);\r\n\t\tvar r = rgba[0]\/255, g = rgba[1]\/255, b = rgba[2]\/255;\r\n\t\tvar pixelData = context.getImageData(0, 0, width, height);\r\n\t\tvar pixels = pixelData.data;\r\n\t\tfor (var i = 0; i &lt; pixels.length; i += 4)\r\n\t\t{\r\n\t\t\tpixels[i+0] *= r;\r\n\t\t\tpixels[i+1] *= g;\r\n\t\t\tpixels[i+2] *= b;\r\n\t\t}\r\n\t\tcontext.putImageData(pixelData, 0, 0);\r\n\t\treturn canvas;\r\n\t}<\/pre>\n<p>\u4ee5\u4e0a\u4ee3\u7801\u4e3a\u5b9e\u73b0\u7684\u5168\u90e8\u903b\u8f91\uff0c\u6709\u4e24\u70b9\u9700\u8981\u6ce8\u610f\uff0c\u989c\u8272\u503c\u901a\u8fc7getImageData\u8fd4\u56de\u7684\u662f0~255\u7684\u503c\uff0c\u8fdb\u884c\u67d3\u8272\u76f8\u4e58\u6211\u4eec\u9700\u8981\u57fa\u4e8e0~1\u7684\u683c\u5f0f\uff0c\u56e0\u6b64\u9700\u8981\u5148\u9664\u4ee5255\u8f6c\u6362\u540e\u518d\u76f8\u4e58\u3002\u53e6\u5916\u4e00\u70b9\u4e3a\u4e86\u65b9\u4fbf\u7528\u6237\u5f00\u53d1\uff0c\u989c\u8272\u503c\u5141\u8bb8\u662f\u4efb\u610fhtml\u652f\u6301\u7684\u989c\u8272\u683c\u5f0f\uff0c\u6709\u53ef\u80fd\u8f93\u5165red\uff0crgba(255,125,128,0.1)\u7b49\u683c\u5f0f\uff0c\u4ee5\u4e0atoRGBA\u4ee3\u7801\u5728\u95ed\u5305\u4e2d\u8fd4\u56de\u4e86\u4e2a\u53ef\u6839\u636e\u8f93\u5165\u683c\u5f0f\u8fd4\u56de\u989c\u8272\u6570\u7ec4\u7684\u5de5\u5177\u51fd\u6570\uff0c\u5176\u501f\u52a9\u7684\u4e5f\u662f\u5728\u4e00\u4e2a\u50cf\u7d20\u7684canvas\u5185\u5b58\u4e2d\u52a8\u6001\u7ed8\u5236\uff0c\u518d\u901a\u8fc7getImageData\u6765\u51b3\u5b9a\u989c\u8272\u4fe1\u606f\uff0c\u518d\u901a\u8fc7map\u7f13\u5b58\u8ba1\u7b97\u7ed3\u679c\uff0c\u8fd9\u79cd\u65b9\u5f0f\u6bd4\u679a\u4e3e\u4e00\u5806\u989c\u8272\u6620\u5c04\u8868\u6765\u5f97\u7cbe\u7b80\u3002<\/p>\n<p>\u5f53\u7136\u91c7\u7528\u8fd9\u79cd\u67d3\u8272\u7b97\u6cd5\u5728\u56fe\u5143\u662f\u7eaf\u9ed1\u8272\u7684\u65f6\u5019\u662f\u6709\u95ee\u9898\u7684\uff0c\u56e0\u4e3a\u9ed1\u8272\u7684rgb\u503c\u90fd\u4e3a0\uff0c\u56e0\u6b64\u65e0\u8bba\u4e58\u4ee5\u4ec0\u4e48\u989c\u8272\u7ed3\u679c\u4e5f\u90fd\u4e3a0\uff0c\u5b9e\u9645\u5e94\u7528\u573a\u666f\u53ef\u4ee5\u8981\u6c42\u7f8e\u5de5\u907f\u514d\u505a\u7eaf\u9ed1\u8272\u7684\u56fe\u7247\uff0c\u6216\u8005\u4ee3\u7801\u5bf9\u7eaf\u9ed1\u8272\u7684\u56fe\u7247\u8fdb\u884c\u7279\u6b8a\u7684\u8fd0\u7b97\u5904\u7406\u3002<\/p>\n<p>\u4ee5\u4e0a\u65b9\u5f0f\u4ec5\u662f\u7b2c\u4e00\u79cd\u67d3\u8272\u65b9\u5f0f\uff0c\u56e0\u6b64\u4e3acreateColorImage1\uff0c\u4e0b\u7bc7\u5c06\u4ecb\u7ecd\u7b2c\u4e8c\u79cd\u67d3\u8272\u65b9\u5f0fcreateColorImage2\u3002<\/p>\n<p><a href=\"http:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/11\/Screen-Shot-2014-11-22-at-8.23.41-PM.png\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-253\" alt=\"Screen Shot 2014-11-22 at 8.23.41 PM\" src=\"http:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/11\/Screen-Shot-2014-11-22-at-8.23.41-PM.png\" width=\"965\" height=\"594\" srcset=\"https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/11\/Screen-Shot-2014-11-22-at-8.23.41-PM.png 965w, https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/11\/Screen-Shot-2014-11-22-at-8.23.41-PM-300x184.png 300w, https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/11\/Screen-Shot-2014-11-22-at-8.23.41-PM-200x123.png 200w\" sizes=\"(max-width: 965px) 100vw, 965px\" \/><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.hightopo.com\/blog\/wp-json\/wp\/v2\/posts\/251"}],"collection":[{"href":"https:\/\/www.hightopo.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hightopo.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hightopo.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hightopo.com\/blog\/wp-json\/wp\/v2\/comments?post=251"}],"version-history":[{"count":2,"href":"https:\/\/www.hightopo.com\/blog\/wp-json\/wp\/v2\/posts\/251\/revisions"}],"predecessor-version":[{"id":255,"href":"https:\/\/www.hightopo.com\/blog\/wp-json\/wp\/v2\/posts\/251\/revisions\/255"}],"wp:attachment":[{"href":"https:\/\/www.hightopo.com\/blog\/wp-json\/wp\/v2\/media?parent=251"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hightopo.com\/blog\/wp-json\/wp\/v2\/categories?post=251"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hightopo.com\/blog\/wp-json\/wp\/v2\/tags?post=251"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}