xxxxxxxxxx
763
let autho
let begin = true;
let main = false
i = 0;
let arr = []
let foo;
let artwork = false;
let listen;
let synth, soundLoop, filter;
let song;
let rates = 1;
let blnd = []
let mode;
let xoff = 0.0;
let finRate = 0;
let intervalInBeats;
let intervalInMIDI;
let intervalInFinale;
let intervalInSound;
let MIDIenv;
let rand1
let rand2
let rand3
let rand4
let rand5
let rand6
let morePain = ['Pain/Liberty.jpg',
'Pain/Rembrandt.jpg',
'Pain/adam.jpg',
'Pain/birth.png',
'Pain/night.jpg',
'Pain/raft.jpg',
'Pain/rembrandt_1.jpg',
'Pain/rom.jpg',
'Pain/ur.jpg']
let painN;
let bright
let type;
let pain;
let pain2
//let shape;
let imOver
let a;
let b;
let c;
let d;
let sh2;
let talkBitch = true;
let beatsYas = false;
let MIDIYas = false;
let soundYas = false;
let finaleYas = false;
let fourCall = false;
let fiveCall = false;
let sixCall = false;
let sevenCall = false;
let eightCall = false;
let nineCall = false;
let showText = true;
let beatsIndex
let beatsNote
let MIDINote
let notePattern = [52, 53, 55, 57, 59, 60, 62, 64, 65, 67, 69];
//let MIDINotes = [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5];
let soundIndex;
let soundNote;
let finaleIndex;
let finaleNote;
let arrColour
let col
let poo
let opp
let poo2
let col2
let col3
let col4
let rat
let onS
let offS
// spotify
let newData
let tempo
let live
let s = new SpotifyWebApi()
let mySong
let songID = ""
let ColH
let ColS
let ColB
let radiusSize
let radiusRatio = 1
function getURLQuery(u) {
let q = window.location.hash.substring(1)
let v = q.split('&')
for (let i = 0; i < v.length; i++) {
let pair = v[i].split("=")
if (pair[0] == u){return pair[1]}
console.log('done auth')
}
return false
}
s.setAccessToken(getURLQuery('access_token'))
function searchAudioFeatures() {
s.getAudioFeaturesForTrack(songID, function(err, data) {
if (err) console.error(err)
else {
mySong = returnData(data)
console.log('song', mySong)
tempo = Math.round(mySong.tempo)
live = Math.round(mySong.liveness)
}
})
}
function returnData(responseData){
return responseData
}
function getCurrentTrack() {
s.getGeneric("https://api.spotify.com/v1/me/top/tracks?limit=1&time_range=long_term", function(err, data) {
if (err) console.error(err)
else {
newData = data
console.log(data)
songID = newData.items[0].id
console.log(songID)
searchAudioFeatures(songID)
}
}
)
}
function preload() {
painN = floor(random(0, morePain.length-1))
// console.log(painN)
psych = loadJSON("Psych.json")
afinn = loadJSON("afinn111.json")
song = loadSound('Background.mp3');
type = loadFont("Kenia-Regular.ttf")
pain = loadImage(morePain[painN])
pain2 = loadImage(morePain[painN])
sh2 = loadImage("Adj-6_102.png")
onS = loadImage('Speak-01.png')
offS = loadImage('Speak-02.png')
}
function setup() {
canvas = createCanvas(windowWidth, windowHeight);
textFont(type)
textLeading(500)
rectMode(CENTER);
angleMode(DEGREES)
frameRate(24)
amplitude = new p5.Amplitude();
foo = new p5.Speech(); // speech synthesis object
let lang = navigator.language || 'en-US'
let listen = new p5.SpeechRec(lang, gotSpeech);
song.amp(0.3)
song.loop();
// fill(255)
// shape = rect(0, 0, windowWidth, windowHeight, 40) //, height/10
rat = pain.width/windowWidth
if (windowWidth/windowHeight > 1.5) {
ratio = pain.height / pain.width
pain.width = windowWidth
pain.height = windowWidth * ratio
}
else if (windowWidth/windowHeight <= 1.5) {
ratio = pain.width / pain.height
pain.height = windowHeight
pain.width = windowHeight * ratio
}
rand1 = random(0, width-width/2.5)
rand2 = random(0, height-height/3)
rand3 = random(0, width-width/1.2)
rand4 = random(0, height-height/2)
rand5 = random(0, width-width/2.5)
rand6 = random(0, height-height/1.7)
//shape = rect(width/2, height/2, windowWidth, windowHeight, height/5)
pain2.width = pain.width * 1.5
pain2.height = pain.height * 1.5
pain2.mask(sh2)
//pain.mask(shape)
let continuous = true;
let interim = false;
listen.start(continuous, interim);
let intervalInBeats = 0.5;
beatsLoop = new p5.SoundLoop(onBeatsLoop, intervalInBeats);
MIDIenv = new p5.Envelope(0.1, 0.9, 1, 0.1);
let intervalInMIDI = 2;
MIDILoop = new p5.SoundLoop(onMIDILoop, intervalInMIDI);
MIDIsynth = new p5.MonoSynth('triangle');
MIDIsynth.amp(0.3)
let intervalInSound = 0.7 - finRate;
soundLoop = new p5.SoundLoop(onSoundLoop, intervalInSound);
let intervalInFinale = 1.2;
finaleLoop = new p5.SoundLoop(onFinaleLoop, intervalInFinale);
synth = new p5.MonoSynth();
synth.amp(0.2);
function gotSpeech() {
console.log(listen.resultString)
if (listen.resultString == 'yes' && !artwork) {
rates += 0.03
typing()
next()
}
if (listen.resultString == 'no' && !artwork) {
rates -= 0.03
next()
}
if (listen.resultString == 'begin') {
begin = false;
main = true;
}
}
}
function next() {
let val = round(random(psych.personality_test.length))
i = val
if(talkBitch == true) {
foo.speak(psych.personality_test[val]);
}
txt.value = psych.personality_test[i];
song.rate(rates)
}
function draw() {
background(198, 70, 26);
let level = amplitude.getLevel();
MIDIenv.setADSR(0.7/arr.length, 0.9 * finRate, 1, 2 * arr.length * 10)
intervalInBeats = intervalInBeats / arr.length;
intervalInMIDI = intervalInMIDI / arr.length ;
intervalInSound = (intervalInSound / arr.length) / finRate;
intervalInFinale = (intervalInFinale / arr.length) / finRate;
xoff = xoff + 0.01;
let n = noise(xoff) * width;
let m = noise(xoff) * width;
let textinput = txt.value;
let words = textinput.split(/\W/);
image(pain, 0, 0)
//let begin == true; let main == false
if (begin == true) {
// autho = createA(str(authURL + authRedirect), "authorise Spotify")
// autho.id("authenticate")
// autho.position(width/2-50, height*2/3-50)
// autho.style("font", type )
textAlign(CENTER, CENTER);
fill(255)
textAlign(CENTER, CENTER);
textSize(75)
text("listen to yourself", width/2, height/2)
// fill(0)
// let f = rect(width/2, height/2, 500, 50)
// f.mouseClicked (getCurrentTrack)
textSize(25)
text("ANSWER 'YES' or 'NO'", width/2, height*4.5/5)
text("SAY 'BEGIN' TO START", width/2, height*4.8/5)
stroke(255)
line(width/2-110, height*4.65/5, width/2+110, height*4.65/5)
}
else {
// autho.position(width+50, height+50)
pain.loadPixels()
loadPixels()
// let r = pain.pixels[i]
// pixels(3, 5) = pain.pixels(3, 5)
if (beatsYas) {
col = pain.get(arr[beatsIndex] * 100, arr[beatsIndex] * 60)
poo = map(arr[beatsIndex], -5, 5, 0, windowWidth)
opp = map(arr[beatsIndex], -5, 5, windowWidth, 0)
poo2 = poo * 2
col2 = pain.get(poo - 100, poo - 100)
col3 = pain.get(poo, arr[beatsIndex] * 100)
col4 = pain.get(arr[beatsIndex] * 50, arr[beatsIndex] * 90)
arrColour = map(arr[beatsIndex], -5, 5, 0, 255)
strokeWeight(0.5)
stroke(col3)
line(0, poo, width / 2, poo + 10)
line(0, poo + 80, 0, poo)
line(400, poo, 700, poo * 6)
line(width / 2 + 40, 0, width / 2 + 40, height)
line(0, height / 2 + 1000, width, height / 2 + 100)
// console.log('poo', poo)
// console.log('col', col)
// console.log('col3', col2)
// console.log('col2', col3)
// console.log('arr', arrColour)
strokeWeight(0.5)
stroke(col2)
line(col[2], arrColour * 10, height, poo)
line(poo2, 0, col3[1], poo)
line(col2[0], col3[2], poo2, 0)
line(width / 2, height / 2, poo, col3[0])
line(arrColour * 10, 0, opp + 70, poo2)
line(width / 2 + 500, 0, width / 2 + 500, height)
line(0, height / 2 + 500, width, height / 2 + 500)
strokeWeight(0.5)
stroke(col)
line(width, 0, width / 2, opp)
line(width / 2, height / 2, col[0], 0)
line(width, col2[2], height / 2, poo2)
line(arrColour, arrColour, arrColour + height, height)
line(height, 0, poo, col[1])
line(width / 2 + 880, 0, width / 2 + 880, height)
line(0, height / 2 + 60, width, height / 2 + 60)
//HERE HER HEREHEEREsxeftguyhcrdftvgy
//HERE
//HERE
//HERE
//HERE
if (arr.length > 7) {
push()
blendMode(BURN)
noStroke()
fill(155, arrColour , arrColour, 70)
circle(width/2, height - (arr[beatsIndex] * 50), arr[beatsIndex] * 500 )
circle(width/2, (arr[beatsIndex] * 50), arr[beatsIndex] * 500 )
pop()
}
}
if (MIDIYas) {
console.log("fuckMIDI")
blend(pain, (notePattern[beatsIndex]*10), m, width/25, height/50+notePattern[beatsIndex]*2, rand1+width/3, rand2+m * level/ 5, n, height/4, DARKEST )
blend(pain, width/3+arr[beatsIndex], height/3, width/5, height/5+arr[beatsIndex], rand3+width/9+notePattern[0] + n / 4, rand4+height/13+notePattern[1], width/5, height/7, ADD)
push()
blendMode(OVERLAY)
fill(poo * (190 / 255), poo, poo * (105 / 255), 35)
rect(width / 2, height / 2, width, height)
//pop()
//push()
translate(100, 200)
// blendMode(OVERLAY)
// image(pain2, 0, 0)
pop()
}
if (soundYas) {
console.log("fuck sound")
blend(pain, width/3+arr[beatsIndex], height/3, width/5, height/5+arr[beatsIndex], rand5+width/9+notePattern[1], rand6+height/3+notePattern[2], width/3, height/7, OVERLAY)
push()
blendMode(BURN)
fill(poo * (190 / 255), poo, poo * (105 / 255), 35)
rect(width / 2, height / 2, width, height)
//pop()
//push()
translate(200, 50)
// blendMode(OVERLAY)
// image(pain2, 0, 0)
pop()
}
if (fourCall){
console.log("fuck4")
blend(pain, width-(notePattern[beatsIndex] * level / 1000), height/5, width/10+notePattern[beatsIndex]*2, height/5+notePattern[beatsIndex]*2, rand1+width/5+notePattern[2], rand2+ m /4 * level * 2, width/2, height/3, OVERLAY)
}
if (fiveCall){
console.log("fuck5")
blend(pain, width-(notePattern[beatsIndex]), level/ 20, width/5+notePattern[beatsIndex]*2, height/15+notePattern[beatsIndex]*2, rand3+n, rand4+height*3/4+notePattern[7], n, height/10, ADD)
}
if (sixCall){
console.log("fuck6")
blend(pain, (notePattern[beatsIndex]*20), height/2, n, height/50+notePattern[beatsIndex]*2, rand5+width*2/3+notePattern[3], rand6+height/4+notePattern[0], n/20, m * level/ 6, ADD )
}
if (sevenCall){
blend(pain, width-(arr[beatsIndex]+arrColour),height/5+arrColour, width/5, height/5+arr[beatsIndex]*2, rand1+width*2/3+notePattern[5] - n, rand2+height*3/4-notePattern[3] - m /10, width/20 + n, height/20 + m/1.5, OVERLAY)
}
if (eightCall){
console.log("fuck7")
blend(pain, width-(notePattern[beatsIndex]*10), height/5, width/10+notePattern[beatsIndex]*2, height/5+notePattern[beatsIndex]*2, rand3+width/5+notePattern[2] - n /2, rand4+height*2.5/4-notePattern[5], width/10 + n * level/ 5, height/3, OVERLAY)
}
if (nineCall){
blend(pain, n , m, width/5, height/2, rand5+width/5 , rand6+m - 100 , width/5 - m /20, m, ADD)
}
if (finaleYas) {
blend(pain, n * level, m * level, n * level, m * level, 0, 0, n * level * 50, m * level * 50, OVERLAY)
}
fill(255)
textAlign(CENTER, CENTER);
if (showText == true){
stroke(0)
strokeWeight(0.5)
textSize(55)
text(psych.personality_test[i], windowWidth / 2, windowHeight / 2, windowWidth - 30, 500);
noStroke()
textAlign(LEFT);
textSize(15);
text((random(words)), windowWidth / 2 - 25, 20)
text((random(words)), windowWidth / 2 - 25, 30)
text((random(words)), windowWidth / 2 - 25, 40)
text((random(words)), windowWidth / 2 - 25, 50)
textSize(20)
text(arr.length, windowWidth / 2 - 70, 32.5)
textSize(5)
text((psych.personality_test[i - 1]), windowWidth / 2 + 70, 32, 20, 20);
}
if (!finaleYas){
stroke(255)
strokeWeight(3)
line(windowWidth / 2 - 30, 10, windowWidth / 2 - 30, 55)
line(windowWidth / 2 + 30, 32.5, windowWidth / 2 + 50, 32.5)
line(windowWidth / 2 + 30, 10, windowWidth / 2 + 30, 55)
line(windowWidth / 2 - 30, 32.5, windowWidth / 2 - 50, 32.5)
}
if(talkBitch == true) {
// ON image
image (onS, (width/2)-15, height-60, 30, 30)
}
else if (talkBitch == false) {
// OFF image
image (offS, (width/2)-15, height-60, 30, 30)
}
}
//corners
fill(198, 70, 26);
noStroke()
push()
translate(0,0)
rotate(0)
beginShape()
vertex(0, height / 5)
bezierVertex(0, height/10, height/10, 0,height / 5, 0)
vertex(0,0)
endShape(CLOSE)
pop()
push()
translate(width,0)
rotate(90)
beginShape()
vertex(0, height / 5)
bezierVertex(0, height/10, height/10, 0,height / 5, 0)
vertex(0,0)
endShape(CLOSE)
pop()
push()
translate(width,height)
rotate(180)
beginShape()
vertex(0, height / 5)
bezierVertex(0, height/10, height/10, 0,height / 5, 0)
vertex(0,0)
endShape(CLOSE)
pop()
push()
translate(0,height)
rotate(270)
beginShape()
vertex(0, height / 5)
bezierVertex(0, height/10, height/10, 0,height / 5, 0)
vertex(0,0)
endShape(CLOSE)
pop()
}
function typing() {
let textinput = txt.value;
let words = textinput.split(/\W/);
console.log("JUST WORDS:", words);
let totalScore = 0;
for (let i = 0; i < words.length; i++) {
var word = words[i].toLowerCase();
if (afinn.hasOwnProperty(word)) {
let score = afinn[word];
console.log("SCORED WORD:", word, score);
totalScore += Number(score);
}
}
console.log("TOTAL SCORE:", totalScore)
if (totalScore != 0) {
arr.push(totalScore)
console.log("final array:", arr)
}
if (arr.length > 0) {
beatsCall()
}
if (arr.length > 1) {
MIDICall()
}
if (arr.length > 2) {
soundCall()
}
if (arr.length > 3) {
fourCall = true;
}
if (arr.length > 4) {
fiveCall= true;
}
if (arr.length > 5) {
sixCall = true;
}
if (arr.length > 6) {
sevenCall = true;
}
if (arr.length > 7) {
eightCall = true;
}
if (arr.length > 8) {
nineCall = true;
}
if (arr.length > 9) {
finaleCall()
rates = n;
finRate = 0.0001
}
}
function beatsCall() {
console.log("beats called")
if (!beatsLoop.isPlaying) {
beatsLoop.start();
}
}
function MIDICall() {
console.log("Tone called")
if (!MIDILoop.isPlaying) {
MIDILoop.start();
}
}
function soundCall() {
console.log("sound called")
if (!soundLoop.isPlaying) {
soundLoop.start();
}
}
function finaleCall() {
console.log("finale called")
artwork = true;
if (!finaleLoop.isPlaying) {
finaleLoop.start();
}
}
function onBeatsLoop(timeFromNow) {
beatsIndex = (beatsLoop.iterations - 1) % arr.length;
synth.amp(0.8)
beatsNote = (arr[beatsIndex] * 60);
// console.log(arr[beatsIndex])
synth.play(beatsNote, 0.6, timeFromNow, 1 / 2);
beatsYas = true;
}
function onMIDILoop(timeFromNow) {
for (let index = 0; index <= arr.length; index++) {
MIDIIndex = map(arr[index], -5, 5, 0, 10)
// console.log(MIDIIndex)
MIDINote = midiToFreq(notePattern[MIDIIndex]);
MIDIsynth.play(MIDINote, 0.8, timeFromNow);
}
MIDIYas = true;
}
function onSoundLoop(timeFromNow) {
soundIndex = (soundLoop.iterations - 1) % arr.length;
soundNote = (arr[soundIndex] * 100);
synth.play(soundNote, 0.8, timeFromNow, 1 / 4);
soundYas = true;
}
function onFinaleLoop(timeFromNow) {
finaleIndex = (finaleLoop.iterations - 1) % arr.length;
finaleNote = (arr[finaleIndex] * 200);
synth.play(finaleNote, 0.6, timeFromNow, 1 / 16);
finaleYas = true;
showText = false;
}
function mouseClicked(onS){
// if (mouseX == onS & mouseY == onS) {
// if (mouseY == & mouseY ==){
talkBitch = !talkBitch
// }
// }
// if (mouseY < width/2){
// getCurrentTrack()
// }
}