我是处理的新手,我正在尝试lerp
处理处理中的功能。基本上我想做的是,点击屏幕上的不同点,这些位置被存储在一个数组中。当用户点击 时,存储的动作会在点之间以平滑enter
的移动方式回放。ellipse
我的问题是,当我单击 Enter 时,我得到“算术异常为零”。你能指导我我错过了什么吗?谢谢。
final static int numFrames = 30; //frames between keyframes
final static int numKeyFrames = 1; //frames between keyframes
Point[] keyFrames;
Point[] frames;
void setup()
{
size(640, 480);
frameRate(30);
LinearInterp();
}
void mouseClicked()
{
stroke(0);
strokeWeight(8);
for(int i=0; i<numKeyFrames; i++)
{
keyFrames = new Point[numKeyFrames];
keyFrames[i] = new Point(mouseX,mouseY);
point(keyFrames[i].x,keyFrames[i].y);
println("Mouse Coordinates are: " + keyFrames[i]);
}
}
void LinearInterp()
{
frames = new Point[numFrames*(numKeyFrames-1)];
for (int kf = 0; kf< numKeyFrames-1; kf++)
{
Point p0 = keyFrames[kf];
Point p1 = keyFrames[kf+1];
for (int f =0; f<numFrames; f++)
{
float a = f*1.0/numFrames;
int newX = int(p0.x * (1-a) + p1.x * a);
int newY = int(p0.y * (1-a) + p1.y * a);
frames[f+(kf*numFrames)] = new Point(newX,newY);
}
}
}
void animateFrames()
{
stroke(187);
strokeWeight(10);
int i = frameCount % frames.length;
point(frames[i].x,frames[i].y);
}
void drawFrames()
{
stroke(187);
strokeWeight(2);
for (int i=0; i<frames.length; i++)
{
point(frames[i].x,frames[i].y);
}
}
void draw()
{
if(keyPressed)
{
if(key == ENTER)
{
drawFrames();
animateFrames();
}
}
}