xxxxxxxxxx
161
let inTouch = false;
let stopOn = false;
let touchended = false;
let touchstarted = false;
var clicks = 0;
let sound;
let t = 100;
let stopSize = 200;
let red = 0;
let blue = 200;
let hue = 200;
function preload() {
sound = loadSound('sound.m4a');
}
function setup() {
createCanvas(windowWidth, windowHeight);
frameRate(10);
colorMode(HSB);
textAlign(CENTER, CENTER);
noStroke();
pixelDensity(displayDensity());
}
function draw() {
background(hue, 100, 100);
// notify when touch event has ended
if (touchended) {
warning();
}
// if we're in a touch event, give some info
if (touchstarted) {
stop();
} else {
if (inTouch) ellipse(mouseX, mouseY, 200, 200);
}
if (touches.length == 3) {
seriously();
}
if (touches.length >= 6) {
pleaseStop();
}
if (clicks >= 20) {
please();
}
if (clicks == 100 || clicks == 150 || clicks == 200 || clicks == 300) {
sound.play();
}
if (clicks >= 80) {
more();
}
if (touches.length >= 10 && clicks >= 50) {
more();
}
} // end draw
function touchStarted() {
inTouch = true;
touchstarted = true;
touchended = false;
clicks++;
return false;
}
function touchEnded() {
inTouch = false;
stopOn = false;
if (touches.length == 0) {
touchended = true;
touchstarted = false;
return false;
}
}
// called whenever a touch is moving (like mouseMoved())
function touchMoved() {
handleMouseAndTouch();
return false;
}
// use same functionality if no touch and only mouse
function mouseMoved() {
handleMouseAndTouch();
}
// this gets called from mouseMoved and touchMoved
// so that this happens either way (I made up this function--
// it's not from p5)
function handleMouseAndTouch() {
hue = map(mouseX, 0, width, 190, 250);
}
function stop() {
background(red, 100, 100);
textSize(stopSize);
fill(0, 100, 0);
text("stop", width / 2, height / 2);
}
function warning() {
textSize(t / 2);
fill(blue + 20, 100, 100);
text("don't touch me.", width / 2, height / 2);
fill(0, 100, 0)
text(clicks, 50, 50);
}
function seriously() {
textAlign(CENTER);
textSize(t * 1.5);
text("seriously?", 400, 150);
}
function please() {
subLoc = height / 2 - (t / 3);
fill(blue, 100, 100);
textSize(t * 0.75);
text("PLEASE", width / 2, subLoc);
}
function pleaseStop() {
fill(0, 100, 0);
textSize(60);
text("please stop.", random(50, width - 50), random(50, height - 50));
// fill(blue, 100, 100);
// textSize(t * 1.5);
// text("please", width / 2, height / 2 - 100);
}
function more() {
fill(blue, 100, 100);
textSize(t * 1.5);
text("more", width / 2, height / 2 - t - 10);
}
function keyPressed() {
clear(); // remove whole sketch on mouse press
}