This is a simply program that is supposed to allow you to drag squares around the screen. The problem is that the contains function is not working after I update the polygon points. Please try this and see if you know what the problem is.
Mouse over the green square and see it highlights. Now click and drag it. Note that it now highlights only when the mouse is within the square AND within the original position (purple bounding box).
Here is the code:
//globals int tile_size = 50; ArrayList tiles; int selected_tile;
tiles = new ArrayList(); color tile_color = color(0,255,0); tiles.add(new Tile(1, tile_color, new PVector(200,200))); tiles.add(new Tile(1, color(255,0,0), new PVector(400,400))); }
//main program loop void draw() { background(0);
//original position stroke(255,0,255); noFill(); rect(200,200,100,100);
drawTiles(); selected_tile = checkMouse(); }
//draw the tiles void drawTiles() { for (int i = tiles.size()-1; i >= 0; i--) { // An ArrayList doesn't know what it is storing so we have // to cast the object coming out Tile tile = (Tile)tiles.get(i); tile.drawTile(); } }
//returns the index of the tile under the mouse, -1 if none //only will return 1 shape int checkMouse() { int selected = -1; for (int i = tiles.size()-1; i >= 0; i--) { Tile tile = (Tile)tiles.get(i); if (tile.checkInside(mouseX, mouseY)) { tile.selected = true; selected = i; } else { tile.selected = false; } } return selected; }
void mousePressed() { press = new PVector(mouseX, mouseY); }
It might be running slowly on your system and that is the problem. It runs ok on mine but it slows down as you start to zoom in. The problem is that it takes a long time to draw very large ellipses and arcs. I've already made sure it's not drawing yinyangs that are completely off the screen.
I'm thinking that in order to increase the speed I need to rewrite the method for drawing arcs so it doesn't draw pixels that are off the screen. Actually there is really 1 shape I am drawing, which is a a half a yingyang. Maybe I should make a method which draws this shape?
I tried to find the code for arc() but I don't know where to find it. Is it from Java? There must be a more efficient way to do this.
Hi, I'm writing a program where I want to use complimentary colors. I know how to do this where the brightness and saturation are constant; you simply phase shift the hue component over by 255/2. But how do I find the opposite color when saturation are involved?