λã > ܛ̳ > ̳ > canvasF(xin)քLƾ

canvasF(xin)քLƾ

Դ|rg2024-08-15 09:46:09 |x140| (bio) a VA v S C |

_ mȻڌH_l(f)҂ȥL̈D Ҫ҂Ҳͨ^3ȥF(xin) ҂ΌF(xin)̈DкСһ քLƾ Lһε˼· ҂@Lƾ ʹõcanvas.strokeRect(x,y, w, h)Lһ߅ x:c x S(bio) y:

_

mȻڌH_l(f)҂ȥL̈D
Ҫ҂Ҳͨ^3ȥF(xin)
҂ΌF(xin)̈DкСһ
քLƾ

Lһε˼·

҂@Lƾ
ʹõcanvas.strokeRect(x,y, w, h)Lһ߅
x:c x S(bio)
y:c y S(bio)
width:εČȡֵ߅ؓ(f)ֵ߅
height:εĸ߶ֵ½ؓ(f)ֵ
עһw,h@ɂ(sh)ֱؓ(f)ֵ
w,hؓ(f)(sh)F(xin)2бQľ

canvasF(xin)քLƾ

LһoB(ti)




  
  
  Document
  


  



canvasF(xin)քLƾ

KӞK�Kƾ�KIĻ�K�˼·

ͨK�K�K�K�K�K�K˾�B(ti)K�Kƾ�KI�
K�K�K�K�KҪ�ֶK�Kһ�K�K�K?K�ҪK�K�Kq|K�K�K�
1.K�canvasעK�K�_(d)K�K?K(ji)ͿKq�rK�Kq|K�εK�Kg|K�K?x,y)
K�Kͬʱ�K�K�KҪ�xK�Kgע�K�K�KӞKq|K�̧K�Kq|K�
2.K�K�K�ؚK�Kg�Kͨ�K�K�KC�K�KIĿ�K͸ߡ�
K�K�K�εĿK�Ⱥ͸߶Kg�K�K�KҪʹ�VK�Kֵ�K�мK�?
K�K�K�K�K�K�{K�K?
3.K�K�Ķ�Kg�K�ƳK֮ǰע�K�K�K�ؚK�K�Ķ�K�K?

KӞK�Kƾ�K�


canvasF(xin)քLƾ
canvasF(xin)քLƾ

K�K�K�K�K�ֶK�K�·K�

ͨK�K�K�K�K�DƬK�K�K�K�ȻK�K�KӞK�KƻIK˾�KI�
K�KǻIK�K�Kظ�K�·K�K�
K�K�KPK�һKqIK�Kظ�·K�K�ԭK�
K�K�K�ÿK�KӞKe�K�KУ�K�K�K�{K�ΡK?
ֻҪK�K�K(ji)�K�ǰK�K�վK�K�DzK�NͿK�ԽK�K�K�K�K?
K�K�K�K�K�һK�

K(ji)�֮ǰK�K�K�K�·K�

function drawRect(x1,y1,x2,y2){
  // K(ji)|K�K�εĿK�Kg�K�K�K�KҪʹ�VK�Kֵ�K�K�мK�K?  // K�rK˿�KӞK�K�K�K�K�K�Kq�K�K�K�NK�εĿK�͸K?  let rectWidth = Math.abs(x2-x1)
  let rectHeight = Math.abs(y2-y1)
  // K惦K�KI�K�K�K�Ϣ
  rectArr = [x1,y1,rectWidth,rectHeight]
  // K(ji)�Kƾ�K�ǰK�K�Kǽ�K�K�K�գK�K�՟K�ƣK�ͲK�K�KӞK�KqPK�K?  ctx.clearRect(0,0,  canvasEle.width, canvasEle.height)
  // K�Kq�Kƾ�K�
  ctx.strokeRect(...rectArr)
}

canvasF(xin)քLƾ

K�Kǵ�СK�΢�K�K�K�ˣK?

K�ЩK�Kǵ�СK�΢�K?
K�K�K�Kg|K�K�K�K?Kյ�K�K�K^ǡ�
K�:KC�K�(900, 1000)K^ӞK�(50, 50)K�K�K�K?
K�K�K�K�KePK�K�{K�ΣK�DzK�ǻK�K�K�K�Kأ�
_K�K�K�K�?
K�rK�KƵľ�KIԌK�K�K�K�KǵPK�K�xK�ơK�_(d)K�K�D
K�δK�K�K�K�K�Kأ�
canvasF(xin)քLƾ

K�K�K�K�KǻI canvas.rect

canvas.rect(x,y,w,h)KCPK�K�K�һK�K�K�·K�
x:K�K�K�K� x K�K�K
y:K�K�K�K� y K�K�K
width:K�KIĿ�K�K�ֵK�K߅�K�ֵK�K�ߡK?
height:K�KIĸ߶ȡ�K�ֵKq�K�K�ֵK�K�K�
K�K�K�K�lK�Kһ�K�K�KqPK�K�K�K�KqPK�K�K�Kֱ�xK�K�՟K�K�ϡK?
K�ҪK�K�stroke()K�fill()K�K�K�ʾK(ji)�K�K^�

ʹK�canvas.rect K�Kƾ�K�·K�

function drawRect(x1,y1,x2,y2){
  let rectWidth = Math.abs(x2-x1)
  let rectHeight = Math.abs(y2-y1)
  // K�K�֮ǰK�K�K֮ǰʵʱ�ؚK�K�K�K�Ke�K�·K�
  ctx.clearRect(0,0,  canvasEle.width, canvasEle.height)
  // K�ʼK�K�
  ctx.beginPath();  
  // K�K�·K�K�K�
  ctx.rect(Math.min(x1, x2), Math.min(y1, y2), rectWidth, rectHeight);  
  // K�K�K�K�K�K�K�
  ctx.stroke(); 
}

canvasF(xin)քLƾ

canvas.strokeRectK�canvas.rectK�K�ͬ

K�K�1K�K�K�: canvas.strokeRect:K�KƵ�K߅�canvas.rectK�K�K�KI�·K�(K�K�K�K�K�K�K(ji)�K�K�)
K�K�2K�rK�: canvas.strokeRectK�K�K�K�Kơ�canvas.rectK�K�K�K�K�Kƣ�K�ҪK�K�stroke()K�fill()K�Kܻ�K�
K�ͬK㣺
1.K�Kǻ�Kƾ�K�
2.K�KܵԌK�K�ͬ
3.K�K�ͨK�strokeStyle(K�ɫ)K�lineWidth(Kߵ_(d)(x))K�K�K�K�K�ʽ

K�K�K�KӞK�K�K?

function drawRect(x1,y1,x2,y2){
  let rectWidth = Math.abs(x2-x1)
  let rectHeight = Math.abs(y2-y1)
  let endX = Math.min(x1, x2)
  let endY = Math.min(y1, y2)
  // K�K�֮ǰK�K�K֮ǰʵʱ�ؚK�K�K�K�Ke�K�·K�
  ctx.clearRect(0,0,  canvasEle.width, canvasEle.height)
  // K�K�֮ǰK�ЩK惦K� beforeRectArr K�K�Kеľ�K�
  allRectInfoArr = [endX, endY, rectWidth, rectHeight]
  ctx.clearRect(0,0,  canvasEle.width, canvasEle.height)
  beforeRectArr.forEach(element => {
    ctx.beginPath(); 
    ctx.strokeRect(...element)
    ctx.stroke();
  });
  
  // K�ʼK�K�·K�
  ctx.beginPath(); 
  // K�KƱ�KIľ�K�·K�
  ctx.rect(...allRectInfoArr); 
  // K�ʼK�K�K�
  ctx.stroke(); 
}
// K�K�K�K�Ķ�K�rK�ҪKƻI֮ǰעK�KӞKq|K�̧K�Kq|
function canvasMouseUpHandler(){
  savaBeforeRect()
  canvasEle.removeEventListener('mousemove', canvasMoveHandler)
  canvasEle.removeEventListener('mouseup', canvasMouseUpHandler)
}
function savaBeforeRect(){
  beforeRectArr.push(allRectInfoArr)
}

canvasF(xin)քLƾ

ȫK�K�K�




  
  
  Document
  


  



βK�

K�KС�K�K�K�K_(d)IJK�K�ĻK?
K�KԸ�Kҵ�K�K�wKл�ˡK?
K�K�K�K�:
K�Kѡ�оK�ΣK�K�ľK�δKС�K?
K�K�aK�K�K�K�K�K�K?
K�λK�KԌK�KPK�ZK?

СK�K|KeӞ

K�K�K�K�K�K�Ke�K�K�K�ϢK�K�K�K�K�K�K�K�ͬK�K^�K֤ʵ�K�K�K�K?/h3>

a 1.0
a 1.0
K�Kͣ�K�K�K�K�K�K�K�IB(ti)K�K�ʽK�IK�K�K�Kԣ�K�K� K�K�

K�K�K�

K�K�K?/h3>

K�K�l

K�K�K�

K�K

K�alittletotheleftK�K�K�K�K�K�һKKܻ�ӭK�K�K�K�K�K�K�K�K�K�I(y)K�K�K�ǶK�ճK�K�K�еĸK�K�K�K�K?/dd>

K�K�KƵ�K�K?/h2>

K�K�

K�SK�K�K�K�K�Kֻ�K汾K�

K�SK�K�K�K�K�΢K_�K(ji)̖�

K�վK�K�K�K�K�K�K�K�K�K^_(d)K�K�K�KPK�İK�K�뷢�ʼK?a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c0a1a4ada9ae80a8a1afb4a5eea3afad">[email protected]

K�ICPK�2022002427K�-10 K湫K�K�K�K�43070202000427K�© 2013~2024 haote.com K�K�K�