Click or Touch Her
xxxxxxxxxx
//source of the voice: https://youtu.be/nziF_3hBa54?t=11570
var voice, unmute;
var volume = 0.5;
const ars = [];
let motchin;
var picID, mochiT;
var vertical;
var a, b;
var px, py, sx, sy;
var stretch = 0;
var count = 2;
var touch = false;
var right = true;
var mute = true;
function preload() {
soundFormats("mp3", "ogg");
voice = loadSound("almal_voice.mp3");
unmute = loadSound("soundless.mp3");
for (var i=0; i<2; i++) ars[i] = loadImage("almal"+i+".png");
motchin = loadImage("motchi-n.png");
}
function setup() {
createCanvas(windowWidth, windowHeight);
if (windowWidth < windowHeight) {
vertical = true;
a = windowWidth;
b = windowHeight;
} else {
vertical = false;
a = windowHeight;
b = windowWidth;
}
frameRate(24);
voice.playMode('restart');
}
function draw() {
background(255);
//Turn off the bottom "//" to get a green background
//background(0, 255, 0);
var rad = atan2(mouseY-windowHeight/2, mouseX-windowWidth/2);
var rx = (sx*5/7.2)/2;
var ry = (sy*5/7.2)/2;
var r = rx*ry / sqrt(sq(rx*sin(rad))+sq(ry*cos(rad)));
var d = sqrt(sq(mouseX-windowWidth/2)+sq(mouseY-windowHeight/2));
if (mouseIsPressed) {
if (d < r) {
if (right) touch = true;
else touch = false;
} else {
touch = false;
right = false;
}
} else {
touch = false;
right = true;
}
if (touch) {
count = 0;
if (sx < a*11/9) stretch += (a*4/3-sx)/8;
else stretch += a/72;
sx = a + stretch;
if (volume < 6) volume += 0.02;
else volume = 6;
} else {
count += 1;
if (count == 1) {
voice.amp(volume);
voice.play();
mochiT = 255;
volume = 1;
}
var decay = 1.5;
if (stretch > 0.1) stretch /= decay;
else stretch = 0;
if (count%2 == 0) {
if (count%4 == 0) sx = a + stretch;
else sx = a - stretch;
} else {
if ((count-1)%4 == 0) sx = a + stretch/decay;
else sx = a - stretch/decay;
}
}
sy = sqrt(pow(a, 3)/sx);
if (mochiT > 0) mochiT -= 32;
else mochiT = 0;
tint(255, mochiT)
if (vertical) {
px = (a-sx)/2;
py = (b-a)/2+(a-sy)/2;
image(motchin, 0, (b-a)/2, a, a*2/7.2);
} else {
px = (b-a)/2+(a-sx)/2;
py = (a-sy)/2;
image(motchin, (b-a)/2, 0, a, a*2/7.2);
}
tint(255, 255)
if (stretch < 1) picID = 0;
else picID = 1;
image(ars[picID], px, py, sx, sy);
}
function mousePressed() {
if (mute) {
unmute.play();
mute = false;
}
}