「JavaScript」fillText()でcanvasを設置する方法

書式
fillText(text, x, y [, maxWidth])
text:描画するテキストを指定
x:横方向の座標
y:縦方向の座標
使用例
htmlコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<canvas id="ct" width="300" height="100"></canvas>
<canvas id="ct" width="300" height="100"></canvas>
<canvas id="ct" width="300" height="100"></canvas>

JSコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
const cft = document.getElementById("ct");
const ctx = cft.getContext("2d");
//青色を設定
ctx.fillStyle = "rgb(0, 0, 255)";
ctx.fillRect (20, 20, 50, 50);
const cft = document.getElementById("ct"); const ctx = cft.getContext("2d"); //青色を設定 ctx.fillStyle = "rgb(0, 0, 255)"; ctx.fillRect (20, 20, 50, 50);
const cft = document.getElementById("ct");
const ctx = cft.getContext("2d");

//青色を設定
ctx.fillStyle = "rgb(0, 0, 255)";
ctx.fillRect (20, 20, 50, 50);

 

JavaScript

Posted by arkgame