Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/450.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
javascript处理框架_Javascript_Processing_Nan_Numeric_Addition - Fatal编程技术网

javascript处理框架

javascript处理框架,javascript,processing,nan,numeric,addition,Javascript,Processing,Nan,Numeric,Addition,我正在尝试将javascript处理框架与html5画布一起使用,但我在简单添加3个数字变量时遇到了一个问题,我无法解决这个问题。 代码如下: var radius = 50.0; var x, y; var nX, nY; var delay = 16.0; // Simple way to attach js code to the canvas is by using a function function sketchProc(processing) { processing.s

我正在尝试将javascript处理框架与html5画布一起使用,但我在简单添加3个数字变量时遇到了一个问题,我无法解决这个问题。 代码如下:

var radius = 50.0;

var x, y;
var nX, nY;
var delay = 16.0;

// Simple way to attach js code to the canvas is by using a function
function sketchProc(processing) {


processing.size(200,200);
processing.strokeWeight(10);
processing.frameRate(15);
x = processing.width/2.0;
y = processing.height/2.0;
nx = x;
ny = y;



  // Override draw function, by default it will be called 60 times per second
  processing.draw = function() {

    radius = radius + Math.sin(processing.frameCount/4);

    x+=((nX-x)/delay);
    y+=((nY-y)/delay);

    processing.background(100);

    processing.fill(0,121,184);

    processing.stroke(255);

    processing.ellipse(x,y,radius,radius);
  };


  processing.mouseMoved = function(){
        nX = processing.mouseX;
        nY = processing.mouseY;

    }
}

var canvas = document.getElementById("canvas1");
// attaching the sketchProc function to the canvas
var p = new Processing(canvas, sketchProc);
// p.exit(); to detach it

与x和y相加的线一定是问题所在。我从这个表达式中得到“NaN”,虽然它是3个数值。有什么想法吗?

JavaScript标识符区分大小写,因此
nx
ny
nx
ny
不同:

nx = x;
ny = y;

...

x+=((nX-x)/delay);
y+=((nY-y)/delay);