xxxxxxxxxx
144
let width = 600;
let height = 600;
let fuego = [
"q",
"u",
"e",
" ",
"a",
"r",
"d",
"a",
" ",
"t",
"o",
"d",
"o",
];
let estado = [
"e",
"s",
"t",
"a",
"d",
"o",
" ",
"o",
"p",
"r",
"e",
"s",
"o",
"r",
];
let resolution = 90;
let dx = width / 1.5 / (resolution - 1);
let dy = height / 1.5 / (resolution - 1);
let v = 4;
let n = 0;
let n1 = 0;
let myFont;
let img;
let gif;
let sound;
let amplitude;
function preload() {
img = loadImage("door.png");
myFont = loadFont("Jabin-MediumSwash1.ttf");
gif = loadImage("fire_1_1.gif");
sound = loadSound('Queloqueme.m4a');
}
function setup() {
createCanvas(600, 600);
img.resize(width / 2, 0);
textFont(myFont);
textAlign(CENTER, CENTER);
frameRate (10);
sound.play();
sound.loop();
amplitude = new p5.Amplitude();
amplitude.setInput(sound);
}
function draw() {
background(0);
imageMode(CENTER);
img.loadPixels();
push();
translate(width / 4, height / 7);
for (let row = 0; row < resolution; row = row + 1) {
for (let col = 0; col < resolution; col = col + 1) {
let x = col * dx;
let y = row * dy;
let pixelSize = 1;
let pixelColor = img.get(x, y);
let scalebright = brightness(img.get(x, y));
textSize(v - 1 + scalebright / 5);
fill(pixelColor);
text(estado[n], x, y);
n = n + 1;
if (n > estado.length - 1) {
n = 0;
}
}
}
pop();
gif.loadPixels();
push();
soundLevel = amplitude.getLevel();
translate(width/6, height / 3);
for (let row = 0; row < resolution; row = row + 1) {
for (let col = 0; col < resolution; col = col + 1) {
let x = col * dx;
let y = row * dy;
let pixelSize = 1;
let pixelColor = gif.get(x, y);
let scalebright = brightness(gif.get(x, y));
let d = dist(mouseX, mouseY, x ,y)
textSize(v - 1 + scalebright / 5 + 0.05*d);
fill(pixelColor);
push()
translate(x, y)
scale(1.0, 1.5 + 20*soundLevel);
text(fuego[n1], 0, 0);
pop()
n1 = n1 + 1;
if (n1 > fuego.length - 1) {
n1 = 0;
}
}
}
pop();
}
function mousePressed() {
userStartAudio();
}