diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/ja/web/api/canvasrenderingcontext2d/scale | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/ja/web/api/canvasrenderingcontext2d/scale')
-rw-r--r-- | files/ja/web/api/canvasrenderingcontext2d/scale/index.html | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/files/ja/web/api/canvasrenderingcontext2d/scale/index.html b/files/ja/web/api/canvasrenderingcontext2d/scale/index.html new file mode 100644 index 0000000000..9bd57b8ca2 --- /dev/null +++ b/files/ja/web/api/canvasrenderingcontext2d/scale/index.html @@ -0,0 +1,124 @@ +--- +title: CanvasRenderingContext2D.scale() +slug: Web/API/CanvasRenderingContext2D/scale +tags: + - API + - Canvas + - CanvasRenderingContext2D + - Method + - Reference +translation_of: Web/API/CanvasRenderingContext2D/scale +--- +<div>{{APIRef}}</div> + +<p>Canvas 2D APIの<code><strong>CanvasRenderingContext2D</strong></code><strong><code>.scale()</code></strong>メソッドは、キャンバス上の長さを縦方向及び横方向に拡縮する変形を適用させます。</p> + +<p>By default, one unit on the canvas is exactly one pixel. A scaling transformation modifies this behavior. For instance, a scaling factor of 0.5 results in a unit size of 0.5 pixels; shapes are thus drawn at half the normal size. Similarly, a scaling factor of 2.0 increases the unit size so that one unit becomes two pixels; shapes are thus drawn at twice the normal size.</p> + +<h2 id="構文">構文</h2> + +<pre class="syntaxbox notranslate">void <em>ctx</em>.scale(<em>x</em>, <em>y</em>); +</pre> + +<h3 id="引数">引数</h3> + +<dl> + <dt><code>x</code></dt> + <dd>水平方向の拡縮係数。負の値を指定すると、縦軸を跨いでピクセルを反転させます。<code>1</code> を指定すると、水平方向には拡縮されません。</dd> + <dt><code>y</code></dt> + <dd>垂直方向の拡縮係数。負の値を指定すると、横軸を跨いでピクセルを反転させます。<code>1</code> を指定すると、垂直方向には拡縮されません。</dd> +</dl> + +<h2 id="例">例</h2> + +<h3 id="図形を拡縮する">図形を拡縮する</h3> + +<p>この例は、拡縮された長方形を描きます。比較のため、元の長方形も描かれます。</p> + +<h4 id="HTML">HTML</h4> + +<pre class="brush: html notranslate"><canvas id="canvas"></canvas> +</pre> + +<h4 id="JavaScript">JavaScript</h4> + +<p>The rectangle has a specified width of 8 and a height of 20. The transformation matrix scales it by 9x horizontally and by 3x vertically. 結果的に、幅は72、高さは60になります。</p> + +<p>キャンバス上の位置が変わることに注意してください。角の位置の指定値が(10, 10)のため、実際の角の位置は(90, 30)になります。</p> + +<pre class="brush: js; highlight:[5] notranslate">const canvas = document.getElementById('canvas'); +const ctx = canvas.getContext('2d'); + +// 拡縮された長方形 +ctx.scale(9, 3); +ctx.fillStyle = 'red'; +ctx.fillRect(10, 10, 8, 20); + +// 変形行列を単位行列に戻す +ctx.setTransform(1, 0, 0, 1, 0, 0); + +// 原型の長方形 +ctx.fillStyle = 'gray'; +ctx.fillRect(10, 10, 8, 20); +</pre> + +<h4 id="結果">結果</h4> + +<p>拡縮された<span style="color: red;">長方形は赤</span>、<span style="color: gray;">元の長方形は灰色です</span>。</p> + +<p>{{ EmbedLiveSample('図形を拡縮する', 700, 180) }}</p> + +<h3 id="垂直・水平方向の反転">垂直・水平方向の反転</h3> + +<p>You can use <code>scale(-1, 1)</code> to flip the context horizontally and <code>scale(1, -1)</code> to flip it vertically. In this example, the words "Hello world!" are flipped horizontally.</p> + +<p>Note that the call to {{domxref("CanvasRenderingContext2D.fillText()", "fillText()")}} specifies a negative x coordinate. This is to adjust for the negative scaling factor: <code>-280 * -1</code> becomes <code>280</code>, and text is drawn leftwards from that point.</p> + +<h4 id="HTML_2">HTML</h4> + +<pre class="brush: html notranslate"><canvas id="canvas"></canvas> +</pre> + +<h4 id="JavaScript_2">JavaScript</h4> + +<pre class="brush: js; highlight:[4] notranslate">const canvas = document.getElementById('canvas'); +const ctx = canvas.getContext('2d'); + +ctx.scale(-1, 1); +ctx.font = '48px serif'; +ctx.fillText('Hello world!', -280, 90); +ctx.setTransform(1, 0, 0, 1, 0, 0); +</pre> + +<h4 id="結果_2">結果</h4> + +<p>{{ EmbedLiveSample('垂直・水平方向の反転', 700, 180) }}</p> + +<h2 id="仕様">仕様</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">仕様</th> + <th scope="col">状況</th> + <th scope="col">コメント</th> + </tr> + <tr> + <td>{{SpecName('HTML WHATWG', "scripting.html#dom-context-2d-scale", "CanvasRenderingContext2D.scale")}}</td> + <td>{{Spec2('HTML WHATWG')}}</td> + <td></td> + </tr> + </tbody> +</table> + +<h2 id="ブラウザの互換性">ブラウザの互換性</h2> + + + +<p>{{Compat("api.CanvasRenderingContext2D.scale")}}</p> + +<h2 id="参考">参考</h2> + +<ul> + <li>このメソッドを定義するインターフェイス: {{domxref("CanvasRenderingContext2D")}}</li> +</ul> |