xxxxxxxxxx
230
let emojis = ['🌵', '🌲', '🌳', '🌴', '🌱', '🌿', '☘️', '🍀', '🍃', '🌾', '🌷', '🌹', '🌺', '🌸', '🌼', '🌻', '🍄', '🍅', '🥕', '🍓'];
let creatures = ['🐛', '🐝', '🐞', '🐌', '🐜', '🕷', '🦗', '🐍', '🦎', '🐀', '🐇', '🦋', '🦔', '🕊'];
let gridSpacing = 40
let poly;
let delay;
let reverb;
let alls = [];
let notes = ["C","E","G","A","H"]
let octave = 4
let direction = 1
let W = window.innerWidth;
let H = window.innerHeight;
let i = 0;
function setup() {
poly = new p5.PolySynth( );
delay = new p5.Delay();
reverb = new p5.Reverb();
delay.process(poly, 0.50, 0.5, 500);
reverb.process(poly, 4, 2);
for (let y = 0; y < H - (gridSpacing * 4); y += gridSpacing) {
for (let x = gridSpacing; x < W - gridSpacing*2; x += gridSpacing) {
let p;
/*
if(window.chrome){
if(i > cts.length-1){
p = document.createElement("p"); //createP(".");
}else{
p = document.createElement("p");;
}
}else{
p = document.createElement("p");
}
*/
p = document.createElement("p");
p.innerHTML = ".";
i++
p.id = i;
p.style.left = x + "px";
p.style.top = y + "px";
p.addEventListener("mousedown", changeEmoji);
document.body.appendChild(p);
//p.position(x, y)
// p.mousePressed(changeEmoji)
//p.mouseOver(changeEmoji)
alls.push(p);
}
}
//background(222);
//console.log(alls.length);
}
function changeEmoji(e) {
userStartAudio();
//console.log(hasfood(this.id-1));
// do nothing when has food!
if( hasfood(this.id-1) ){ return;}
let randNote = floor(random(notes.length))
if(random(1)<0.1){
octave+= direction
}
if(octave >= 6){
direction = -1
}
if(octave <= 4){
direction = 1
}
let noisey = e.target.id / i;
console.log((int(noisey*10)+2) );
poly.play(notes[randNote] + (int(noisey*5)+4) , .15, 0, 0.25);
let remoji = randomEmoji();
//change the html inside of THIS p tag to be a new random emoji
// console.log(this);
this.innerHTML = remoji;
if(random()*100>80){
setAnimal(this.id);
}
}
function setAnimal(_id){
let randNote = floor(random(notes.length));
let dir = floor(random(2));
switch(dir){
case 0:
if(_id >=2 && hasfood(_id-2)){
// console.log("try left");
alls[(_id-2)].innerHTML =returnRandomAnimal(); // left
poly.play(notes[randNote] + (octave +2) , .15, 0, 0.25);
}
case 1:
if(_id < alls.length-1 && hasfood(_id)){
// console.log("try right");
alls[(_id)].innerHTML = returnRandomAnimal();// right
poly.play(notes[randNote] + (octave +2) , .15, 0, 0.25);
}
// todo > up down case!
}
}
function hasfood(_idx){
if(alls[_idx].innerHTML == "."){
return false; }else{
return true;
}
}
function returnRandomAnimal() {
return creatures[floor(random(creatures.length))];
}
//utility function
function randomEmoji() {
let output;
let rand = floor(random(emojis.length))
output = emojis[rand]
return output;
}
var myVar = setInterval(grow, 1100);
function grow(){
let cp = alls[int(random()*alls.length)];
//console.log(cp);
let cont = cp.innerHTML;
if(cont != "."){
// cp.html(".");
cp.innerHTML = ".";
let randNote = floor(random(notes.length));
poly.play(notes[randNote] + (octave -2) , .15, 0, 0.25);
}
}