/* built with Studio Sketchpad:
* https://sketchpad.cc
*
* observe the evolution of this sketch:
* https://studio.sketchpad.cc/sp/pad/view/ro.h7uSv4dEtAL/rev.4
*
* authors:
* GoToLoop
* license (unless otherwise specified):
* creative commons attribution-share alike 3.0 license.
* https://creativecommons.org/licenses/by-sa/3.0/
*/
/**
* JoyStick Circle (v1.0)
* GoToLoop (2015/Dec/05)
*
* forum.Processing.org/two/discussion/13786/how-make-key-combos
* studio.ProcessingTogether.com/sp/pad/export/ro.9Zd5RXcA2S3CR
*/
static final int CIRCLE_SIZE = 25;
static final PVector UP_POS = new PVector(125, 50);
static final PVector DOWN_POS = new PVector(125, 200);
static final PVector LEFT_POS = new PVector(50, 125);
static final PVector RIGHT_POS = new PVector(200, 125);
static final PVector CENTER_POS = new PVector(125, 125);
PVector circlePos = CENTER_POS;
void keyPressed() {
switch (keyCode) {
case UP:
circlePos = UP_POS;
break;
case DOWN:
circlePos = DOWN_POS;
break;
case LEFT:
circlePos = LEFT_POS;
break;
case RIGHT:
circlePos = RIGHT_POS;
break;
default:
circlePos = CENTER_POS;
}
redraw();
}
void keyReleased() {
circlePos = CENTER_POS;
redraw();
}
void setup() {
size(250, 250);
smooth(4);
noLoop();
ellipseMode(CENTER);
strokeWeight(2.5);
stroke(0);
fill(#FFFF00);
}
void draw() {
background(0350);
ellipse(circlePos.x, circlePos.y, CIRCLE_SIZE, CIRCLE_SIZE);
}