Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.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
Java 坐标值不存储在处理中_Java_Coordinates_Processing - Fatal编程技术网

Java 坐标值不存储在处理中

Java 坐标值不存储在处理中,java,coordinates,processing,Java,Coordinates,Processing,我真的不知道为什么x和y值不会进入drawLines函数 float x, x1, x2; float y, y1, y2; float rad; //radius int lines = 30; //number of lines int colorNumber = 1; void setup() { background(#FFFFFF); size (800, 600); rad = 8; } void draw() { } 这将创建数学封套的三个点或顶点 void mo

我真的不知道为什么x和y值不会进入drawLines函数

float x, x1, x2;
float y, y1, y2;
float rad; //radius
int lines = 30; //number of lines
int colorNumber = 1;

void setup() {
  background(#FFFFFF);
  size (800, 600);
  rad = 8;
}

void draw() {
}
这将创建数学封套的三个点或顶点

void mouseClicked() {
  float x = mouseX;
  float x1 = mouseX;
  float x2 = mouseX;
  float y = mouseY;
  float y1 = mouseY;
  float y2 = mouseY;
  if (colorNumber == 1) {
    fill(#9393ff);
    ellipse(x, y, rad, rad);
  } else if (colorNumber == 2) {
    fill(#FF9393);
    ellipse(x1, y1, rad, rad);
  } else if (colorNumber == 3) {
    fill(#93ff93);
    ellipse(x2, y2, rad, rad);
  }
}
这将使用顶点的坐标绘制封套

void drawLines(int numLines) {
  for (int i = 0; i < numLines; i = i + 1) {
    float x = mouseX;
    float x1 = mouseX;
    float x2 = mouseX;
    float y = mouseY;
    float y1 = mouseY;
    float y2 = mouseY;
    float t = (float) i/(numLines-1); 
    float startX = x + t * (x1 - x);
    float startY = y + t * (y1 - y);
    float endX = x1 + t * (x2 - x1);
    float endY = y1 + t * (y2 - y1);
    line (startX, startY, endX, endY);
  }
}

void mouseReleased() {
  colorNumber++; 
  if (colorNumber == 4) {
    colorNumber = 1;
  }
  println(colorNumber);
}

void keyPressed() {
  if (keyPressed == true) {
    background(#FFFFFF);
  }
}
void绘图线(整数线){
对于(int i=0;i

最后一个东西只是告诉代码,如果你按下一个键,它将重置回退

我理解你打算使用鼠标和鼠标来指定信封点击时3个点之一的坐标。当前的问题是,每次单击都将所有3个点设置为相同的坐标。您需要引入一个变量来跟踪单击时要设置的坐标,以便只设置一对坐标。然后,只有在设置了所有3个坐标后,才能调用drawLines()

我提议如下:

void mouseClicked() {

    ellipse(mouseX, mouseY, 8, 8);
    coords[index] = new PVector(mouseX, mouseY);
    index += 1;
    if (index == 3) {
        drawLines(lines);
    }
    index %= 3;
}
引入两个变量,一个用于跟踪修改的点;另一个是一组pvector(只是为了让它更干净)

修改mouseClicked()以包括以下内容:

void mouseClicked() {

    ellipse(mouseX, mouseY, 8, 8);
    coords[index] = new PVector(mouseX, mouseY);
    index += 1;
    if (index == 3) {
        drawLines(lines);
    }
    index %= 3;
}
drawLines()变为:

void绘图线(整数线){
对于(int i=0;i

最后,由于您的绘图是在黑色背景上进行的,默认笔划颜色为黑色,请使用strokeColour()更改线条的颜色,以便在绘制信封后可以看到信封。

看起来您正在对变量
x
y
进行阴影处理-您要使用哪些变量-仅声明一次?虽然我不知道您的代码中设置/宣布值
mouseX
等的位置,但是我有三个坐标对,因此有6个坐标点(x、x1、x2、y、y1、y2),分别等于三次单击中每一次的mouseX和mouseY值。单击窗口中的一个点,它会创建一个点,mouseX和mouseY值在该点发挥作用。
drawLines
从何处调用?我从任何地方都打过电话,但都没用。可悲的是,我已经为此工作了好几个小时,不知道是什么错了,我到处都叫它,但它不起作用,所以基本上你不知道?请分享您正在使用的真实代码-此代码不称为
drawines
-只是注意到您正在使用
处理
-正确吗?
void drawLines(int numLines) {

    for (int i = 0; i < numLines; i = i + 1) {
        x = coords[0].x;
        x1 = coords[1].x;
        x2 = coords[2].x;
        y = coords[0].y;
        y1 = coords[1].y;
        y2 = coords[2].y;
        float t = (float) i / (numLines - 1);
        float startX = x + t * (x1 - x);
        float startY = y + t * (y1 - y);
        float endX = x1 + t * (x2 - x1);
        float endY = y1 + t * (y2 - y1);
        line(startX, startY, endX, endY);
    }
}