ãã¹ã¿ã¼ã»ãªãã»å弧 #SVG
ãã®è¨äºã¯ SVG Advent Calendar 2015 ã®25æ¥ç®ã®è¨äºã§ãã
www.adventar.org
Advent Calendar ã®æå¾ãç· ããããã®ã«ç¸å¿ããå
容ãã©ããã¯ãããã¾ããããçãããã£ã¨SVGãæããããªãã¯ãã§ãã
SVGã¨ã¯ï¼
SVGã¨ã¯ç»åãã¡ã¤ã«ã®å½¢å¼ã®ä¸ã¤ã§ãåºæ¬çã«ã¯ãã¯ã¿ã¼ç»åï¼å¼ã伸ã°ãã¦ãèããªãã¢ã¬ï¼ã§ããç»åãªãã ãã©ä¸èº«ã¯XMLãããªãã¡ããã¹ããã¡ã¤ã«ã«ãªã£ã¦ãããä¸æè°ã§ä¾¿å©ãªç»åã§ãããã¾ããã§åãã¦SVGã®ååãèããã¨ããçããã¯ãä¸è¨ã® Advent Calendar ã«æ²è¼ããã¦ããè¨äºãèªãã ããWikipediaの記事 ãèªãã¨è¯ãã§ãããã
SVGææãã¨ã¯ï¼
åè¿°ã®éãSVGã¯XMLã§ãããããã¹ãã§ãã
ããã¹ãã§ããã¨ãããã¨ã¯ãããã¹ãã¨ãã£ã¿ã§ä½æãããç·¨éããããããã¨ãçè«ä¸å¯è½ã§ããã¨ãããã¨ãè¨ãã¾ãã
çè«ä¸å¯è½ãªãã ã£ããå®éã«ããããï¼ã¨èããã®ã人éã¨ãããã®ã§ããããããèæ¯ããè¿å¹´çãä¸ãã£ã¦ãã¦ããã®ããSVGææããã¨ãã趣å³ã«ãªãã¾ããããã¹ãã¨ãã£ã¿ã§æãã¾ãããã
ï¼æ³¨æï¼ä¸è¬çã«ã¯ãAdobe Illustrator ãªã©ã®ãã¼ã«ã§æããç»åãSVGå½¢å¼ã§åºåãããã¨ãå¤ãã¯ãã§ãã
ãããªç»åã ã£ã¦ãSVGãªãããã¹ãã¨ãã£ã¿ã§ãµã¯ãã¨æãã¾ãã
ã½ã¼ã¹ã¯ãããªæãã§ãã
ãããã³ãã¼ãã¦ããã¹ãã¨ãã£ã¿ã«è²¼ãä»ããæ¡å¼µåã.svgãã§ä¿åããã¦ãããã©ã¦ã¶ã«èªã¿è¾¼ã¾ããã¨åãããã«æç»ãããã¯ãã§ãã
<?xml version="1.0" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg width="480px" height="360px" viewBox="0 0 480 360" xmlns="http://www.w3.org/2000/svg" version="1.1"> <rect fill="white" stroke="black" stroke-width="2" x="0" y="0" width="480" height="360"/> <polygon fill="red" stroke="none" points="40,40 40,320 440,320 440,40 400,40 400,280 80,280 80,40"/> </svg>
rect è¦ç´ ãå¤æ ã®é»ãç´°ãç·ãã polygon è¦ç´ ããå¹ãã®åãæãã¦ãã¾ãã
â»å¥ã«çè
ãå¹ãã§ãã訳ã§ã¯ãªãã§ããããï¼
æ £ãã¦ããã¨ãå ¬å¼ã® SVG 1.1 の仕様 ãè¦ãªããã§ããã°5å以å ã«ä¸è¨ã®å³å½¢ãæããã¨ãã§ããããã«ãªãã¾ããããã¹ãã¨ãã£ã¿ã§ã
pathè¦ç´
SVGã§ã¯ããã¾ãã¾ãªå³å½¢ããµãã¼ãããã¦ãããç°¡åã«å³å½¢ãæããã¨ãã§ãã¾ãã
ä¾ãã°ä»¥ä¸ã®ãããªå³å½¢ãããã¾ãã
- rect : é·æ¹å½¢ãå·¦ä¸åº§æ¨ã¨å¹ ã¨é«ããæå®ãã¦æãã
- circle : åï¼æ¥åã§ã¯ãªãçåï¼ãä¸å¿åº§æ¨ã¨åå¾ãæå®ãã¦æãã
- ellipse : æ¥åãä¸å¿åº§æ¨ã¨xæ¹ååå¾ãyæ¹ååå¾ã¨ãæå®ãã¦æããï¼å転ã¯ã¢ãã£ã³å¤æã§å®ç¾ï¼
- line : ç·åãå§ç¹ã¨çµç¹ãæå®ãã¦æãã
- polyline : ç·åãã¤ãªããããããã®ãã«ã¯ã«ã¯æ²ããã
- polygon : å¤è§å½¢ãåé ç¹ã®åº§æ¨ãæå®ãã¦æãã
ãããã¯é常ã«ä¾¿å©ã§ããããã¤ãå¾ããSVGã®ã½ã¼ã¹ãè¦ãã¨ãã«æå³ãåããããããããé常ã«éå®ãã¾ãããããã®è¦ç´ ã使ã£ã¦æããã¨ãã§ããã®ã§ããã°ããã²ããããã¹ãã§ãã
ã¨ãããããããã®å³å½¢ã§ã¯è¡¨ç¾ã§ããªããã®ã¨ããã®ã¯æ°å¤ãåå¨ãã¾ãã
ãããã£ãå³å½¢ã¯ãpath要素 ã使ã£ã¦æããã¨ã«ãªãã¾ãã
ç»åãæãããã°ã©ã ãæ¸ãããã¨ããã人ã§ããã°ãããããããã¾ããããpathè¦ç´ ã§ç·ãæãã¨ãã¯ããã³ãã®èãæ¹ãæ ¹åºã«ããã¾ãããã³ã¯ç¾å¨ã®åº§æ¨ã¨ããç¶æ
ãæã¡ã¾ããç¾å¨å°ç¹ããç®çå°ã¾ã§ã®çµè·¯ãã©ã®ããã«ç·ãå¼ãã®ããã¨ããã®ãã³ãã³ãã§æå®ãã¦ããã¾ãã便å©ã§ãããã
æ²ç·ãããã
path è¦ç´ ã® d å±æ§ã§ä½¿ããã¨ãã§ããã³ãã³ãã«ã¯ã以ä¸ã®ãããªãã®ãããã¾ãã
â»ããã§ã¯å¤§æåã®ã³ãã³ããç´¹ä»ãã¦ãã¾ãããããããã®ã³ãã³ãã«ã¯å°æåãã¼ã¸ã§ã³ããããããã¯ç¾å¨ã®ãã³ã®ä½ç½®ããã®ç¸å¯¾åº§æ¨ãæå®ãããã¨ã§æç»ããããã®ã«ãªãã¾ãã
- M : ç·ãå¼ããã«ãã³ãæå®ãã座æ¨ã®ã¨ããã¸ç§»åããã
- Z : éå§å°ç¹ã¾ã§ã®ç·åãå¼ãï¼éããé åãä½ãï¼
- L : æå®ãã座æ¨ã¾ã§ã®ç·åãå¼ã
- H : æå®ããx座æ¨ã¾ã§ã®æ°´å¹³ç·ãå¼ã
- V : æå®ããy座æ¨ã¾ã§ã®åç´ãªç·ãå¼ã
- C : 3次ã®ベジェ曲線ãå¼ã
- S : 3次ã®ãã¸ã§æ²ç·ãå¼ããã1åç®ã®å¶å¾¡ç¹ã®åº§æ¨ã¯ç´åã«å¼ãããã¸ã§æ²ç·ã®ãã®ã«å¿ããï¼æ¬å½ã¯ãã¡ãã¨ããå®ç¾©ãããã®ã§ã公式ドキュメントãã覧ãã ããï¼ã
- Q : 2次ã®ãã¸ã§æ²ç·ãå¼ã
- T : 2次ã®ãã¸ã§æ²ç·ãå¼ãããå¶å¾¡ç¹ã®åº§æ¨ã¯ç´åã«å¼ãããã¸ã§æ²ç·ã®ãã®ã«å¿ããã
- A : å弧ãæã
ç·åãæãã³ãã³ãã¯åç´æå¿«ã§ããã2種é¡ã®ãã¸ã§æ²ç·ãå¶å¾¡ç¹ãç·ã«ä¸ããå½±é¿ã®ãã¨ãç¥ã£ã¦ããã°æããã¨ãå¯è½ã§ãã注æããã®ã¯ç®çå°ã®åº§æ¨ãããå¶å¾¡ç¹ã®åº§æ¨ãå
ã«æ¸ãã¨ãããã¨ãããã§ãã
ä¸æ¹ã§ãå弧ã¯ããã¯è¡ãã¾ããã
å弧ãæã
å弧ãæãã¨ãã«ã©ã®ãããªãã©ã¡ã¼ã¿ãå¿ è¦ãªã®ãæãã¦ã¿ã¾ãããã
- rx : xæ¹åã®åå¾
- ry : yæ¹åã®åå¾
- x-axis-rotation : x軸ããã®å転è§ã0ã ã¨å転ããªãã
- large-arc-flag : é·ãæ¹ã®å弧ãæããªã1ãçãæ¹ãªã0ã
- sweep-flag : æè¨åãã«å弧ãæããªã1ãåæè¨åãã«ãããªã0ã
- x : ç®çå°ã®x座æ¨
- y : ç®çå°ã®y座æ¨
æãããããªã«ãããã¨ããææ³ãæ±ããæ¹ãå¤ããã¨ã§ãããã
large-arc-flag 㨠sweep-flag ã®è©³ç´°ã«ã¤ãã¦ã¯ãè¨èã§ããããè¦ããããå³ç¤ºããããã®ãè¦ãæ¹ããã£ã¨å¹çãè¯ããããªã®ã§ãå³ãè²¼ã£ã¦ããã¾ãã
origin : Paths – SVG 1.1 (Second Edition)
Copyright © 2011 W3C® (MIT, ERCIM, Keio), All Rights Reserved.
ä¸æ¹ãæ®æ®µç§ãã¡ãå弧ãæãã¨ãã¯ã次ã®ãããªãã®ãæå®ãããã¨ãèããã¨æãã¾ãã
- ä¸å¿ã®åº§æ¨
- x, y ããããã®æ¹åã®åå¾
- éå§è§åº¦ã¨çµäºè§åº¦
確ãã«ãã¡ãã®çµã¿åããã®æ¹ãå弧ãæãä¸ã§ä¾¿å©ããã«è¦ãã¾ãããåè¿°ã®éããpathè¦ç´ ã¯ãã³ã®æ¦å¿µã®ãã¨ã§æç»ãããä»çµã¿ã«ãªã£ã¦ãã¾ãã®ã§ãéå§åº§æ¨ã¯åãããæå®ããã¦ããã®ã¨ãçµç¹åº§æ¨ã¯ãºããªãã®å¤ãæ示çã«æå®ããæ¹ãå¾ç¶ã®ç·ãå¼ãä¸ã§æå©ãªã®ã§ããã ããã rx, ry, x-axis-rotation, ãªã©ã®æå®ãããæ¹ãè¯ãã®ã§ãã
ä¸éãèæ¯ãç解ããã¨ããã§ãpath è¦ç´ ã使ã£ã¦å弧ãæãã¦ã¿ã¾ãããï¼
ãã£ãæããªãï¼
æããªã人ã®å¤§å¤æ°ã¯ããã©ã¡ã¼ã¿ã®é çªãæè¨ã§ãã¦ãã¾ãããå度æ²è¼ãã¾ãã®ã§è¦ãã¦ãã ããï¼
- rx : xæ¹åã®åå¾
- ry : yæ¹åã®åå¾
- x-axis-rotation : x軸ããã®å転è§ã0ã ã¨å転ããªãã
- large-arc-flag : é·ãæ¹ã®å弧ãæããªã1ãçãæ¹ãªã0ã
- sweep-flag : æè¨åãã«å弧ãæããªã1ãåæè¨åãã«ãããªã0ã
- x : ç®çå°ã®x座æ¨
- y : ç®çå°ã®y座æ¨
ã¿ã¤ãã«ã¨ãã¦ããã¹ã¿ã¼ã»ãªãã»å弧ããæ²ãã¾ãããããã¹ã¿ã¼ããã«ã¯çµå±ã¯åç´ãªè¨æ¶ãå¿
è¦ã§ããã
ã§ããããããæå®ããããã¨ãã§ããã°ãå弧ãéãéçã¯ä¸æã«å®ã¾ããã¨ããã¤ã¡ã¼ã¸ãæ±ããã¨ãã§ããã®ã§ã¯ãªãã§ããããï¼
ãã¨ã¯ç·´ç¿ããã®ã¿ã§ããçãããããã¹ãã¨ãã£ã¿ã§å弧ã®SVGå³å½¢ãæãã人çãè±ãã«ãã¦ãã£ã¦ä¸ããã
ããã§ã¯SVGãã¡ã³ã®çæ§ããããå¹´ãï¼ï¼