I would like to have an LED's intensity controlled by the volume from LineIn instead of the mouseY position that I have it controlled by now. Any suggestions?
Code:
import ddf.minim.*;
import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
Minim minim;
AudioInput in;
void setup()
{
size(1050, 550, P2D);
arduino = new Arduino(this, Arduino.list()[0], 57600);
for(int i = 0; i < in.bufferSize() - 1; i++)
{
ellipse(i, height/2 + in.left.get(i)*0, i+1, 0 + in.left.get(i+1)*height);
}
if(pmouseY!=mouseY){
// if the present mouseY value is different than the previous mouse value
// output this value to pin 3
arduino.analogWrite(3,mouseY);
How do I merge these two sketches to make the expanding circles in the 'RIPPLE' sketch animate according to voice activation, instead of the sine wave image that is in the 'SOUNDSCAPE' sketch now?
Is it possible to make the 'stars' 'twinkle' all over the screen when the mouseX position moves instead of the spotlight that I have going on right now? This is my sketch so far:
int numCircles = 500;
Circle[] circles = new Circle[numCircles];
void setup(){
size(1440, 800, P2D);
noFill();
smooth();
for (int i=0; i<numCircles; i++){
circles[i] = new Circle(random(width),random(height));
}
// Create buffered image for 3d cube
pg = createGraphics(width, height, P3D);
calc1 = new int[width];
calc3 = new int[width];
calc4 = new int[width];
calc2 = new int[height];
calc5 = new int[height];
colorMode(HSB);
fire = new int[width][height];
palette = new color[250];
// Generate the palette
for(int x = 0; x < palette.length; x++) {
//Hue 0 to 85: red to yellow
//Saturation is maximum: 255
//Lightness is 0..255 for x=0..128, and 255 for x=128..255
palette[x] = color(x/3, 255, constrain(x*3, 5, 255));
}
// this speeds up the effect by 10fps
for (int x = 0; x < width; x++) {
calc1[x] = x % width;
calc3[x] = (x - 1 + width) % width;
calc4[x] = (x + 1) % width;
}
// Output everything to screen using our palette colors
pixels[counter] = palette[fire[x][y]];
// Extract the red value using right shift and bit mask
// equivalent of red(pg.pixels[x+y*w])
if ((pg.pixels[counter++] >> 16 & 0xFF) == 128) {
// Only map 3D cube 'lit' pixels onto fire array needed for next frame
fire[x][y] = 128;
}
}
}
updatePixels();
}
if(keyPressed) {
if (key == 'a' || key == 'A') {
fill(0x90880000);
rect(random(height),random(width),random(height),random(width));
}
if (key == 'b' || key == 'B') {
fill(0x90000066);
rect(random(width),random(height),random(width),random(height));
}
if (key == 'c' || key == 'C') {
fill(0x90005500);
rect(random(height),random(width),random(height),random(width));
}
if (key == 'd' || key == 'D') {
fill(0x90330066);
rect(random(width),random(height),random(width),random(height));
}
if (key == 'e' || key == 'E') {
fill(0x90777777);
rect(random(height),random(width),random(height),random(width));
}
}
for (int i=0; i<numCircles; i++) {
circles[i].display(); // display all the circles
}
}
class Circle {
float x,y; // location
float dim; // dimension
color c; // color
Circle(float x, float y) {
this.x = x;
this.y = y;
dim = random(5);
c = color(random(55));
}
void display() {
float distance = dist(x,y,mouseX,mouseY); // distance between circle and mouse
if (distance < 355) { // if distance is smaller than 255
fill(355-distance);
} else { // if distance is bigger than 255
fill(c);
}
ellipse(x,y,dim,dim); // a circle at position xy
}
}
This may seem like a silly question, but I can't seem to find a straight or comprehensive answer in any of the tutorials or references.
I would like to add to generate an array of maybe 100 circles of random sizes (< 10 or 20) and in a random pattern all over a 1439, 800 window. I do not want them to move during the program, just generate at random every time the program runs anew. I also intend to use mouseX to control the colour which I would like to stay in the black and white range.
I think I can figure out the color part on my own but I really need help on figuring out the code to generate these circles. Any pointers at all would be much appreciated, but please keep it simple as I am just a student starting out and have a hard time understanding all of this.