HTML5 LogoãCanvasã§æãã¦ã¿ã
ãã£ãè¯ããã ãæªããã ããã¡ãã£ã¨ããããªããã©ãHTML5ã®ãã´ãã§ããã¨ãããã¨ãªã®ã§ãã¡ãã£ã¨éãã§ã¿ããCCã©ã¤ã»ã³ã¹ã§æä¾ããã¦ãããSVGãã¼ã¿ãããã®ã§ãä¸èº«ãè¦ãã¨ããããããªãããã«Cavnasã§ãæãããã ã¨æãç«ã£ãã®ã§ã帰å®
é»è»ã®ä¸ã§ã³ã¼ããæ¸ãã¦ã¿ãï¼ã¯ãããæ°æ¥½ã¢ã¼ãã§ãï¼ã
polygonã¯ä¸è¨ã®ããã«é ç¹ã®ä¸¦ã³pointsã¨å¡ãã¤ã¶ãè²ãæå®ãã¦ããã ãã
<polygon fill="hsl(13, 77%, 52%)" points="107.644,470.877 74.633,100.62 437.367,100.62 404.321,470.819 255.778,512 "/>
pointsãæ£è¦è¡¨ç¾ã§ãã¼ã¹ããã®ãå®è£ ãç°¡åãä¸åº¦ã«å ¨é¨å解ããã®ããããã©ãgãªãã·ã§ã³ã§æå¹ãªlastIndexæ©æ§ã使ã£ã¦åããé çªã«ãã¼ã¹ããã以ä¸ã®ãããªã³ã¼ãã«ãªããforã®ä½¿ãæ¹ã«ã¡ãã£ã¨æµæãæãã人ããããããããªãã
var pat = /(-?\d+(\.\d+)?)\s*,\s*(-?\d+(\.\d+)?)/g; g.beginPath(); for (var p, head = true; (p = pat.exec(points)); ) { var x = Number(p[1]); var y = Number(p[3]); if (head) { g.moveTo(x, y); head = false; ] else { g.lineTo(x, y); } } g.close(); g.fill();
次ã«ãpathã¯ä¸è¨ã®ããã«ç¸å¯¾/絶対座æ¨ã¨åç´/æ°´å¹³ç´ç·ã ãã使ã£ã¦ããã大æåã¯çµ¶å¯¾åº§æ¨ã§ãå°æåãç¸å¯¾åº§æ¨ãMã¯å§ç¹(moveTo), Hã¯æ°´å¹³ç´ç·ãVã¯åç´ç´ç·ã
<path d="M108.382,0h23.077v22.8h21.11V0h23.078v69.044H152.57v-23.12h-21.11v23.12h-23.077V0z"/>
polygonã®æ£è¦è¡¨ç¾ããã¡ãã£ã¨è¤éã ãã©ã大ãããã¨ã¯ãªããCanvasã«ã¯ç¸å¯¾ä½ç½®æå®ã®lineToããªãã®ã§ãç¾å¨ã®(x, y)座æ¨ãå¤æ°ã«ä¿æãã¦ããã以ä¸ã®ãããªã³ã¼ãã«ãªãã
var pat = /([MLVHZ])(\s*(-?\d+(\.\d+)?)(,|\s+)?(-?\d+(\.\d+)?)?)?/ig; var x = 0; var y = 0; g.beginPath(); for (var p; (p = pat.exec(path)); ) { switch (p[1]) { case 'M': x = Number(p[3]); y = Number(p[6]); g.moveTo(x, y); break; case 'v': y += Number(p[3]); g.lineTo(x, y); break; case 'H': x = Number(p[3]); g.lineTo(x, y); break; : (ç¥) : case 'z': g.closePath(); break; } } g.fill();
ãããã¦ã§ããã®ããå·¦ã®ç»é¢ãåã«è¡¨ç¤ºãã¦ãã¤ã¾ããªãã®ã§ãããããå転伸縮ã¢ãã¡ã¼ã·ã§ã³ãã¤ããã
ã³ã¼ãã¨å®éã®åä½ã¯ããã¡ãããã©ããï¼
æ°æ´ããã«SVGãã®ãã®ããCanvasã«æç»ããã³ã¼ããæ¸ãã®ãé¢ç½ããããããªãã
Have fun!