第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

lineWidth 打印出來為NaN?是什么問題呢?求解答


var canvasWidth = 800;
var canvasHeight = canvasWidth;
var isMouseDown = false;
var lastloc = {x: 0, y: 0};//上一次鼠標(biāo)的位置
var lastTimestamp = 0;

var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
canvas.width = canvasWidth;
canvas.height = canvasHeight;

drawGrid();
canvas.onmousedown = function (e) {
? ?e.preventDefault();
? ?isMouseDown = true;
? ?lastloc = windowToCanvas(e.clientX, e.clientY);
? ?lastTimestamp = new Date().getTime();//當(dāng)前時(shí)間戳
}
canvas.onmouseup = function (e) {
? ?e.preventDefault();
? ?isMouseDown = false;
? ?console.log("up");
}
canvas.onmouseout = function (e) {
? ?e.preventDefault();
? ?isMouseDown = false;
? ?console.log("out");
}
canvas.onmousemove = function (e) {
? ?e.preventDefault();
? ?if (isMouseDown) {
? ? ? ?var curloc = windowToCanvas(e.clientX, e.clientY);
? ? ? ?var curTimestamp = new Date().getTime();
? ? ? ?var s = calcDistance(curloc, lastloc);
? ? ? ?var t = curTimestamp - lastTimestamp;
? ? ? ?var lineWidth = calcLineWidth(t, s);
? ? ? ?console.log(lineWidth);
? ? ? ?//write
? ? ? ?context.beginPath();
? ? ? ?context.moveTo(lastloc.x, lastloc.y);
? ? ? ?context.lineTo(curloc.x, curloc.y);
? ? ? ?context.strokeStyle = "black";
? ? ? ?context.lineWidth = lineWidth;
? ? ? ?context.lineCap = "round";
? ? ? ?context.lineJoin = "round";
? ? ? ?context.stroke();
? ? ? ?lastloc = curloc;
? ? ? ?lastTimestamp = curTimestamp;
? ?}
}
function windowToCanvas(x, y) {
? ?var bbox = canvas.getBoundingClientRect();
? ?return {x: Math.round(x - bbox.left), y: Math.round(y - bbox.top)}
}
function calcDistance(loc1, loc2) {
? ?return Math.sqrt((loc1.x - loc2.x) * (loc1.x - loc2) + (loc1.x + loc2.x) * (loc1.x + loc2))
}
function calcLineWidth(t, s) {
? ?var v = s / t;
? ?var resultLineWidth;
? ?if (v<=0.1) {
? ? ? ?resultLineWidth = 30;
? ?} else if (v>=10) {
? ? ? ?resultLineWidth = 1;
? ?} else {
? ? ? ?resultLineWidth = 30 - (v - 0.1) / (10 - 0.1) * (30 - 1);
? ?}
? ?return resultLineWidth;
}
function drawGrid() {
? ?context.save();
? ?context.strokeStyle = "rgb(230,11,9)";
? ?context.beginPath();
? ?context.moveTo(3, 3);
? ?context.lineTo(canvasWidth - 3, 3);
? ?context.lineTo(canvasWidth - 3, canvasHeight - 3);
? ?context.lineTo(3, canvasHeight - 3);
? ?context.closePath();
? ?context.lineWidth = 6;
? ?context.stroke();

? ?context.beginPath();
? ?context.moveTo(0, 0);
? ?context.lineTo(canvasWidth, canvasHeight);
? ?context.moveTo(canvasWidth, 0);
? ?context.lineTo(0, canvasHeight);
? ?context.moveTo(canvasWidth / 2, 0);
? ?context.lineTo(canvasWidth / 2, canvasHeight);
? ?context.moveTo(0, canvasHeight / 2);
? ?context.lineTo(canvasWidth, canvasHeight / 2);
? ?context.closePath();
? ?context.lineWidth = 1;
? ?context.stroke();
? ?context.restore();
}

正在回答

1 回答

function calcDistance(loc1, loc2) {
? ?return Math.sqrt((loc1.x - loc2.x) * (loc1.x - loc2) + (loc1.x + loc2.x) * (loc1.x + loc2))
}

應(yīng)改為:

function calcDistance(loc1, loc2) {
? ?return Math.sqrt((loc1.x - loc2.x) * (loc1.x - loc2.x) + (loc1.y - loc2.y) * (loc1.y + loc2.y))
}

兩點(diǎn)間距離公式.

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

HeyLuckyGirl 提問者

非常感謝!我也發(fā)現(xiàn)這邊寫的不仔細(xì),謝謝!
2016-01-10 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

lineWidth 打印出來為NaN?是什么問題呢?求解答

我要回答 關(guān)注問題
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)