focus τ
selectedtimerOntStarttStopmodenModenotesplayBoolplayCntconstantsrandomsgetXY
let selected = 4;
let timerOn = false;
let tStart = 0;
let tStop = 0;
let mode = 5;
let nMode = 15;
let notes = [];
let playBool = false;
let playCnt = 0;
let r1 = 60,
r2 = 100,
r3 = 100;
let constants = [2, 0.5, 0.4];
let t = 0;
let cnt = 0;
function preload() {
userStartAudio();
i = int(random([33, 45, 48]));
notes[0] = loadSound("/assets/" + str(i) + ".mp3");
notes[1] = loadSound(
"/assets/" + str(i + 2) + ".mp3"
);
notes[2] = loadSound(
"/assets/" + str(i + 4) + ".mp3"
);
notes[3] = loadSound(
"/assets/" + str(i + 5) + ".mp3"
);
notes[4] = loadSound(
"/assets/" + str(i + 7) + ".mp3"
);
notes[5] = loadSound(
"/assets/" + str(i + 9) + ".mp3"
);
notes[6] = loadSound(
"/assets/" + str(i + 11) + ".mp3"
);
notes[7] = loadSound(
"/assets/" + str(i + 12) + ".mp3"
);
notes[8] = loadSound(
"/assets/" + str(i + 14) + ".mp3"
);
notes[9] = loadSound(
"/assets/" + str(i + 16) + ".mp3"
);
}
function randoms() {
c1 = [random(100, 185), random(150, 205), random(150, 205)];
c2 = [random(140, 155), random(150, 205), random(150, 225)];
constants = [int(random(3, 10)), random(0.1, 0.5), random()];
}
function setup() {
userStartAudio();
mode = random([12, 8, 7, 11]);
cnv = createCanvas(windowWidth, windowHeight);
randoms();
r2 = height / 10;
r3 = min(width, height) / 4;
timers = [0.5, 1, 2, 4, 5, 10];
textAlign(CENTER);
rectMode(CENTER);
noStroke();
for (let i = 0; i < notes.length; i++) {
notes[i].amp(0.2);
}
}
function draw() {
translate(width / 2, height / 2);
noStroke();
t += 0.002;
currentTime = millis() / 1000;
n = 400;
for (let i = 0; i < notes.length; i++) {
if (notes[i].isPlaying) {
if (notes[i].currentTime() > 2) {
notes[i].stop();
}
}
}
if (tStop < currentTime && timerOn) {
for (let i = 0; i < n; i++) {
fill(0 + i / 1.5);
circle(0, 0, max(width, height) * 2 - (i * max(width, height)) / (n / 2));
playBool = true;
}
if (frameCount % 60 === 1) {
notes[int(tau[playCnt])].play();
if (playCnt < tau.length - 1) {
playCnt++;
} else {
timerOn = false;
}
}
} else {
frameCount = 0;
for (let i = 0; i < n; i++) {
fill(c1[0] - i / 5, c1[1] - i / 5, c1[2] - i / 5);
circle(0, 0, max(width, height) * 2 - (i * max(width, height)) / (n / 2));
}
beginShape();
noFill();
stroke(255, 255, 255, 100);
strokeWeight(0.25);
for (
let i = 0;
i < timers[selected] * (Math.PI * 2);
i += (Math.PI * 2) / 400
) {
getXY(i);
vertex(x, y);
}
endShape();
}
x = -width / 2 + width / 20;
y = -height / 2 + height / 20;
fill(c2[0], c2[1], c2[2], 100);
circle(x, y, width / 40);
for (let i = 0; i < nMode; i++) {
if (i === mode) {
fill(c1[0] - 0, c1[1] - 0, c1[2] - 0, 100);
} else {
fill(c1[0] - 100, c1[1] - 100, c1[2] - 100, 100);
}
x = (((-nMode + 1) / 2) * height) / 40 + (height / 40) * i;
y = -height / 2 + height / 20;
circle(x, y, height / 40);
fill(0, 0, 0, 10);
x = width / 2 - width / 20;
y = -height / 2 + height / 20;
if (timerOn && !(tStop < currentTime && timerOn)) {
circle(x, y, height / 40);
fill(c1[0], c1[1], c1[2], 50);
text("X", x, y + 5);
}
}
for (let i = 0; i < 6; i++) {
if (i === selected) {
fill(c1[0] - 100, c1[1] - 100, c1[2] - 100);
} else {
fill(c1[0] - 150, c1[1] - 150, c1[2] - 150);
}
x = -r1 + (r1 / 2) * i;
y = height / 2 - r2;
circle(x, y, 30);
fill(c1[0] + 20, c1[1] + 20, c1[2] + 20);
if (timers[i] === 1) {
text("τ", x, y + r1 / 15);
} else {
text(str(timers[i]) + "τ", x, y + r1 / 15);
}
}
if (tStop < currentTime && timerOn) {
}
noStroke();
for (let i = 0; i < timers[selected] * (Math.PI * 2); i += 0.01) {
noStroke();
if (tStart + i * 60 < currentTime && timerOn) {
fill(c2[0], c2[1], c2[2]);
s = 2.5 + 2.2 * Math.sin(i * 2);
getXY(i);
circle(x, y, s);
} else {
fill(c2[0], c2[1], c2[2], 10);
s = 0;
}
noFill();
stroke(c2[0], c2[1], c2[3]);
}
x = -r1 + (r1 / 2) * 6;
y = height / 2 - r2;
fill(c1[0], c1[1], c1[2], 50);
circle(x, y, 30);
fill(c1[0] - 110, c1[1] - 110, c1[2] - 110);
if (!timerOn) {
triangle(x - r1 / 9, y + r1 / 6, x - r1 / 9, y - r1 / 6, x + r1 / 6, y);
} else {
rect(x, y, r1 / 4, r1 / 4);
}
}
function getXY(i) {
if (mode === 0) {
x = -width / 2 + 20 + (i * (width - 40)) / (Math.PI * 2 * timers[selected]);
y = r3 * Math.sin(t + i) * Math.cos(i / constants[0]);
}
if (mode === 1) {
x = -width / 2 + 20 + (i * (width - 40)) / (Math.PI * 2 * timers[selected]);
y = r3 * Math.sin(t + i - constants[0] * constants[1]);
}
if (mode === 2) {
x =
(r3 - i) * Math.cos(t + i * (selected + int(constants[0]))) * Math.cos(i);
y =
(r3 - i) * Math.cos(t + i * (selected + int(constants[0]))) * Math.sin(i);
}
if (mode === 3) {
x =
((sqrt(i) * r3) / 8) * Math.cos(2 * t + i + constants[0] * constants[1]);
y =
((sqrt(i) * r3) / 8) * Math.sin(2 * t + i + constants[0] * constants[1]);
}
if (mode === 4) {
x =
(r3 + (i * sqrt(i)) / 8) * Math.cos(i * constants[0] + t) -
constants[1] *
r3 *
Math.sin(i * constants[2] + t) *
Math.cos(i / constants[2]);
y =
(r3 + (i * sqrt(i)) / 8) *
Math.sin(i / constants[0] + t * constants[2]) *
Math.cos(i / constants[1] + t * constants[2]);
}
if (mode === 5) {
x = -width / 2 + 20 + (i * (width - 40)) / (Math.PI * 2 * timers[selected]);
y = (r3 / 2) * Math.sin(i + t) - (r3 / 3) * Math.cos(t + i / constants[0]);
}
if (mode === 6) {
x = (r3 - i) * Math.cos(i + t);
y = (r3 / 2) * Math.sin(i + t) - (r3 / 2) * Math.cos(t + i / constants[0]);
}
if (mode === 7) {
x = (r3 - i * 2) * Math.cos(i + t * 2 + constants[2]);
y = (r3 / 2) * Math.sin(i + t * 2 + constants[2]);
}
if (mode === 8) {
x = r3 * Math.sin(i * i + t * 2 + constants[2]);
y = r3 * Math.sin(i + t + constants[2]) * Math.cos(i * i);
}
if (mode === 9) {
x = r3 * Math.cos(i * i + (t * constants[0]) / 4 + constants[2]);
y = r3 * Math.cos(i + t) - (r3 / 5) * Math.cos(i * i);
}
if (mode === 10) {
x =
r3 * Math.cos(i + t / 2 + constants[2]) -
(r3 / 4 - i * 5) * Math.sin(i + constants[2]);
y = r3 * Math.sin(i - t + constants[2]);
}
if (mode === 11) {
x = r3 * Math.cos(i + t / constants[0]) - (r3 / 4 - i * 5) * Math.sin(i);
y = r3 * Math.sin(i - t) - (r3 / 4 - i * 5) * Math.cos(i);
}
if (mode === 12) {
x =
r3 * Math.cos(i + t) -
(r3 / 4 - (i * width) / 200) *
Math.sin(t + i + constants[0] + constants[0]);
y =
Math.sin(t + i + constants[0]) *
(r3 - (i * height) / 60) *
Math.cos(t + i + constants[0]);
}
if (mode === 13) {
x =
r3 * Math.cos(i + t) -
i * 2 * Math.sin(t + i) * Math.cos(t + i * constants[2]);
y =
r3 * Math.sin(t + i) -
i * 2 * Math.cos(t + i) * Math.sin(t + i * constants[0]);
}
if (mode === 14) {
x = r3 * Math.cos(i - t) - (r3 / 2) * Math.sin(i - t);
y =
r3 * Math.sin(i - t) -
i * 4 * Math.cos(i - t) * Math.sin(i * constants[0] - t);
}
}
function mousePressed() {
x = -r1 + (r1 / 2) * 6;
y = height / 2 - r2;
if (
mouseX - width / 2 < x + r1 / 4 &&
mouseX - width / 2 > x - r1 / 4 &&
mouseY - height / 2 < y + r1 / 4 &&
mouseY - height / 2 > y - r1 / 4
) {
timerOn = !timerOn;
tStart = millis() / 1000;
tStop = tStart + timers[selected] * (Math.PI * 2) * 60;
}
for (let i = 0; i < 6; i++) {
x = -r1 + (r1 / 2) * i;
y = height / 2 - r2;
if (
mouseX - width / 2 < x + r1 / 4 &&
mouseX - width / 2 > x - r1 / 4 &&
mouseY - height / 2 < y + r1 / 4 &&
mouseY - height / 2 > y - r1 / 4
) {
selected = i;
timerOn = false;
}
}
for (let i = 0; i < nMode; i++) {
x = (((-nMode + 1) / 2) * height) / 40 + (height / 40) * i;
y = -height / 2 + height / 20;
if (
mouseX - width / 2 < x + height / 80 &&
mouseX - width / 2 > x - height / 80 &&
mouseY - height / 2 < y + height / 80 &&
mouseY - height / 2 > y - height / 80
) {
mode = i;
}
}
x = -width / 2 + width / 20;
y = -height / 2 + height / 20;
if (
mouseX - width / 2 < x + height / 80 &&
mouseX - width / 2 > x - height / 80 &&
mouseY - height / 2 < y + height / 80 &&
mouseY - height / 2 > y - height / 80
) {
randoms();
}
x = width / 2 - width / 20;
y = -height / 2 + height / 20;
if (
mouseX - width / 2 < x + height / 80 &&
mouseX - width / 2 > x - height / 80 &&
mouseY - height / 2 < y + height / 80 &&
mouseY - height / 2 > y - height / 80
) {
tStop = millis() / 1000 - Math.PI * 2 * timers[selected] * 60;
tStart = tStop - Math.PI * 2 * timers[selected] * 60;
}
}
function keyPressed() {
if (keyCode === 32) {
randoms();
mode = int(random(0, nMode - 0.001));
}
if (keyCode === 67) {
tStop = millis() / 1000 - Math.PI * 2 * timers[selected] * 60;
tStart = tStop - Math.PI * 2 * timers[selected] * 60;
}
}
tau =
"62831853071795864769252867665590057683943387987502116419498891846156328125724179972560696506842341359642961730265646132941876892191011644634507188162569622349005682054038770422111192892458979098607639288576219513318668922569512964675735663305424038182912971338469206972209086532964267872145204982825474491740132126311763497630418419256585081834307287357851807200226610610976409330427682939038830232188661145407315191839061843722347638652235862102370961489247599254991347037715054497824558763660238982596673467248813132861720427898927904494743814043597218874055410784343525863535047693496369353388102640011362542905271216555715426855155792183472743574429368818024499068602930991707421015845593785178470840399122242580439217280688363196272595495426199210374144226999999967459560999021194634656321926371900489189106938166052850446165066893700705238623763420200062756775057731750664167628412343553382946071965069808575109374623191257277647075751875039155637155610643424536132260038557532223918184328403978761905144021309717265577318723067636559364606039040706037059379915472451988277824994435505669582630311497144849083013919016590662337234557117781501967635092749298786385101208018554033422780196976480257167232071274153202094203638859111923978935356748988965107595494536942080950692924160933685181389825866273540579783042095043241139320481160763003870225067648600711752804949929465278283985452085398455935647095632720186834432824398491726300605723659491114134996770109891771738539913818544215950186059106423306899744055119204729613309982397636695955071327396148530850557251036368351493457819555455876001632941200322904983843464344295447002828839471370963227223147051042669514836989368770466478147882866690955248337250379671389711241984384443685451005085137753435809892033069336099772544655835721715687676559359533629082019077675727219013601284502504102347859697921682569772538912084839305700444213223726134885572440783898900942474275739219127287438345749355293151479248277817316652919916267809560551801989315281579025389367967051914196516452410449788154534389565369652029539818052802727888749106101364069925049034987993028628596183813185018744433929230314197167748211957719195459509978603235078569362765373677378855483119837118504919079188620999450493616919745472893916973076734724452521982492161024877687809024882730995255615954313828719954002592321788833897371116968127068441444516569772963169120570120336854789045349353577905042770450999093334556479729131922327097724611549129960711872691363486482250301521389589021931921880504577594217862913382737344574978811202030066172358573618417495218356498771780194298193519705227310995637862595696433659978974453176097151280285409551102647592829030474924687290857168895905317356421022827094714790462268543322042719390724628859049698743742202915308071805598688074840146211570781243967748956169569793666428914277375038870128604369063820969620107412293613498385563823958799041228393268575088812874902474363843599967820318391236293502853824794978818143729884639231358904161902931004504632077638602841875242757119132778755741660781395841546934443651251993230028430061360768954690984052108293318504029948857014650373320042648681763814209726634692993029078115925371220110162133175939963271494727681051429182057941282802219424125608780795190313543154008406757398720144611175263527188437462502942410658563836523722517346431583968296976583289412191505413914441835134233445821963381830560347013425497166445743670418707931450242167158302739764182888420135020669342206282534222739817317032796630039403303023370342875315236703113017698199797199647746910566632710152958370717864523709792642658661797141284093505181418309628330997189232743605419639886198489779151425657811846466521945994241688671465309787647823865194927334611672082856277660640764980751797048748834058265531236187546888061414938422403826040660760395242202200898586430321684889719275339677904573695662471053164262899153714524866883786079372852486821546453956056146378308822020893646505432402105304544223320793331146185094221115707526933641306219793053837241129538625141172713240371162014587213197529722358209066977006922273153735064988833360792531595754371121691059308253308170612286888637173539502913228136014004757553182688034254989408411244610779891226281422540008157094665398781629093292917615945416533661268657175713966104716178661315148135909143275505084042299115231628005002524571882604329431019585184619815930947522510353135027150356593329095583490022599229780609279894265924214680875037914719229178038779426223580859565712950064063973830280574161";