Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all 2896 articles
Browse latest View live

minim duty cycle modulation

$
0
0

Hello. I'd like to patch a square waveform to modulate the dutyCycle parameter, like we can do with frequency modulation or amplitude modulation. I've seen something like Osc1.patch( Osc2.frequency ) or Osc1.patch( Osc2.amplitude ), but nothing about the duty cycle. Can someone help me ? Thanks, Laurent


ControlP5: Textarea

$
0
0

Does displaying an updating text at CP5 textarea is ambiguous? Is there other way to output a text in the display except using text() ? My issue with text is that, changing background is a must. Here's my code..

import controlP5.*;
import processing.serial.*;

String ser;
ControlP5 cp5;
Textarea myTextarea;

Serial port;
PImage bg;
void setup() {
  size(800, 480);
  bg = loadImage("APSS.png");
  port = new Serial(this, Serial.list()[0], 9600);
  cp5 = new ControlP5(this);

  myTextarea = cp5.addTextarea("txt")
    .setPosition(100, 100)
    .setSize(200, 200)
    .setFont(createFont("arial", 12))
    .setLineHeight(14)
    .setColor(color(128))
    .setColorBackground(color(255, 100))
    .setColorForeground(color(255, 100));
  ;
}

void draw() {
  ser = port.readString();
  delay(1000);
  drawBackground();

}

void drawBackground() {
  background(bg);
  myTextarea.setText(ser);
}

lines in a text file in Glabel

$
0
0

I have saved three lines in a text file and three Glabel, how to save every life in Glabel ??? That is: line 1 in Glabel 1 line 2 in Glabel 2 line 3 in Glabel3

the easiest it will cycle through "for", but as a change in the cycle variable name Glabel?

for(int i=0; i<+2;i++) { ['label'+і].setText(reader.readLine());} So not working

How to play a midi sound from soundcipher i.e a string sound and prolong this sound

$
0
0

Hello there! I have a question: when i play a string sound pressing a key using soundcipher the sound has a lenght and after a while it starts to glitching. how can i play longer notes , string sound notes, and have them stop when i just release the sound key, but keeping the quality of the string sound without glitches?

Averaging a few seconds of a video feed pixel

$
0
0

I would like to display a video pixel's average over a couple of seconds. What would be the best method to.

To make the question simple, let's say I want to get the color of the center pixel of a video feed and fill a rectangle the size of the window to this particular color. To mitigate the flickering of this colored rectangle which will naturally occur from the video, I would like to average, say, the color of the last 60 frames of the video and always have the rectangle displaying that averaged color.

What would be an approach to making this happen?

How to get one audio track to stop playing when another starts playing (Minim)

$
0
0

I have two soundtracks- one named rain and another named heartbeat. The goal is to trigger these audio files when a key is pressed. My problem is that I need to ensure that when one is playing the other stops, and for some reason processing isn't recognizing the .stop() or .pause() functions.

I'm only a beginner with code, so if anyone can let me know what I'm doing wrong/how I can fix this, I'd appreciate it a lot!

    import ddf.minim.spi.*;
    import ddf.minim.signals.*;
    import ddf.minim.*;
    import ddf.minim.analysis.*;
    import ddf.minim.ugens.*;
    import ddf.minim.effects.*;

    Minim minim;
    AudioPlayer heartbeat;
    AudioPlayer rain;

    void setup()
    {
      size(400, 600);
      minim = new Minim(this);
      heartbeat = minim.loadFile("heartbeat.mp3");
      rain = minim.loadFile("rainforest.mp3");
    }

    void draw() {
      background(0);
      stroke(255);
    }

    void keyPressed() {
      if (key == 'h') {
        heartbeat.rewind();
        heartbeat.play();
        if (key == 'p') {
            heartbeat.pause(); }
      }
       if (key == 'r' && !rain.isPlaying()) {
        rain.rewind();
        rain.play();
        if (key == 's') {
            rain.pause(); }
      }
    }

(CP5) How to convert the text in Texfield to a string

$
0
0

I'm trying to make a decimal/hexadecimal/binary converter for a college project using user input, but can't figure out any sort of way to actually use any of the stuff I input? Bear in mind I am useless at processing, so my code is messy and not complete.

Code:

import controlP5.*;

ControlP5 cp5;

void setup()
{
  size(700, 400);
  cp5 = new ControlP5(this);
  cp5.addTextfield("Decimal").setPosition(20, 100).setSize(200, 40).setAutoClear(false);
  cp5.addTextfield("Binary").setPosition(20, 170).setSize(200, 40).setAutoClear(false);
  cp5.addTextfield("Hexadecimal").setPosition(20, 240).setSize(200, 40).setAutoClear(false);
  cp5.addBang("DecimalS").setPosition(240, 100).setSize(200, 40);
  cp5.addBang("BinaryS").setPosition(240,170).setSize(200, 40);
  cp5.addBang("HexadecimalS").setPosition(240, 240).setSize(200, 40);
}

//Hexadecimal button
//Hexadecimal to Decimal conversion
public void HexadecimalS()
{
int num = 0, power = 0, res = 0;
String hex = (cp5.get(Textfield.class, "Hexadecimal").getText(), 360,130);

for(int i = hex.length()-1; i >= 0; i--)
{
  char dec = hex.charAt(i);
  String s1 = hex.substring(i, i+1);

  switch(dec)
  {
    case 'A' : num = 10; break;
    case 'B' : num = 11; break;
    case 'C' : num = 12; break;
    case 'D' : num = 13; break;
    case 'E' : num = 14; break;
    case 'F' : num = 15; break;
    default  : num = Integer.parseInt(s1);
  }
  res = res + ((num)*(int)(Math.pow(16,power)));
  power++;
}
println(res);

//Hexadecimal to Binary conversion
String bin = "";
    String binFragment = "";
    int iHex;
    hex = hex.trim();
    hex = hex.replaceFirst("0x", "");

    for(int i = 0; i < hex.length(); i++){
        iHex = Integer.parseInt(""+hex.charAt(i),16);
        binFragment = Integer.toBinaryString(iHex);

        while(binFragment.length() < 4){
            binFragment = "0" + binFragment;
        }
        bin += binFragment;
    }
    println(bin);
}


//Decimal button
//Decimal to binary conversion
public void DecimalS()
{
int deci = 142, res1 = 0, decim = deci;

String s2 = new String("");

while(deci > 0)
{
  res1 = deci%2;
  s2 = s2 + (Integer.toString(res1));
  deci = deci/2;
}

for(int i = s2.length()-1; i>=0; i--)
{
  print(s2.charAt(i));
}

println("");

//Decimal to hexadecimal conversion
String decHex = Integer.toHexString(decim);
println(decHex);
}

//Binary button
//Binary to decimal conversion
public void BinaryS()
{
String bin = cp5.get(Textfield.class, "Binary");
int binary = Integer.parseInt();
int power1 = 0, res2 = 0;
while(binary > 0)
{
  res2 = res2 + ((binary%2)*(int)(Math.pow(2,power1)));
  power1++;
  binary = binary/10;
}
println(res2);
}

How to change permission in terminal I cannot use VideoExport Library.

$
0
0

Hi guys,

I have a problem trying to use any of the code from the library of Video Export that they get the same error.

Even with the code from the website itself here > http://funprogramming.org/VideoExport-for-Processing/#examples ,

I also get error with permission thing.

say:

java.io.IOException: Cannot run program "/Users/Tuang/Desktop/DMA_WORKS/Work1_Facial Muscles/Cam_Rec/sketch_161027a/sketch_161027a.pde": error=13, Permission denied
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
    at com.hamoid.VideoExport.startFfmpeg(Unknown Source)
    at com.hamoid.VideoExport.initialize(Unknown Source)
    at com.hamoid.VideoExport.saveFrame(Unknown Source)
    at sketch_161027b.draw(sketch_161027b.java:51)
    at processing.core.PApplet.handleDraw(PApplet.java:2412)
    at processing.awt.PSurfaceAWT$12.callDraw(PSurfaceAWT.java:1540)
    at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:316)
Caused by: java.io.IOException: error=13, Permission denied
    at java.lang.UNIXProcess.forkAndExec(Native Method)
    at java.lang.UNIXProcess.<init>(UNIXProcess.java:247)
    at java.lang.ProcessImpl.start(ProcessImpl.java:134)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
    ... 7 more
VideoExport error: Ffmpeg failed. Study /var/folders/nq/xsfvm25d249181txfc2_c39c0000gn/T/untitled6197566133901091867sketches/sketch_161027b/camera.mp4.txt for more details.
Could not run the sketch (Target VM failed to initialize).
For more information, read revisions.txt and Help → Troubleshooting.

So I google

1) how to change permission -> which I found that my Mac cannot find the file it said there is no such file.

2) how to find a file in Mac with terminal -> later I found that it is about the space bar in a folder name, so I changed it.

Then, I was able to find a file and I guess I've already changed the permission with chmod 777, since I typed it in and has no error with finding the file thing. However, back to the Processing the same error still there.

3) Do I have FFmpeg ->Terminal said, it cann't find it so I download two versions and installed one but didn't work so try installed another, still didn't work.

Now.. I don't know what to do. Please help! The error still here.


Processing.sound looping SoundFile

$
0
0

I want to loop a SounFile so that it starts over once the SoundFile plays. What am I doing wrong?

void mouseReleased() {
 if (mouseX > 25 && mouseX < 75 && mouseY > 25 && mouseY < 75) {
     if (value1 == 0)
      Sewer.loop();
    else
    Sewer.stop();
  }
}

I've also tried different variations like

void mouseReleased() {
 if (mouseX > 25 && mouseX < 75 && mouseY > 25 && mouseY < 75) {
     if (value1 == 0)
loop();
      Sewer.play();
    else
    Sewer.stop();
  }
}

Trouble with window size when using SecondApplet

$
0
0

First off I am new to processing and GUI in java. I am trying to port a program I made in matlab (I know what you are thinking, but it was due to the fact I had to take a class that used it for my degree, and since it has a super simple GUI maker) to java so I can make an executable from it and distribute it.

Now the issue I am having is for some reason the settings function under the SecondApplet class seems to affect the window that is made using the original setup function. So when the program is ran, the window is reduced to a super small ~100x100 size even if both size calls are size(1280,650), as well the second window now is the correct size. But if the settings function is commented out, the original window is correct, and the new window will be ~100x100.

Goal is to have the button called "Suspension_Setup" open a new window to enter data about the suspension points on the users vehicle, and then save them in a file to be used by the original window to display what I am trying to do.

If anyone can, could I also get an answer on a good way to close the second window, while preserving the original window? I have looked, but the only thing I have seen is using PFrame, and I don't know if I need that yet.

This is super bare bones right now due to the fact I am trying to just make the framework for the interface first, and ran into this issue very quickly.

Code:

import controlP5.*;  // Importing GUI library

ControlP5 cp5;  // Creating a new object for the GUI library

CheckBox checkbox;  // Creating a checkbox object

DropdownList d1, d2;  // Creating a Dropdown menu object

boolean show = false;  // Setting the default state of the second window to false

void setup()
{
  size(1280, 650);
  cp5 = new ControlP5(this);
  checkbox = cp5.addCheckBox("checkBox")
    .setPosition(500, 500)
    .setColorForeground(color(120))
    .setColorActive(color(255))
    .setColorLabel(color(255))
    .setSize(40, 40)
    .setItemsPerRow(3)
    .setSpacingColumn(30)
    .setSpacingRow(20)
    .addItem("0", 0)
    .addItem("50", 50)
    .addItem("100", 100)
    .addItem("150", 150)
    .addItem("200", 200)
    .addItem("255", 255);

  // create a DropdownList
  d1 = cp5.addDropdownList("myList-d1").setPosition(500, 20);

  formatDropdown(d1); // customize the first list

  // create a second DropdownList
  d2 = cp5.addDropdownList("myList-d2").setPosition(500, 80);

  formatDropdown(d2); // customize the second list

  // create a new button with name 'buttonA'
  cp5.addButton("Suspension_Setup")
    .setPosition(0, 0)
    .setSize(80, 30);
}


void formatDropdown(DropdownList ddl)
{
  // a convenience function to customize a DropdownList
  ddl.setSize(200, 200);
  ddl.setBackgroundColor(color(190));
  ddl.setItemHeight(30);
  ddl.setBarHeight(30);
  ddl.setCaptionLabel("dropdown");
  for (int i = 0; i < 40; i++)
  {
    ddl.addItem("item " + i, i);
  }
  //ddl.scroll(0);
  ddl.setColorBackground(color(60));
  ddl.setColorActive(color(255, 128));
  ddl.close();

  // remove items from the pulldown menu  by name
  // d1.removeItem("item "+cnt);

  // add new items to the pulldown menu
  // int n = (int)(random(100000));
  // d1.addItem("item "+n, n);
}

void keyPressed()  // Might be used in future for shortcuts or special features
{

}

// function Suspension_Setup will receive changes from controller with name Suspension_Setup
public void Suspension_Setup(int theValue) {
  println("a button event from Suspension_Setup: "+theValue);
  show = true;
  String[] args = {"TwoFrameTest"};
  SecondApplet sa = new SecondApplet();
  PApplet.runSketch(args, sa);
}

void controlEvent(ControlEvent theEvent)
{
  // DropdownList is of type ControlGroup.
  // A controlEvent will be triggered from inside the ControlGroup class.
  // therefore you need to check the originator of the Event with
  // if (theEvent.isGroup())
  // to avoid an error message thrown by controlP5.

  if (theEvent.isGroup())
  {
    // check if the Event was triggered from a ControlGroup
    println("event from group : "+theEvent.getGroup().getValue()+" from "+theEvent.getGroup());
  } else if (theEvent.isController())
  {
    println("event from controller : "+theEvent.getController().getValue()+" from "+theEvent.getController());
  }
}

void draw()
{
  background(0);
}


public class SecondApplet extends PApplet
{
  public void settings()
  {
    size(1280, 650);
  }
  public void draw()
  {
    if (show)
    {
      background(255);
      noFill();
      ellipse(100, 50, 10, 10);
    }
    show = false;
  }
}

Thank you for the help!

G4P with PeasyCam not working on Mac

$
0
0

PeasyCam works only intermittently when I create a GWindow. The G4P with PeasyCam example does not work for me either.
Just calling GWindow.getWindow causes the problem.

How can I control my particles in one window from another window via the mouse?

$
0
0

I am not sure if I am missing something specific to the toxi library, but I keep getting a ConcurrentModificationException when I try to control my particles in my secondary window via the mouse in my primary window. The crash seems to be random, sometimes it crashes on one click, sometimes I can drag the particles around for a second or two either way I can;t seem to figure it out. Can anyone help, please?

Particles p;
AttractionBehavior mouseAttractorP;
Vec2D mousePos;
FinalPanel tp;

void setup() {
  size(1024, 768, P3D);
  frameRate(60);
  tp = new FinalPanel(400,400);
  surface.setTitle("Touch Panel");

}

void draw() {
  background(0, 0, 0);
}



void mousePressed() {
  mousePos = new Vec2D(mouseX, mouseY);

  if (mouseButton == LEFT) {
    // create a new attraction force field around the mouse position
    mouseAttractorP = new AttractionBehavior(mousePos, 250, 7);
    p.physics.addBehavior(mouseAttractorP);
  }

  if (mouseButton == RIGHT) {
    // create a new repulsion force field around the mouse position
    mouseAttractorP = new AttractionBehavior(mousePos, -33, -1);
    p.physics.addBehavior(mouseAttractorP);
  }
}

void mouseDragged() {
  // update mouse attraction focal point
  mousePos.set(mouseX, mouseY);
}

void mouseReleased() {
  // remove the mouse attraction when button has been released
  p.physics.removeBehavior(mouseAttractorP);
}


import toxi.geom.*;
import toxi.physics2d.*;
import toxi.physics2d.behaviors.*;
import toxi.math.*;
import megamu.mesh.*;



class Particles {
  final PApplet g;
  int NUM_PARTICLES;
  VerletPhysics2D physics;
  AttractionBehavior mouseAttractor;
  float [][] pos;
  float eSize;
  float xOff;

  Delaunay delaunay;
  int [] polygons;


  Particles(PApplet _p) {
    g = _p;
    xOff = 0;


    NUM_PARTICLES = 666;
    eSize = 1;
    physics = new VerletPhysics2D();
    physics.setDrag(0.7);
    physics.setWorldBounds(new Rect(0, 0, width, height));
    physics.addBehavior(new GravityBehavior(new Vec2D(-0.00007, -0.0003f)));
    for (int i = 0; i<NUM_PARTICLES; i++) {
      addParticle();
    }
  }


  void addParticle() {
    VerletParticle2D p = new VerletParticle2D(Vec2D.randomVector().scale(133).addSelf(width / 2, height/2));
    physics.addParticle(p);
    // add a negative attraction force field around the new particle
    physics.addBehavior(new AttractionBehavior(p, 13, 0.3f, 3f));
  }

  void drawParticles() {
    // store particles delaunayitions to do delaunay triangulation
    pos = new float[NUM_PARTICLES][2];

    for ( int i=0; i<NUM_PARTICLES; i++) {
      // particle system using verlet integration
      VerletParticle2D p = physics.particles.get(i);
      g.pushStyle();
      g.fill(255, 33);
      g.ellipse(p.x, p.y, g.noise(xOff) * 13, g.noise(xOff) * 13);
      g.popStyle();

      pos[i][0] = physics.particles.get(i).x;
      pos[i][1] = physics.particles.get(i).y;
    }
  }


  // delaunay triangulation logic taken from here :
  // http://www.openprocessing.org/sketch/43503
  void drawLines() {
    // delaunay triangulation
    delaunay = new Delaunay(pos);
    // getEdges returns a 2 dimensional array for the lines
    float[][] edges = delaunay.getEdges();
    for (int i=0; i<edges.length; i++)
    {
      // use the edges values to draw the lines
      float startX = edges[i][0];
      float startY = edges[i][1];
      float endX = edges[i][2];
      float endY = edges[i][3];
      float distance = dist(startX, startY, endX, endY);
      // remap the distance to opacity values
      float trans = 255-map(distance, 0, 33, 33, 0);
      // stroke weight based on distance
      // fast invert square root helps for performance
      float sw = 3f/sqrt(distance*2);
      g.ellipseMode(CENTER);

      g.pushStyle();
      g.strokeWeight(sw);
      g.stroke(g.noise(1)*233);
      g.fill(g.random(255), g.random(255), g.random(255));
      g.noFill();
      g.ellipse(startX, startY, eSize, eSize);
      g.popStyle();
      //pushStyle();
      //stroke(200, 3);
      //noFill();
      //bezier(startX, startY, endX, mouseY, width/2, mouseY, width/2, height/2);
      //popStyle();
    }
  }
}



class FinalPanel extends PApplet {
  int w, h;

  public FinalPanel(int _w, int _h) {
    super();
    w = _w;
    h = _h;
    PApplet.runSketch(new String[]{this.getClass().getName()}, this);
  }

  public void settings() {
    size(w, h, P3D);
  }

  public void setup() {
    blendMode(ADD);
    surface.setTitle("Final Panel");
    surface.setLocation(0, 0);
    p = new Particles(this);
  }

  void draw() {
    background(0);
    p.physics.update();
    p.drawParticles();
    p.drawLines();
  }
}

Is it possible to twist/bend/stretch/change shape of images with processing? If so where to start?

$
0
0

Particularly looking to stretch/modify different sections of the image differently

Also looking to do this with live video, will this make it more difficult?

Cheers, Woody

G4P GPanel example.

$
0
0

It's probably very simple to find but google did not help :-( I want to do simple panels overlapping and changing ... Where are the GPanel examples?

Thank you. David.

Clear the stage with HYPE framework

$
0
0

Hi guys,

I'm new to the forum and hope one of you can help me. I started working with processing after quite some time and love the ease of use. Also started with the HYPE framework and am amazed at the possibilities.

I want to know how to clear the stage before a draw loop. I have a perlin noise field and want to rotate the arrows, based on the z value of the perlin noise. It draws the stage, but with every loop, it keeps adding more lines. I somewhat understand what's going on, since I keep on adding more and more objects to H with each loop. But I can't find how to remove all objects or clear the stage for that matter.

Hopefully one of you can help me out, since I'm not finding anything in the documentation so far. Thanks!

import hype.*;

float inc = 0.05;
float scl = 10;
int cols,rows;
float zOff, xOff, yOff = 0;
HRect d;


void setup() {
    size(500,500);

    smooth();

    cols = floor(width/scl);
    rows = floor(height/scl);

    H.init(this).background(#ffffff).autoClear(true);


}

void draw(){

    yOff = 0;

    for (int y = 0; y < rows; ++y) {

        xOff = 0;

        for (int x = 0; x < cols; ++x) {

            float r = noise(xOff, yOff, zOff) * 255;

            d = new HRect();
            d
                .loc(x*scl, y*scl)
                .fill(#000000)
                .size(1,scl)
                .strokeWeight(0)
                .rotate(r);
            ;

            xOff += inc;

            H.add(d);

        }

        yOff += inc;
    }

    H.drawStage();



    zOff +=0.1;

}

Amplitude of sound file instead of Audio In using Sound library

$
0
0

Hi,

I can do an amplitude analysis of Audio In (the microphone) without issue, by using Amplitude in the Processing 3 Sound library. amp.input() accepts an input sound source, but the only example code I have been able to find uses Audio In as the input. How can I analyze a sound file on my computer instead of Audio In?

Processing will not Export

$
0
0

First time in the forum, so please move this if it's in the wrong spot.

When I try and export my application I get an "Error during export" message, but it doesn't give and error code or anything, I am on windows 10 64 bit, latest drivers and latest processing version.

Here is my code in case that helps

/**
Mouse Press.
Move the mouse to position the shape.
Press the mouse button to invert the color.
*/
import processing.serial.*;

Serial port;
int led;

void setup() {
  size(640, 360);
  noSmooth();
  fill(126);
  background(102);
  port = new Serial(this, "COM3", 9600);
  port.bufferUntil('\n');
}

void draw() {
  if (mousePressed) {
    stroke(255);
    led = 1;
    port.write(led);
  } else {
    stroke(0);
    led = 0;
    port.write(led);
  }
  line(mouseX - 66, mouseY, mouseX + 66, mouseY);
  line(mouseX, mouseY - 66, mouseX, mouseY + 66);
}

Thanks, any help would be much appreciated

How to get an octave based frequency spectrum from the FFT in Minim

$
0
0

I want to create audio visuals like the bars visual that is commonly used in music videos. Minim has an FFT that gets the amplitude of each frequency band, but each band is evenly spaced. So the result is that the bars are mostly showing only the high frequencies, and the mid and low frequencies are bunched up on the left. I tried this, but I'm not good with logarithms and have no clue what the correct math to calculate this should be, and it didn't really work:

import ddf.minim.analysis.*;
import ddf.minim.*;

Minim minim;
AudioPlayer song;
FFT fft;

// the number of lines/bands to draw
int bands = 512;

float a = (log(20000 - 20) / log(bands));

void setup()
{
  size(512, 200);

  minim = new Minim(this);

  song = minim.loadFile("test.mp3", 2048);
  song.loop();

  fft = new FFT(song.bufferSize(), song.sampleRate());
}

void draw()
{
  background(0);
  stroke(255);

  fft.forward(song.mix);

  for(int i = 0; i < bands; i++)
  {
    // calculate the frequency for the current band on a logamorithmic scale
    float freq = pow(i, a) + 20;

    // get the amplitude at that frequency
    float amplitude = fft.getFreq(freq);

    // convert the amplitude to a DB value.
    // this means values will range roughly from 0 for the loudest
    // bands to some negative value.
    float bandDB = 20 * log(2 * amplitude / fft.timeSize());
    // so then we want to map our DB value to the height of the window
    // given some reasonable range
    float bandHeight = map( bandDB, 0, -150, 0, height );

    // draw the band as a line
    line(i, height, i, bandHeight);
  }
}

I don't even know if it can be done using the FFT in Minim because there might not be enough bands calculated for the lower frequencies. If not, what can I use to accomplish this?

webcam light-drawing

$
0
0

...basically I want to go on with a tutorial I found. My aim is to draw a continous curve by capturing light(brigthness) via the webcam. The problem I have at the moment is that the drawn ellipse is always refreshed, so I don't see a curve but just a circle... Thanks!

import processing.video.*; Capture cam; int x,y;

void setup (){ size (640,480); frameRate (30); background (0);

printArray (Capture.list()); //choose Webcam, change according the size! //cam = new Capture (this, 640,480, "Logitech QuickCam Express/Go",30); cam = new Capture (this, 640,480, "Integrated Camera",30); cam.start(); }

void draw (){

if (cam.available()){ cam.read(); cam.loadPixels(); float maxBri = 0.0; int theBrightPixel=0; for (int i=0; i<cam.pixels.length; i++){ if(brightness(cam.pixels[i]) > maxBri){ //find the brightest maxBri = brightness (cam.pixels[i]); theBrightPixel =i; //store id of brightest pixel } } x= theBrightPixel % cam.width; //find x with modolo y= theBrightPixel /cam.width; //find y with int, row

} image (cam,0,0); fill (255,0,0); ellipse (x,y,20,20); }

Minim Waveform problem

$
0
0

Hi all !

i've been coding in processing for a few month now and i'm starting to use minim to add sound in my sketches yet i'm totally new to this library and afters hours of strugling i can't find a way to solve my problem: here is my basic code

import ddf.minim.*;
Minim minim;
AudioPlayer groove;
float x, y, a, b, c, d, z;
PFont police;
PFont polisse;
String DISASTERPEACE;
String HLD;

void setup() {
  size(600, 600);
  minim = new Minim(this);
  groove = minim.loadFile("groove.mp3", 1024);
  groove.loop();
  background(0);
  textAlign(CENTER);
  emissive(0, 26, 51);
 police=createFont("drifter.ttf", 32);
 polisse=createFont("DF.ttf", 25);
   textFont(police);
 HLD="Hyper Light Drifter";
  DISASTERPEACE="DISASTERPEACE";
  smooth();
  stroke(random(0, 255), random(0, 255), random(0, 255));

  for (int i=0; i<40; i++)
  {
    fill(random(0, 255), random(0, 255), random(0, 255));
    ellipse(x, y, z, z);
    ellipse(a, b, z, z);
    ellipse(c, d, z, z);
    line(x, y, a, b);
    line(x, y, c, d);
    line(c, d, a, b);
    x=random(0, 600);
    y=x+20;
  a=x-20;
    b=random(0, 600);
   c=b+20;
    d=b-20;
    z=3;
  }
  fill(255);
    textSize(12);
  text(HLD, 300, 275);
   textSize(30);
  text(DISASTERPEACE, 300, 313);
  //save("ESSAIS10.jpg");
}

so i simply want the line to react to the playing music, i've read a ton of minim releated stuff and saw all the exemples about it and yet i can't manage to make thoose line vibrate to the music

i've tried many things but nothing worked.

thanks for your help

Viewing all 2896 articles
Browse latest View live