在autoit

时间:2015-09-22 05:00:21

标签: javascript autoit

我偶然发现了一个JS脚本,它以某种方式预测了鼠标的方向或它的去向,并在它到达那里之前将一个物体放在它的路径前面。抱歉,如果我让你感到困惑,

但这是脚本,我无法理解足以在AutoIt中复制,例如:https://jsfiddle.net/pfyruc14/34/

var canvas = document.getElementById('can-i-haz-prediction'),
    context = canvas.getContext('2d'),
    trail = [],
    requiredTrailLength = 20,
    mousePosition = {
        x: 0,
        y: 0
    };

function predict(trail) {
    var b = trail.pop(),
        a = trail[0], // trail.pop() // use this instead of trail[0] for different prediction
        d = {
            x: b.x - a.x,
            y: b.y - a.y
        },
        m = Math.sqrt( d.x * d.x + d.y * d.y );

    d.x = 5 * d.x / m;
    d.y = 5 * d.y / m;

    var predictions = [];
    for(var i = 1; i <= 10; i++) {
        predictions.push({
            x: b.x + i * d.x,
            y: b.y + i * d.y
        });
    }

    return predictions;
}

function step() {
    window.requestAnimationFrame(step);

    trail.length >= requiredTrailLength && trail.shift();
    trail.push(mousePosition);
    if (trail.length < requiredTrailLength) {
        return;
    }

    drawPredictions();
}

function drawPredictions() {
    context.clearRect(0, 0, canvas.width, canvas.height);

    var predictions = predict(Array.prototype.slice.call(trail));
    context.beginPath();
    context.moveTo(predictions[0].x, predictions[0].y);
    for (var i = 1; i < predictions.length; i++) {
        context.lineTo(predictions[i].x, predictions[i].y);
        context.moveTo(predictions[i].x, predictions[i].y);
    }
    context.stroke();
}

function getMousePosition(event) {
    var rect = canvas.getBoundingClientRect();
    return {
        x: event.clientX - rect.left,
        y: event.clientY - rect.top
    };
}

canvas.onmousemove = function (event) {
    mousePosition = getMousePosition(event);
};

step();

我一直在寻找这种外语已经有一段时间了,经历了许多令人头疼的事情,我的“研究”让我觉得

 context.lineTo(predictions[i].x, predictions[i].y);
  context.moveTo(predictions[i].x, predictions[i].y);

预测[i]是预测的旋转值?

我从来都不擅长数学,但我真的很乐意这样做。 有人可以帮我在AutoIt中制作这样的东西吗? 我认为它更简单太对了?  我可以看到很多很酷的东西可以用来做这个。

0 个答案:

没有答案