HTML5 Canvasã®ãã©ã¦ã¶ã«ãã£ã¦ç°ãªãå¾®å¦ãªæ¯ãèãã«ã¤ãã¦ã¾ã¨ãã¦ã¿ãã
ã¯ããã«
Canvasã¯HTML5ã¨ã¯åãé¢ãããç¬ç«ããä»æ§(HTML Canvas 2D Context)ã«ãªã£ã¦ããããã§ãããç¾ç¶ã®ãã©ã¦ã¶ä¸ã§ã®Canvasã®ã«ã¤ãã¦ãæ®æ®µã¯ãã¾ãæ°ã«ããªãå¾®å¦ãªæ¯ãèãã«ã¤ãã¦èª¿ã¹ãçµæãã¾ã¨ãã¦ã¿ã¾ããã
調ã¹ããã©ã¦ã¶ã®åãã¼ã¸ã§ã³ã¯ä»¥ä¸ã®éãã§ãã
Firefox | Chrome | Safari | Opera |
---|---|---|---|
3.6.8 | 6.0.490.1 dev | 5.0.1 | 10.61 |
ç·ãæã (lineTo)
ãã ã®ç´ç·ãæãã ãã®lineToã§ããããã®åç´ãªãã®ã«ããæãããå¤ãã®äººãæ®æ®µã¯æ°ã«ããªããããªåé¡ãããã¾ããããã¯åº§æ¨å¤ã¨ã¢ã³ãã¨ãªã¢ã¹ã§ãã詳ããè¦ãåã«ãå®éã®çµæã示ãã¾ããããä¸è¨ã®ã¤ã¡ã¼ã¸ä¸ã«æããã¦ããç·ã¯ãããããç·å¹ (lineWidth)ã1ã®ç·ã§ãã
ã©ã®ãã©ã¦ã¶ã§ãåãããã«æç»ããã¦ããããã§ãããããè¦ãã¨ãéã®45度ã®æãç·ãChromeã¨ãã以å¤ã§ã¯ç°ãªãã¾ããå°ããã¦ãããã«ããã®ã§ã10åã«æ¡å¤§ãã¦è¦ã¦ã¿ã¾ãããããã®æ¡å¤§ãcanvas(ã¤ã¡ã¼ã¸ã®ãã£ããã£*1 )ã使ã£ã¦ãã¾ããä¸å³ã§ãå·¦ãChrome以å¤ã§ãå³ãChromeã§ããéã®æãç·ã¯Chrome以å¤ã§ã¯ã¢ã³ãã¨ãªã¢ã¹ããã¦ãã¾ãããChromeã§ã¯ããã¦ãã¾ããã
ãããã«é¢ç½ããã¨ã«ããããã®ç·ã¯ããããç·å¹ ãï¼ã§ããã«ãé¢ããããè²ãèãã¦å¤ªãè¦ããã¨ãããã¨ã§ããç¹ã«ãä¸ç«¯ã®æ°´å¹³ç·ã®èµ¤ã¨å·¦ç«¯ã®åç´ç·ã®ç·ã¯ã©ã¡ãã(2, 2)ã®åº§æ¨ããå³æ¹åã¨ä¸æ¹åã«ä¼¸ã°ãã¦ããç´ç·ã§åº§æ¨å¤ã¯æ´æ°å¤ã§ããã©ããã¦ï¼ãã¯ã»ã«åã®å¹ ã«ãªã£ã¦ãããã¨ããã¨ãCanvs2Dã®åº§æ¨å¤ã¯ãã¯ã»ã«ããã¼ã¹ã«ãã¦ããã®ã§ã¯ãªããããã¾ã§æ°å¦çãªæå³ã§ã®ãã®ã ããã§ãã
ã¤ã¾ããåç¹(0, 0)ã¯canvasã®å·¦ä¸ã§ãããå·¦ä¸ã®ãã¯ã»ã«(ã®ä¸å¤®)ãåç¹ã§ã¯ãªããå·¦ä¸ã®ãã¯ã»ã«ã®å·¦ä¸ã®é ãåç¹ã«ãªãã¾ãããªã®ã§ãæ´æ°ã§è¡¨ããã座æ¨å¤ã¯ããã¯ã»ã«ã¨ãã¯ã»ã«ã®ã¡ããã©å¢çã«ãªããããå¹ ï¼ã§ãã£ã¦ã2ãã¯ã»ã«åã«è·¨ã£ã¦æç»ããããã¨ã«ãªãã¾ãã±0.5ã·ãããã¦ãã¯ã»ã«ã®ä¸å¤®ã«ãªãããã«åº§æ¨ãæå®ããã°æ°´å¹³ã»åç´ã®ç·ã¯ï¼ãã¯ã»ã«åã ãã®å¹ ã«ãªãã¾ãã
ä¸ã®å³ã§ã4æ¬ã®èµ¤ã®åç´ç·ã®Y座æ¨ã¯å·¦ãããããã15.0, 18.3, 20.5, 22.7 ã«ãªã£ã¦ãã¾ããã20.5ã®å ´åã¡ããã©ãã¯ã»ã«å¹ ãï¼ã«ãªã£ã¦ãããã¨ããããã¾ãã
ç´°ãç·ãæã (lineWidth)
ç·ã®å¹ ã¯GraphicsContext2Dãªãã¸ã§ã¯ãã®lineWidthããããã£æå®ãã¦ããã®åã¯float(JavaScriptã§ã¯Numberã«ãããã³ã°)ãªã®ã§ãå¹ ã2.5ã®ç·ã1ããç´°ãç·ãªã©ã表ç¾å¯è½ã¨ãããã¨ã«ãªãã¾ãã
å ã»ã©ã®æç»ããç·ã®å¹ ã0.5ã«è¨å®ããã¨ãã®çµæã以ä¸ã«ç¤ºãã¾ãã
åç´ã®èµ¤ã®ç·ã«æ³¨ç®ãã¦ãã ãããY座æ¨å¤ããããã15.0, 18.3, 20.5, 22.7ã®åç´ç·ã§ãããç·å¹ ã1ã®ã¨ãã¯2ãã¯ã»ã«ã«è·¨ããã太ããªãçµæã«ãªãã¾ããããç·å¹ ã0.5ã®ã¨ãã¯15.0ã®ç·ä»¥å¤ã¯1ãã¯ã»ã«å ã«åã¾ãå¹ ã§ãã確ãã«ãChrome以å¤ã¯1ãã¯ã»ã«å¹ ã®ç·ã¨ãã¦æç»ããã¦ãã¾ããChromeã®å ´åã¯ãå¹ ã1ã®ã¨ãã¨åãã¾ã¾å ¨ä½çã«ã¢ã«ãã¡ãããã£ãããã«ãªã£ã¦ãã¾ãããã®ãããï¼ããç´°ãç·ãChromeã§ã¯å¯ã¼ããæãã«ãªããã¨ãããã¾ãã
ãã¦ãï¼ããç´°ãç·ã¯ã¢ã«ãã¡å¤ãå°ãããã¦éæ度ãä¸ãã¦æç»ããã¦ãã¾ãããããã¯å®è£ ä¸ã®åä½ã§ãããcanvasã®ä»æ§ã§ã¯ãã®ãããªãã¨ã¯è¦å®ããã¦ãã¾ãããäºå®ä¸ãã¢ã«ãã¡å¤ã¯0ã255ã®1ãã¤ãã§å®è£ ãããã®ã§ãç·å¹ ã¨ã¢ã«ãã¡å¤ãç·å½¢é¢ä¿ã«ãªã£ã¦ããã¨ä»®å®ããã¨ãç·å¹ ã1/255ããç´°ãç·ã¯ã¢ã«ãã¡å¤ã0以ä¸ã«ãªãå®å ¨éæãªã®ã§æç»ãããªãã¨ãããã¨ã«ãªãã¾ãã
å®éã«ç¢ºèªãã¦ã¿ã¾ããããã¨ãã£ã¦ããèãç´°ãç·ãï¼æ¬æãã¦ãããç®ã§è¦ã¦ãåããã¾ãããã¤ã¡ã¼ã¸ããã£ããã£ãã¦ãã¼ã¿ã調ã¹ãã°åããã¾ãããããã§ã¯å¥ã®æ¹æ³ãã¨ãã¾ããã¤ã¾ããç·å¹
ã®ééã§å¹³è¡ãªç·ã§ã³ã£ããã¨åãã¦ã©ããªãããè¦ã¦ã¿ã¾ããå·¦å³ã¯å¹
ï¼ã®ç·ã赤ã¨éã交äºã«ï¼ã¥ã¤ããããªããæãããã®ã§ãããã®ç·ã®å¹
ãå°ãããã¦ã©ããªããã確èªãã¾ãããç·å¹
ãå°ãããªãã¨èµ¤ã¨éãæ··ããåã£ã¦ç´«ã«ãªãã¾ãããããã«å°ããããã¨çªç¶æç»ãããªããªãå ´åãããã¾ãã
çµæã以ä¸ã«ç¤ºãã¾ãã
Firefox | Chrome | Safari | Opera |
---|---|---|---|
1/256 | 1/128 | 1/255 | â |
Firefoxã¯1/256ãå¢çã¨ãã¦æç»ãããªããªãã¾ããChromeã¯1/128ã®ããã§ããSafariã¯å ¨ä½çã«ã¢ã«ãã¡ãä¸ãã£ã¦æ確ãªå¢çã¯è¦ã¤ãããã¾ããã§ãããOparaã¯1/51200ãã¦ãæç»ããã¾ããã
å·¦å³ã¯ç·å¹
ã1/64ã®ã¨ãã®Chromeã®çµæã§ããæ ¼åç¶ã®ãã¿ã³ã表示ããã¦ãã¾ãããããã¯canvasã®èæ¯ã«ã»ããããã¤ã¡ã¼ã¸ã§ããChromeã®å ´åãç´°ãç·ã®ã¢ã«ãã¡ã®ããæ¹ãä»ã¨ç°ãªããä¸æ¸ã(copy)æ¹å¼ã®ãããªãã®ã«ãªã£ã¦ããããã§ãã
ããã¾ã§ã®åä½ã以éã®é ç®ã§ç»å ´ããããã¤ãã¯ä¸è¨ã®ãªã³ã¯ããå®éã®åä½ã確èªã§ãã¾ãã
ç©å½¢ã¨ãã®å¡ãã¤ã¶ã (rect, fill)
ç©å½¢ãç°¡åã«æç»ããrect()ã¨ããAPIãããã¾ãã
The rect(x, y, w, h) method must create a new subpath containing just the four points (x, y), (x+w, y), (x+w, y+h), (x, y+h), with those four points connected by straight lines, and must then mark the subpath as closed. It must then create a new subpath with the point (x, y) as the only point in the subpath.
ç©å½¢ãæãã¦ãã®å¾ãæ°ãããã¹ãçæãã¦ä½ç½®ã(x,y)ã«ã»ãããããã¨ããã¾ããããã®è§£éã®éãããã©ã¦ã¶ã§ç¾ãã¦ãã¾ããwã¨hã¯æ£æ°ã§ãªããã°ãããªãã¨ã¯æ¸ããã¦ããªãã®ã§ãè² æ°ã§ãããã¨èãããã¾ãããã®ã¨ã(x,y)ã¯ç©å½¢ã®å·¦ä¸ã¨ã¯ç°ãªãä»ã®ç¹ã«ãªãã¾ãããChromeã¨Safariã§ã¯(x,y)ãå¿ ãå·¦ä¸ã«ãªãããã«èª¿æ´ãã¦ããã¨æãããçµæã«ãªã£ã¦ãã¾ãã
ããã«ãä»æ§ããã¯ç©å½¢ãæãç·åã®æ¹åãèªã¿åãã¾ãããwã¨hãæ£ã¾ãã¯è² ã«è¨å®ãããããã¨ã§ãæè¨åããåæè¨åãã®ç©å½¢ãæç»ãããã¨ãã§ãã¾ããããããChromeã¨Safariã§ã¯é ç¹ã®å¤ã調æ´ããã¦ãã¾ããããã常ã«æè¨åãã§æç»ãããããã§ãã
ä¸æ¹ãOperaã§ã¯w, hã«è² ã®æ°ãæå®ããã¨INDEX_SIZE_ERRä¾å¤ãæãããã¾ãã
以ä¸ã®çµæã«ãã®éãããããã¾ãã
å®éã®åä½ã¯ä»¥ä¸ã§ç¢ºèªã§ãã¾ãã
ãªããç©å½¢é åã®å¡ãã¤ã¶ãã¯ãç·å¹
ãã¼ãã®ç·ã§å²ã¾ããå
å´ãå¡ãã¤ã¶ããã¨ã§ãããã座æ¨å¤ãã¡ããã©æ´æ°ã®ã¨ãã«ã¢ã³ãã¨ãªã¢ã¹ããããã¨ãªãåãã¯ã»ã«ãããã¿ãªæç»ããã¾ããå·¦å³ã¯ã5x5ã®å¤§ããã®ç©å½¢ãå·¦ä¸åº§æ¨ãå¤ãã¦æç»ãããã®ã§ããã¢ã³ãã¨ãªã¢ã¹ããã¦ããã®ã¯ã座æ¨ã0.5ã®ç«¯æ°ã§ãããã®ã§ãã
ã¾ããfill()ã«ããå¡ãã¤ã¶ãã®winding ruleã¯non-zeroã®ã¿ããµãã¼ãããã¦ãã¾ãã
The fill() method must fill all the subpaths of the current path, using fillStyle, and using the non-zero winding number rule.
å½±ãæã (shadow)
Canvas2D APIã¯2Dãªã®ã«å½±ãæç»ããã¨ããæ©è½ãããã¾ããå©ç¨ã·ã¼ã³ãå¤ãããç¹å¥ã«ç¨æãããæ©è½ã®ããã«æããã¾ãããã¡ãã£ã¨éåæãããã¾ãã
å½±ã«ã¯ã¼ããå¹æ(blur)ãæå®ã§ãã¾ãããå³å½¢ãã¤ã¡ã¼ã¸èªä½ã«blurãé©ç¨ã§ããªãã®ã¯ãã¡ãã£ã¨æ®å¿µã§ãã
ãã®å½±ã®æç»ã¯Chromeãã¡ãã¨å¤ãªå®è£ ã«ãªã£ã¦ãã¾ããChromeã§ã¯ä»¥ä¸ã®ãããªåé¡ããã¾ãã
- å³å½¢ãrotate()ã§å転ããã¨å½±ã®ä½ç½®èªä½ãå転ãã¦ãã¾ãã
- å³å½¢ã«ã¢ã«ãã¡ãä»ãã¦èããã¦ããå½±ãèããªããªã
- å³å½¢ã«ã°ã©ãã¼ã·ã§ã³ãã¤ããã¨ãå½±ã«ãã°ã©ãã¼ã·ã§ã³ãã¤ãã¦ãã¾ã
- ã¤ã¡ã¼ã¸ã«å½±ãã¤ããªã
ä¸æ¹ãSafariã§ã¯å³å½¢ã«ã°ã©ãã¼ã·ã§ã³ãä»ããã¨ãå½±ãã¤ããªãã¨ããåé¡ãããã¾ãã
å®éã®åä½ã¯ä¸è¨ã§ç¢ºèªã§ãã¾ãã
ã¯ãªããå¢çã®ã¢ã³ãã¨ãªã¢ã¹ (clip)
Chromeã§ã¯ãclipã§ããæããå³å½¢ã®å¢çãã¢ã³ãã¨ãªã¢ã¹ãããªãã¨ããçç¶ãããã¾ãã
ç´ç·ã«æ¥ãã弧ãæã (arcTo)
arcToã®å¦ã«ã¤ãã¦ã¯ä¸è¨ã®éå»ã®ã¨ã³ããªã¼ã§åãä¸ãã¾ããã
Operaã«å¤åããã£ãããã§ãããç¸å¤ãããæ¿ããå¤ã§ãã以åã®Operaã¯å·¦ã®ãããªæç»ããã¦ãã¾ããããä»ã¯å³ã®ãããªãã®ã«ãªã£ã¦ãã¾ããå°ãã¯é¡ããããªã£ãã®ã§ããããï¼
Composite
globalCompositeOperationã¯Porter-Duffã®æ¹æ³ã§åæããã¾ããããã©ã¦ã¶ã«ãã£ã¦å¾®å¦ã«çµæãç°ãªãã¾ãããªããcanvasä»æ§ã§ã¯lighterã¨ããããããã£ã¯å®ç¾©ããã¦ãã¦ããdarkerã¨ããããããã£ã¯å®ç¾©ããã¦ãã¾ããããSafariã¨Chromeã§ã¯å®è£ ããã¦ããããã§ãã
Firefoxã®çµæã以ä¸ã«ç¤ºãã¾ãã
ä¸ã¯Operaã®çµæã§ããcopyã¨darker以å¤ã¯Firefoxã¨åãã§ãã
ä¸ã¯Safariã¨Chromeã®çµæã§ãã両è
ã¯åãã§ããFirefox/Operaã¨æ¯ã¹ã¦å¤§ããªéããããã®ããããã¾ãã
Firefoxç³»ã¨Chromeç³»ã®ã©ã¡ããæ£ãããã¯ãPorter-Duffãã©ãå®ç¾©ããã¦ãããã調ã¹ãã°ããããã§ããWikipediaã®å³å ¥ã説æãåãããããã§ãããã
ãããè¦ãã¨ãã©ãããFirefox/Operaãæ£ãããChrome/Safariã¯ééã£ã¦ããããã§ãã
Porterã¨Duffã«ãããªãªã¸ãã«ã®è«æã¯ä¸è¨ããèªããã¨ãã§ãã¾ãã
- http://www.keithp.com/~keithp/porterduff/
Computer Graphics Volume 18, Number 3 July 1984 pp 253-259
ã¡ãªã¿ã«ãä¸è¨ã®ãã¼ã¸ãæ«ãåã«ãã¯ã¦ããããããä»ããããããã§ããããã©ã¦ã¶ã§å®è¡ããçµæã表示ãã¦ããããããã©ã¦ã¶ã«ããã«çµæãç°ãªããã¨ã«æ³¨æãå¿ è¦ã§ãã
å®éã®åä½ã¯ä»¥ä¸ãã確èªãã¦ã¿ã¦ãã ããã
360度以ä¸ã®arc
arcã¯startAngleããendAngleã¾ã§ã®åå¨ä¸ã®å¼§ãæç»ãããã®ã§ããããã®è§åº¦ã360度以ä¸ã®ã¨ãã©ããªããã¯ãä»æ§ã§ã¯ä»¥ä¸ã®ããã«æè¨ããã¦ãã¾ãã
If the anticlockwise argument is false and endAngle-startAngle is equal to or greater than 2Ï, or, if the anticlockwise argument is true and startAngle-endAngle is equal to or greater than 2Ï, then the arc is the whole circumference of this circle.
ã¤ã¾ãã360度以ä¸ã®arcã¯ä¸å¨å ¨é¨ãæç»ããå¿ è¦ãããã¾ããChrome以å¤ã§ã¯æ£ãããªãããã§ããfill()ããã¨ãã®çµæãç°ãªãã¾ãã
å®éã®åä½ã¯ä»¥ä¸ãã確èªã§ãã¾ãã
ã°ã©ãã¼ã·ã§ã³
ãã°ããåã¾ã§ã¯ãChromeã®RadialGradientãé ·ãç¶æ ã§ããããç¾å¨ã¯åé¡ã¯ç¡ããªã£ã¦ãã¾ãã
ããã¹ã (fillText, strokeText)
textBaselineããããã£ã§åç´ä½ç½®ã®ãã¼ã¹ã©ã¤ã³ãæå®ã§ãã¾ãããFirefoxã¯hangingãæ£ããããã¾ãããalphabeticãæå®ããã¨ãã¨åããªã®ã§ãå®è£ ããã¦ããªãã®ããããã¾ããã
ã¾ããfillText()ã§Safariã¨Operaã¯ã¢ã³ãã¨ãªã¢ã¹ããã¾ãããFirefoxã¨Chromeã¯ããã¾ãããstrokeText()ã§ã¯å ¨é¨ã®ãã©ã¦ã¶ãã¢ã³ãã¨ãªã¢ã¹ããã¦ãã¾ããã
ãããã«
ãã©ã¦ã¶æ¯ã«ç°ãªãcanvasã®ç´°ããåä½ã«ã¤ãã¦ã¾ã¨ãã¦ã¿ã¾ãããcanvasä»æ§ã¯ã¾ã ãã©ãããªã®ã§ä»ã®æ®µéã§100%æºæ ã¯æå¾ ã§ããªãã¨ãã¦ãããã©ã¦ã¶éã§ã®åä½ã®éãã¯è§£æ¶ãã¦æ¬²ãããã®ã§ãã
åä½ã確èªããã½ã¼ã¹ã³ã¼ãã®èª¬æã¯ä¸åçç¥ãã¾ããããæ®´ãæ¸ãã³ã¼ãã§ããèå³ããæ¹ã¯ä¸èº«ãè¦ãã¦ã¿ã¦ãã ããã