处理翻转条件

时间:2013-01-17 19:26:37

标签: processing rollover

我正在处理一个简单的翻转。目前,当鼠标悬停在椭圆上时,翻转工作正常,但当我将鼠标移动到另一个位置时它不会消失。

float x = random(0, 255);
float y = random(0, 255);
float d;
float radius;
boolean rollover = false;

void setup() {
  PFont font = loadFont("DialogInput-12.vlw");
  size (800, 600);
  noStroke();
  smooth();
}

void draw() {
  drawData(x, y);

  if (rollover) {
  fill(y);
  textAlign(CENTER);
  text("hahaha", width/2, height/2);
  }

}

void drawData(float x, float y) {

  float value = x;
  float d = dist(x, y, mouseX, mouseY);
  float radius = map(value, 0, y, 10, 10);
  fill(x);  
  ellipse(x, y, radius, radius);

  if(d < radius) {
  rollover = true;
  } else {
    rollover = false;
  }


}

1 个答案:

答案 0 :(得分:4)

只需在绘制循环的开头添加'background(colorvalue)'行:

float x = random(0, 255);
float y = random(0, 255);
float d;
float radius;
boolean rollover = false;

void setup() {
  PFont font = loadFont("DialogInput-12.vlw");
  size (800, 600);
  noStroke();
  smooth();
}

void draw() {
  background(255);  // add this

  drawData(x, y);

  if (rollover) {
  fill(y);
  textAlign(CENTER);
  text("hahaha", width/2, height/2);
  }

}

void drawData(float x, float y) {

  float value = x;
  float d = dist(x, y, mouseX, mouseY);
  float radius = map(value, 0, y, 10, 10);
  fill(x);  
  ellipse(x, y, radius, radius);

  if(d < radius) {
  rollover = true;
  } else {
    rollover = false;
  }


}