FabricJsキャンバス内にグリッド/アレイ(p * p)のボタンを描画しようとしています。私は希望のグリッド/アレイを作成することができます。FabricJs:FabricJsキャンバスにボタンのグリッド/アレイ(p * p)を描画します
しかし、同じ高さと幅のブロック内にボタンを描く/配置することはできません。
HTML:
<div>
<canvas id="canvas" width="500" height="500" style="border:1px solid #000000</canvas>
</div>
<button onclick="drawGrid()">Create Grid</button>
スクリプト:
var canvas = new fabric.Canvas('canvas');
var currentCanvasWidth = canvas.width;
var currentcanvasHeight = canvas.height;
var context = canvas.getContext("2d");
var gridSize = 50; //decides the value of p(p = currentCanvasWidth/gridSize)) and the height and width of each block inside the p*p array
function drawGrid(){
// Drawing vertical lines
var x;
for (x = 0; x <= currentCanvasWidth; x += gridSize) {
context.moveTo(x + 0.5, 0);
context.lineTo(x + 0.5, currentcanvasHeight);
}
// Drawing horizontal lines
var y;
for (y = 0; y <= currentcanvasHeight; y += gridSize) {
context.moveTo(0, y + 0.5);
context.lineTo(currentCanvasWidth, y + 0.5);
}
gridSize = gridSize;
context.strokeStyle = "black";
context.stroke();
}
また、私はグリッド/アレイブロック内のボタンを作成するためのHTMLキャンバスのコンテキストまたはFabricJsには何も見つかっていません。
このアプローチの方向性はありますか? FabricJs Canvas内にボタンの配列を作成するための他の方法があります。
ここは私のキャンバスのImageです。基本的には、TIC-TAC-TOE gridのようなボタンの配列を作成し、後でボタンをさまざまな色で塗りつぶして自分のシーンを表現したいと考えています。
作成したい画像の例を表示できますか? –
私はいくつかの画像を追加して私の質問を編集し、より明確にしました。 –