/** * Specify all the Javascript methods that can be called from this sketch. */ interface JavaScript { } // interface JavaScript /** * This method is called from Javascript and gives * the links to the left and right sketches. */ void setLinkSketch(Object[] pjs, JavaScript js) { pjsLeft = pjs[0]; pjsRight = pjs[2]; } Object pjsLeft, pjsRight; int xLine, yLine, xSquare, ySquare, xCircle, yCircle; /** * Initialize the sketch */ void setup() { size(250,300); background(0); smooth(); noLoop(); xLine = 500; // Initially draw items off screen yLine = 500; // to hide them. xSquare = 500; ySquare = 500; xCircle = 500; yCircle = 500; } /** * Draw the sketch */ void draw() { fill(0,0,0,20); rect(-1,-1,width+2,height+2); // draw lines stroke(#FFFF00); line(xLine,-1,xLine,height+2); line(-1,yLine,width+2,yLine); // draw square fill(#00FF00); rect(xSquare-10, ySquare-10, 20, 20); // draw circle stroke(#FF00FF); fill(#FF00FF); ellipse(xCircle, yCircle, 20, 20); } //draw /** * Respond to mouse movement by updating the square location and asking other * sketches to draw the square. */ void mouseMoved() { xSquare = mouseX; ySquare = mouseY; if (pjsLeft != null) { pjsLeft.drawSquare(xSquare, ySquare); } if (pjsRight != null) { pjsRight.drawSquare(xSquare, ySquare); } redraw(); } /** * Get coordinates of lines */ void drawLines(int xCoor, int yCoor) { xLine = xCoor; yLine = yCoor; redraw(); } // drawLines /** * Get cooredinates of circle */ void drawCircle(int xCoor, int yCoor) { xCircle = xCoor; yCircle = yCoor; redraw(); } // drawCircle