/* built with Studio Sketchpad:
* https://sketchpad.cc
*
* observe the evolution of this sketch:
* https://studio.sketchpad.cc/sp/pad/view/ro.snWs5vRc2hE/rev.4
*
* authors:
* GoToLoop
* license (unless otherwise specified):
* creative commons attribution-share alike 3.0 license.
* https://creativecommons.org/licenses/by-sa/3.0/
*/
/**
* Quadrant Mouse Position (v1.0)
* GoToLoop (2016-Feb-25)
*
* forum.Processing.org/two/discussion/15129/mousex-and-mousey
* studio.ProcessingTogether.com/sp/pad/export/ro.9hc1FSKJk66wK
*/
static final int FPS = 5, BOLD = 8;
static final boolean ONLINE = 1/2 == 1/2.;
String quadrant;
void setup() {
size(800, 600);
smooth(4);
noLoop();
frameRate(FPS);
stroke(0);
strokeWeight(BOLD);
rectMode(CORNER);
mouseMoved();
}
void draw() {
fill((color) random(#000000));
rect(0, 0, width, height);
final int cx = width>>1, cy = height>>1;
line(0, cy, width, cy);
line(cx, 0, cx, height);
if (!ONLINE) frame.setTitle("Quadrant: " + quadrant);
else println("Quadrant: " + quadrant);
}
void mouseMoved() {
final int cx = width>>1, cy = height>>1;
final int mx = mouseX, my = mouseY;
if (mx < cx & my < cy) quadrant = "Top-Left";
else if (mx < cx & my >= cy) quadrant = "Bottom-Left";
else if (mx >= cx & my < cy) quadrant = "Top-Right";
else quadrant = "Bottom-Right";
redraw();
}