xxxxxxxxxx
let pX, pY;
function setup() {
createCanvas(windowWidth, windowHeight);
colorMode(HSB);
ellipseMode(CENTER);
pX = 0;
pY = height / 2;
}
const hues = [
[0, 0, 10, 1],
[0, 0, 90, 1],
[0, 0, 30, 1],
[10, 90, 35, 1]
];
let hueIndex = 0;
let gameOver = false;
function switchHue() {
hueIndex = (hueIndex + 1) % hues.length;
}
function backHue() {
if (hueIndex - 1 < 0) {
hueIndex = hues.length - 1;
} else {
huesIndex = hueIndex - 1;
}
}
function reset() {
gameOver = false;
}
function draw() {
background(10, 100, 90, 1);
stroke(hues[hueIndex]);
strokeWeight(1)
line(0, height / 2 + 50, width, height / 2 + 50);
if (keyIsDown(LEFT_ARROW)) {
pX -= 10;
if (pX < 0) {
pX = width;
backHue();
}
}
if (keyIsDown(RIGHT_ARROW)) {
pX += 10;
if (pX > width) {
pX = 0;
switchHue();
}
}
fill(0);
strokeWeight(20);
if (!gameOver) {
ellipse(pX, pY, 50, 80);
}
const overscan = 20;
const period = 5; //(mouseX/width) * 100;
let amp = sin(frameCount / 100) * height * 0.75;
amp = mouseY / height * height / 2;
const gameoverY = (height / 2) - 80;
if (amp > gameoverY) {
gameOver = true;
}
noFill();
beginShape();
for (let x = -overscan; x < width + overscan; x++) {
const y = sin(x / period) * amp;
vertex(x, -overscan + y);
}
endShape();
beginShape();
for (let x = -overscan; x < width + overscan; x++) {
const y = sin(x / period) * amp;
vertex(x, height + overscan + y);
}
endShape();
}
function mousePressed() {
reset();
}