Loading...
Logo
Processing Forum
Hey,

I am trying to edit a preexisting code 'pointillism'. Instead of reacting to the location of the mouse, I am hoping to program it to react to a live audio input, something like the higher the frequency the smaller the circles. I am extremely new to this and have no idea where to start so any help would be amazing.

The code is below

 
// The next line is needed if running in JavaScript Mode with Processing.js
/* @pjs preload="yes.jpg"; */

PImage img;
int smallPoint, largePoint;

void setup() {
  size(1450, 800);
  img = loadImage("yes.jpg");
  smallPoint = 4;
  largePoint = 40;
  imageMode(CENTER);
  noStroke();
  background(255);
}

void draw() {
  float pointillize = map(mouseX, 0, width, smallPoint, largePoint);
  int x = int(random(img.width));
  int y = int(random(img.height));
  color pix = img.get(x, y);
  fill(pix, 128);
  ellipse(x, y, pointillize, pointillize);
}

Is anyone able to help me out here, I would greatly appreciate it!
And could anyone recommenced any good sites for beginner learning in this sort of area?
Thanks again! :)
 

Replies(6)

" And could anyone recommenced any good sites for beginner learning in this sort of area?"
Side bar of the site:
Tutorials
Examples
Books

About your problem: look at the Minim library shipped with Processing perhaps. There are lot of similar threads in this forum, too.

Thank you :)

I have looked at various other threads but I am unsure on how to apply it to my code, as i have zero idea about this! If anyone could tell me how you would go about it it would be much appreciated.

Thanks again for the feedback it was very useful.
You may try this.. I wonder whether I got your idea as you expect it to be though.. :)

import ddf.minim.*;

Minim minim;
AudioInput in;

PImage img;
int smallPoint, largePoint;

void setup() {
  size(640, 360);

  minim = new Minim(this);
  // use the getLineIn method of the Minim object to get an AudioInput
  in = minim.getLineIn();
  // uncomment this line to *hear* what is being monitored, in addition to seeing it
  in.enableMonitoring();

  img = loadImage("moonwalk.jpg");
  smallPoint = 4;
  largePoint = 40;
  imageMode(CENTER);
  noStroke();
  background(0);
}

void draw() {
  for(int i = 0; i < in.bufferSize() - 1; i++) {
    //ellipse(20,20,in.left.get(i)*200,in.left.get(i+1)*200);
    //ellipse(320,20,in.right.get(i)*200,in.right.get(i+1)*200);
    if((in.left.get(i)*200+in.left.get(i+1)*200/2) > 0){
      
      float pointillize = (in.left.get(i)*200+in.left.get(i+1)*200);
      
      int x = int(random(img.width));
      int y = int(random(img.height));
      color pix = img.get(x, y);
      fill(pix, 128);
      ellipse(x, y, pointillize, pointillize);
    }
  }
}
Thank you so much that's perfect! I have been trying to make the shapes fade over say... 5s or something, could you inform me on how to approach this?

Thanks again.
Note that using Minim makes the @pjs directive obsolete... (ie. no Minim in JS mode).
" fade over"
You probably need to create an object per shape, to manage a list of created shapes, and make them to evolve (changing their transparency, for example). When transparency reaches 0, delete the shape.