rect পদ্ধতি

rect পদ্ধতি একটি নির্দিষ্ট বিন্দুতে একটি আয়তক্ষেত্র আঁকে। stroke বা fill পদ্ধতি প্রয়োগ করলেই এই আয়তক্ষেত্রটি দৃশ্যমান হবে। প্রথম ক্ষেত্রে কনট্যুরটি দেখা যাবে, এবং দ্বিতীয় ক্ষেত্রে - ভরাট আকারটি দেখা যাবে।

সিনট্যাক্স

javascriptcontext.rect(x, y, width, height)

উদাহরণ

চলুন rect ব্যবহার করে একটি কনট্যুর আঁকি:

html<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas>
javascriptlet canvas = document.querySelector('#canvas');
let ctx = canvas.getContext('2d');

ctx.rect(50, 50, 100, 75);
ctx.stroke();

Результат:

উদাহরণ

এবং এখন একটি ভরাট আকার আঁকুন:

html<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas>
javascriptlet canvas = document.querySelector('#canvas');
let ctx = canvas.getContext('2d');

ctx.rect(50, 50, 100, 75);
ctx.fill();

Результат:

আরও দেখুন

  • fillRect পদ্ধতি,
    যা একটি ভরাট আয়তক্ষেত্র আঁকে
  • strokeRect পদ্ধতি,
    যা একটি আয়তক্ষেত্রের কনট্যুর আঁকে