Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何调整HTML5画布上已关闭的路径的大小?_Html_Path_Html5 Canvas_Dynamic Resizing_2d Context Api - Fatal编程技术网

如何调整HTML5画布上已关闭的路径的大小?

如何调整HTML5画布上已关闭的路径的大小?,html,path,html5-canvas,dynamic-resizing,2d-context-api,Html,Path,Html5 Canvas,Dynamic Resizing,2d Context Api,我在画布上绘制了一条二次曲线。我想通过window.setInterval来设置它的动画,并在此后更改它的尺寸(请注意,不仅仅是更改它的比例) 调用context.closePath()后,如何保留对路径的可编辑引用?我建议您在新的路径对象中保留对路径的引用;这样,您可以动态修改x、y、点等,然后在每个动画步骤中进行渲染 var testPath = new Path(100, 100, [[40, 40], [80, 80]]); var canvas = document.getElemen

我在画布上绘制了一条二次曲线。我想通过window.setInterval来设置它的动画,并在此后更改它的尺寸(请注意,不仅仅是更改它的比例)


调用context.closePath()后,如何保留对路径的可编辑引用?

我建议您在新的
路径
对象中保留对路径的引用;这样,您可以动态修改x、y、点等,然后在每个动画步骤中进行渲染

var testPath = new Path(100, 100, [[40, 40], [80, 80]]);
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');

function Path(x, y, points)
{
    this.x = x;
    this.y = y;
    this.points = points;
}

function update()
{
    ctx.clearRect(0, 0, canvas.width, canvas.height);
    ctx.strokeStyle = 'red';
    ctx.moveTo(testPath.points[0][0], testPath.points[0][1]);
    for (var i = 1; i < testPath.points.length; i++)
    {
        ctx.lineTo(testPath.points[i][0], testPath.points[i][1]);
    }
    ctx.stroke();
    testPath.points[1][1]++; // move down

    // loop
    requestAnimationFrame(update);
}

update();​
var testPath=新路径(100100,[[40,40],[8080]];
var canvas=document.getElementById('canvas');
var ctx=canvas.getContext('2d');
功能路径(x、y、点)
{
这个.x=x;
这个。y=y;
这个点=点;
}
函数更新()
{
clearRect(0,0,canvas.width,canvas.height);
ctx.strokeStyle=‘红色’;
ctx.moveTo(testPath.points[0][0],testPath.points[0][1]);
对于(var i=1;i
出于某些原因,JSFIDLE不能很好地处理Paul Irish的requestAnimationFrame polyfill,但它应该在本地工作。我肯定会推荐这个而不是setInterval


一旦在
画布上绘制了像素,它就不会保留对象表示。如果要操纵对象而不是像素,请使用或,这样就无法“重画”画布上已可见的路径?或者有没有其他方法,比如删除旧的,然后放一个新的在它的位置上?没有,一旦画出来,它只是像素。
canvas
中的动画是通过清除像素并绘制新的稍有不同的像素来实现的。您可以清除画布并使用不同的参数重新绘制路径。如果你有不想清除的东西,就把路径放在它自己的画布上。