/* built with Studio Sketchpad:
* https://sketchpad.cc
*
* observe the evolution of this sketch:
* https://studio.sketchpad.cc/sp/pad/view/ro.KpI7uPLmQ5W/rev.8
*
* authors:
* GoToLoop
* license (unless otherwise specified):
* creative commons attribution-share alike 3.0 license.
* https://creativecommons.org/licenses/by-sa/3.0/
*/
/**
* Clockwise Pathway Circle (v1.1.1)
* GoToLoop (2015-Oct-14)
*
* Forum.Processing.org/two/discussion/12995/
* ellipse-moving-in-a-square-pathway-continuously#Item_2
*
* Studio.ProcessingTogether.com/sp/pad/export/ro.9DEx177ceWoBc
* OpenProcessing.org/sketch/902693
* Trinket.io/processing/4f96265ee0
*/
static final short DIAM = 0100, RAD = DIAM >> 1;
static final float SPD = 4, BOLD = 2.5;
static final color BG = 245; // whitesmoke
static final PVector
N = new PVector(0000, -SPD, #FFFF00), // yellow
S = new PVector(0000, +SPD, #FF00FF), // fuchsia
W = new PVector(-SPD, 0000, #00FFFF), // cyan
E = new PVector(+SPD, 0000, #00FF00); // lime
final PVector loc = new PVector(RAD, RAD);
PVector vel = E;
boolean clockwise = true;
void setup() {
size(600, 500);
smooth();
frameRate(60);
ellipseMode(CENTER);
strokeWeight(BOLD);
stroke(0);
fill((color) vel.z);
}
void draw() {
constrainToBorder();
loc.add(vel);
background(BG);
ellipse(loc.x, loc.y, DIAM, DIAM);
}
void keyPressed() {
clockwise ^= true;
if (vel == E) vel = clockwise? S : N;
else if (vel == S) vel = clockwise? W : E;
else if (vel == W) vel = clockwise? N : S;
else vel = clockwise? E : W;
fill((color) vel.z);
}
void mousePressed() {
keyPressed();
}
void constrainToBorder() {
if (vel == E && loc.x > width - RAD - SPD) vel = clockwise? S : N;
else if (vel == S && loc.y > height - RAD - SPD) vel = clockwise? W : E;
else if (vel == W && loc.x < RAD + SPD) vel = clockwise? N : S;
else if (vel == N && loc.y < RAD + SPD) vel = clockwise? E : W;
else return;
fill((color) vel.z);
}