全局变量"x"不存在,处理 3.2.3。处理和 Kinect



当我遇到一个无法找到解决方案的错误时,我开始在处理中编码。

**免责声明:我是新的编码,所以我有困难理解它是如何工作lol

我试图用处理程序为kinect程序编写代码,以产生连锁反应,但我不知道如何定义两个变量。

代码:

// A simple ripple effect. Click on the image to produce a ripple
// Author: radio79
// Code adapted from http://www.neilwallis.com/java/water.html
// Code adapted from https://forum.processing.org/two/discussion/25348/can-i-apply-ripple-effect-to-kinect
import org.openkinect.processing.*;
Kinect kinect;

PImage img;
Ripple ripple;
void setup() {
size(1920, 1080);
kinect = new Kinect(this);
kinect.initVideo();

img = new PImage(kinect.colorWidth, kinect.colorHeight);
ripple = new Ripple();
//frameRate(60);
}
void draw() {
image(kinect.getVideoImage(), 0, 0);
img.loadPixels();
for (int loc = 0; loc < Kinect.colorWidth * Kinect.colorHeight; loc++) {
img.pixels[loc] = ripple.col[loc];
}

img.updatePixels();
ripple.newframe();
}
class Ripple {
int i, a, b;
int oldind, newind, mapind;
short ripplemap[]; // the height map
int col[]; // the actual pixels
int riprad;
int rwidth, rheight;
int ttexture[];
int ssize;
Ripple() {
// constructor
riprad = 3;
rwidth = width >> 1;
rheight = height >> 1;
ssize = width * (height + 2) * 2;
ripplemap = new short[ssize];
col = new int[width * height];
ttexture = new int[width * height];
oldind = width;
newind = width * (height + 3);
}

void newframe() {
// update the height map and the image
i = oldind;
oldind = newind;
newind = i;
i = 0;
mapind = oldind;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
short data = (short)((ripplemap[mapind - width] + ripplemap[mapind + width] + 
ripplemap[mapind - 1] + ripplemap[mapind + 1]) >> 1);
data -= ripplemap[newind + i];
data -= data >> 5;
if (x == 0 || y == 0) // avoid the wraparound effect
ripplemap[newind + i] = 0;
else
ripplemap[newind + i] = data;
// where data = 0 then still, where data > 0 then wave
data = (short)(1024 - data);
// offsets
a = ((x - rwidth) * data / 1024) + rwidth;
b = ((y - rheight) * data / 1024) + rheight;
//bounds check
if (a >= width) 
a = width - 1;
if (a < 0) 
a = 0;
if (b >= height) 
b = height-1;
if (b < 0) 
b=0;
col[i] = img.pixels[a + (b * width)];
mapind++;
i++;
}
}
}
}
void mouseDragged() {
for (int j = mouseY - ripple.riprad; j < mouseY + ripple.riprad; j++) {
for (int k = mouseX - ripple.riprad; k < mouseX + ripple.riprad; k++) {
if (j >= 0 && j < height && k>= 0 && k < width) {
ripple.ripplemap[ripple.oldind + (j * width) + k] += 512;
}
}
}
}

错误是:'全局变量"x"全局变量"y"不存在"等等。请帮助。

我需要帮助定义的变量第一次出现在第18行,它们是colorWidth和colorHeight

img = new PImage(kinect.colorWidth, kinect.colorHeight);

colorWidth和colorHeight用红色下划线表示。

我试过用这个方法:

public 
float colorWidth;
float colorHeight;

但是,似乎只有第二行定义正确。第一行发出消息"colorWidth无法解析或不是一个字段"。当程序运行时,或参数colorWidth的非法修饰符;只允许最后的"单击下划线时。程序在公共代码

后显示的图片请帮助! !谢谢你!

关键字public在这里没有任何意义,它必须用于函数或变量。你根本不需要它。因此,删除它应该解决问题!

相关内容

  • 没有找到相关文章

最新更新