xxxxxxxxxx
int min = 0;
int max = 1000;
int target = 500;
void setup() {
background(200, 100, 100);
fullScreen();
}
void draw() {
fill(255, 255, 255);
fullScreen();
textAlign(LEFT, TOP);
mono = createFont("monospace", 32);
textFont(mono);
text('Binary Search', 0, 0);
textAlign(CENTER, CENTER);
text('Min = ' + min + ' Max = ' + max + ' \nGuess: ' + target, width / 2, height / 2);
}
void keyPressed() {
print('beep boop');
// 0 = <, 1 = >, 2 = ==.
if (key == '<' || key == ',') {
target = (int)((min + max) / 2);
max = target;
max = int(max);
target = int(target);
}
if (key == '>' || key == '.') {
target = (int)((min + max) / 2);
min = target;
min = int(min);
}
if (key == '=') {
print('Number: ' + target);
}
target = max / 2 + min;
}