xxxxxxxxxx
var img;
var crowd;
var osc;
function preload() {
img = loadImage("IMG_7528_1.png");
crowd = loadSound('crowd.mp3');
}
function setup() {
createCanvas(720, 200);
pixelDensity(1);
img.loadPixels();
loadPixels();
crowd.loop();
osc = new p5.Oscillator(); // this actually sets up the oscillator
osc.freq(400); // this gives it an initial frequency
osc.amp(0); // this gives it an initial amplitude
osc.setType('triangle'); // mellowness to harshness 'sine', 'triangle, 'square', 'sawtooth';
osc.start();
}
function draw() {
for (var x = 0; x < img.width; x++) {
for (var y = 0; y < img.height; y++ ) {
// Calculate the 1D location from a 2D grid
var loc = (x + y*img.width)*4;
// Get the R,G,B values from image
var r,g,b;
r = img.pixels[loc];
// Calculate an amount to change brightness based on proximity to the mouse
var maxdist = 50;
var d = dist(x, y, mouseX, mouseY);
var adjustbrightness = 255*(maxdist-d)/maxdist;
r += adjustbrightness;
// Constrain RGB to make sure they are within 0-255 color range
r = constrain(r, 0, 255);
// Make a new color and set pixel in the window
//color c = color(r, g, b);
var pixloc = (y*width + x)*4;
pixels[pixloc] = r;
pixels[pixloc+1] = r;
pixels[pixloc+2] = r;
pixels[pixloc+3] = 255;
}
}
updatePixels();
var f = map(mouseX, 0, width, 200, 1000);
var a = map(mouseY, 0, height, 1., 0.);
osc.freq(f)
osc.amp(a);
}