Mouse Hover Over Dynamic Background

edited February 2014 in How To...

I have a sketch which is constantly drawing ellipses. I want to be able to hover over, and have the ellipses grow and become circled, but then go back to normal when the cursor moves on, but still have the original layer continue to draw new ellipses. I was thinking that if I could do the hover over drawing on a second layer I could just wipe it clean after mouse hover, but I don't know how to do that. This is how I have it set up right now (basically each time a circle is drawn I record the coordinates to a tsv file. There's probably a better way to do this to, but this is the only way I've gotten it to work):

void draw() {
  int x = int(random(0, 600));
  int y = int(random(0, 600));

  checkCircles();

  for (int i = 0; i < 100;i++) {
    x = int(random(0, 600));
    y = int(random(0, 600));
    fill(#8c0e10);
    ellipse(x, y, circle, circle);
    circleOutput.println(x+"\t"+y);
  }
}

void checkCircles() {
  String[] circles = loadStrings("circleData.tsv");
  for (int i = 0; i<circles.length;i++) {
    String[] row = split(circles[i], "\t");
    if (int(row[0]) == mouseX && int(row[1]) == mouseY) {
      stroke(255);
      fill(#8c0e10);
      ellipse(int(row[0]), int(row[1]), 30, 30);
      noStroke();
    }
  }
}
]

But this obviously leaves the mouseHover circles behind so I'm just constantly drawing new circles. It gets covered eventually by the constantly drawn circles in the draw function, but I want them to disappear immediately. Any ideas would be greatly appreciated.

Answers

  • 1st of all, you've posted an unrunnable code w/ duplicate functions! >:P
    And 1st strategical idea is to have a Circle class to keep track where each elliptical drawing is and its dimensions! >-)

  • Sorry, I just realized I copied the code twice. This code may still not run properly as it was edited from the original code to be more simple and just show the part I was working on here, but I think you should be able to see what I'm talking about.

    However I apparently didn't explain myself very well. The ellipses are being recorded on line 12 and read on line 17. That's not the problem. The problem is that I need the newly drawn ellipses to disappear after my mouse moves on without wiping the dynamic background behind it.

    I was thinking I could use pGraphics? But I'm not very experienced with them and if someone could point me in the right direction that would be amazing.

  • I was thinking I could use PGraphics?

    I've just posted examples of using it in the post bellow:

    http://forum.processing.org/two/discussion/2728/altering-images-for-later-recall

Sign In or Register to comment.