0

这是我的源代码:

int index;
int num = 60;
float mx[] = new float[num];
float my[] = new float[num];
float explosion;
float x;
float y;
float px;
float py;
float xold;
float yold;
float xplode1;
float yplode1;
float xplode2;
float yplode2;
float xplode3;
float yplode3;
float xplode4;
float yplode4;
float easing = 0.05;

void setup() {
  size(1366, 768);
  noStroke();
//  noFill();
  fill(25, 155);
}

void draw() {
  int which = frameCount % num;

  explosion = explosion + 0.32;
  background(92, 55, 169);

  float targetX = mouseX;
  float dx = targetX - px;
  float lx = targetX - x;
  if (abs(dx) > 1) {
    mx[which] += dx * easing;
    x += lx * easing;
    if (mousePressed && (mouseButton == LEFT)) {
      xplode1 = dx + 50 + sin(explosion)*30;
      xplode2 = dx + 50 + sin(explosion)*30;
      xplode3 = dx - 50 - sin(explosion)*30;
      xplode4 = dx - 50 - sin(explosion)*30;
    }
    else {
      xplode1 = -10;
      xplode2 = -10;
      xplode3 = -10;
      xplode4 = -10;
    }
  }

  float targetY = mouseY;
  float dy = targetY - py;
  float ly = targetY - y;
  if (abs(dy) > 1) {
    my[which] += dy * easing;
    y += dy * easing;
    if (mousePressed && (mouseButton == LEFT)) {
      yplode1 = dy + 50 + sin(explosion)*30;
      yplode2 = dy - 50 - sin(explosion)*30;
      yplode3 = dy - 50 - sin(explosion)*30;
      yplode4 = dy + 50 + sin(explosion)*30;
    }
    else {
      yplode1 = -10;
      yplode2 = -10;
      yplode3 = -10;
      yplode4 = -10;
    }
  }

  for(int i = 0;i<num;i++){
    index = (which + 1 + i) % num;
    ellipse(mx[index], my[index], i, i);
  }
  ellipse(xplode1, yplode1, 10, 10);
  ellipse(xplode2, yplode2, 10, 10);
  ellipse(xplode3, yplode3, 10, 10);
  ellipse(xplode4, yplode4, 10, 10);
}

我想有一个~60的轨迹,并且对整个事情也有一些缓和。我已经让每个功能都单独工作,但是当我添加到褪色中时。有很多不需要的变量,我根本没有清理代码,我已经研究了几个小时,我知道可能有一个非常简单的解决方案,我现在看不到。任何帮助都会很棒,谢谢。

4

1 回答 1

1

不要咬得比你能咀嚼的多,学习一些小事。向量将使您的代码不那么混乱。您可以在处理站点上找到 Vector 类的详细说明。这样,将有一个 Vector 对象来存储这两个值,而不是拥有两个不同的变量 xplode1 和 xplode2。一开始您可能会发现这些概念很困难,但它们将成为未来草图的宝贵工具。

如果您对变量、函数、条件和循环等基本概念感到满意,请开始学习OOP(面向对象编程)。再次,丹尼尔·希夫曼来帮忙

此外,在 StackOverflow 上询问时要更加具体。解决问题通常意味着找到正确的问题。

于 2013-06-11T12:26:19.953 回答