xxxxxxxxxx
481
i = 0;
let arr = []
let foo;
let artwork = false;
let listen;
let synth, soundLoop, filter;
let song;
let rates = 0.5;
let blnd = []
let mode;
let type;
let pain;
let pain2
//let shape;
let imOver
let a;
let b;
let c;
let d;
let sh2;
let beatsYas = false;
let MIDIYas = false;
let soundYas = false;
let finaleYas = false;
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
function preload() {
psych = loadJSON("Psych.json")
afinn = loadJSON("afinn111.json")
song = loadSound('Pad-Solbath.wav');
type = loadFont("Kenia-Regular.ttf")
pain = loadImage("Rembrandt.jpg")
pain2 = loadImage("Rembrandt.jpg")
sh2 = loadImage("PNG_SEQ/Adj-6_101.png")
}
function setup() {
createCanvas(windowWidth, windowHeight);
textFont(type)
rectMode(CENTER);
angleMode(DEGREES)
foo = new p5.Speech(); // speech synthesis object
let lang = navigator.language || 'en-US'
let listen = new p5.SpeechRec(lang, gotSpeech);
song.amp(0.03)
song.loop();
// fill(255)
// shape = rect(0, 0, windowWidth, windowHeight, 40) //, height/10
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
}
//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.8;
beatsLoop = new p5.SoundLoop(onBeatsLoop, intervalInBeats);
MIDIenv = new p5.Envelope(0.5, 0.9, 1, 2);
let intervalInMIDI = 2;
MIDILoop = new p5.SoundLoop(onMIDILoop, intervalInMIDI);
MIDIsynth = new p5.MonoSynth('triangle');
MIDIsynth.amp(1)
let intervalInSound = 0.7;
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.3
next()
}
}
}
function next() {
let val = round(random(psych.personality_test.length))
foo.speak(psych.personality_test[val]);
i = val
txt.value = psych.personality_test[i];
song.rate(rates)
}
function draw() {
background(198, 70, 26);
let textinput = txt.value;
let words = textinput.split(/\W/);
image(pain, 0, 0)
pain.loadPixels()
loadPixels()
//, height/10
// for (let y = 0; y < height; y++) {
// for (let x = 0; x < width; x++) {
// let i = (x + y * width) * 4;
// 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(1)
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(1)
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(1)
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)
strokeWeight(1)
stroke(col4)
line(opp, 0, opp * 2 + 70, height - poo)
line(poo, poo, poo - 90, height)
line(0, col2[1] + 90, width - col2[1] + 90, col4[1] - 100)
line(opp * poo, 100 - poo2, width, poo2 - col3[1])
line(width / 2 - (poo * 2), 0, width / 2, height - 70)
// line(0, height/2, width, height/2)
push()
blendMode(BURN)
noStroke()
// line(arr[beatsIndex], beatsNote, arr[beatsIndex] + 100, beatsNote)
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) {
push()
blendMode(OVERLAY)
fill(poo * (190 / 255), poo, poo * (105 / 255), 35)
rect(width / 2, height / 2, width, height)
pop()
push()
translate(poo, 10 + col3[0])
blendMode(DODGE)
image(pain2, 0, 0)
pop()
// image(pain2, width/2+arr[beatsIndex]*100, 0, 100, height )
}
if (soundYas) {
}
if (finaleYas) {
}
// }
// }
// }
noStroke()
fill(255)
textAlign(CENTER, CENTER);
textSize(55)
text(psych.personality_test[i], windowWidth / 2, windowHeight / 2, windowWidth - 30, 500);
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);
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)
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 > 2) {
MIDICall()
}
if (arr.length > 12) {
soundCall()
}
if (arr.length > 16) {
finaleCall()
}
}
// this is called when arr
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;
}