xxxxxxxxxx
// Mouse Control
int swidth, sheight, xc, yc, rad;
int[] fillcol = new int[3];
// The setup code below is executed once only.
void setup() {
// Set up the graphics:
background(50);
// Set up the screen size:
swidth = 0.7*screen.width;
sheight = 0.7*screen.height;
size(swidth,sheight);
// Increase the font size:
textSize(20);
// Set the location and intial radius of the circle:
xc = 0.5*swidth;
yc = 0.5*sheight;
rad = 40;
// Set the initial color of the circle to blue:
fillcol = {0,255,0};
}
// The draw code below is executed over and over again.
void draw() {
background(255); // Clear the screen.
fill(fillcol[0],fillcol[1],fillcol[2]); // Set the fill color.
ellipse(xc,yc,2*rad,2*rad); // Draw a circle.
}
void mouseDragged() {
// This is a built-in Processing function. It runs any time a mouse button
// is pressed and the mouse cursor dragged around the screen.
// Set the radius of the circle so that the circle passes through the
// current mouse location:
// rad = sqrt(pow(mouseX-xc,2) + pow(mouseY-yc,2));
// Set the color of the circle to red while the mouse button is pressed:
fillcol = {0,0,255};
xc = mouseX;
yc = mouseY;
}
void mouseReleased() {
// This is a built-in Processing function. It runs any time a mouse button
// is released.
// Set the fill color back to blue, now that the mouse button has
// been released:
fillcol = {0,255,0};
}