Loading...
Logo
Processing Forum
I am working on a project and need a little help. I will have 3 working areas eventually. The umbrella area will have a "joystick" that will control 2 servos through arduino. Right now I am just trying to draw an ellipse in the umbrella area and be able to move it only withi the area of that image, and then have it spring back to the center of that image.
 
Here is the basis of what I have at the moment:

PImage umbrella; 
PImage selection;
PImage stars;
void setup()
{
  size(1440, 900);
  umbrella = loadImage("Umbrella_Corporation_logo.jpg"); 
  selection = loadImage("Grocery-List.jpg");
  stars = loadImage("absorptionspec.jpg");
  noLoop();
}
void draw()
{
  image(umbrella, 1140, 600);
  image(selection, 1140, 0);
  image(stars, 0, 0);
}

Replies(3)

Looks like a good start. What's next?
" be able to move it"
How do you want to move it? (before the Arduino step, which is wise to delay until you get want you want).
In general, you move an object by using variables for its coordinates, and changing the values of these variables.
Now I have the three images, as well as an ellipse that is constrained to the bottom right (joystick) image.The frame part is something I found and will worry about in the future. For now, I am going to try to focus on how to get the ellipse to spring back to the center of the joystick image. I tried to make sense of the springs2 example on the website, but having trouble wrapping my brain around the logic and math. I was thinking of something like an opposing function to void mouseMoved, but there isn't anything out there that I know of.
 
Updated code:
Copy code

  1. int ellipseSize = 70;
    int screenXSize = 1440;
    int screenYSize = 900;
    PImage umbrella; 
    PImage selection;
    PImage stars;
    int value = 0;

  2. void setup() {
      size(screenXSize, screenYSize);
      frame.removeNotify();
      frame.setUndecorated(true);
      umbrella = loadImage("Umbrella_Corporation_logo.jpg");  // Load the image into the program 
      selection = loadImage("Grocery-List.jpg");
      stars = loadImage("absorptionspec.jpg");
    }
  3. void draw() {
      frame.setLocation(0, 0);
      noCursor();
      image(umbrella, 1140, 600);
      image(selection, 1140, 0);
      image(stars, 0, 0);
      fill(0, 64, 255, 127);
      float mx = constrain(mouseX, 1140 + (ellipseSize/2), 1440 - (ellipseSize/2));
      float my = constrain(mouseY, 600 + (ellipseSize/2), 900 - (ellipseSize/2));
      smooth();
      ellipseMode(CENTER);
      ellipse(mx, my, ellipseSize, ellipseSize);
    }