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

cannot convert from element type object to aug3.arobjrct

$
0
0

cannot convert from element type object to aug3.arobjrct

what to do?


Several attractors using toxiclibs

$
0
0

Hello, I am trying to build an interactive installation as following:

There should be 12 attractors that attract particles depending on their color. I am trying to build 12 different particle systems of different colors that flow around the screen. When something is activated (e.g: mousePressed) the 12 attractors should attract the particles on their particle system.

I am trying to use toxiclibs in order to create the physics and attractors.

Someone did something similar or can help a little bit?

How can associate Amplitude analyze() (sound library) with a GImageButton (G4P library)

$
0
0

How can I associate the rms.input with a GImageButton?

I think that the problem is that if I have these arguments:

seq3.play(k, 1.0);
rms = new Amplitude(this);
rms.input(seq3);

in the setup() and I press a GImageButton of play, I obtain only 0.0 always, and if I change it to another position to activate them when I press play button an error appear. If I have the example Amplitude in Sound Library and I try to put in draw()

rms = new Amplitude(this); rms.input(sample);

everything crash with the following error:Untitled

I need to put and GImageButton to play the song and to start to analize de Amplitude. But if I put these like

public void setup() {
    size(640,360);
    sample = new SoundFile(this, "Seq3.aiff");
}

public void draw() {
    background(125,255,125);
    noStroke();
    fill(255,0,150);

    sum += (rms.analyze() - sum) * smooth_factor;

    float rms_scaled=sum*(height/2)*scale;

    ellipse(width/2, height/2, rms_scaled, rms_scaled);
    println(rms_scaled);
}

void handleButtonEvents(GImageButton button, GEvent event){
if(button == btnPlaySeq3){
    loop();
    seq3.play(k, 1.0);
    rms = new Amplitude(this);
    rms.input(seq3);
    }

everything crash and appear the same error. If I put

rms = new Amplitude(this); rms.input(sample);

in the setup() and only seq3.play(k, 1.0) in the handleButtonEvents like this

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

    sample = new SoundFile(this, "Seq3.aiff");

    rms = new Amplitude(this);
    rms.input(sample);
}

public void draw() {
        background(125,255,125);
        noStroke();
        fill(255,0,150);

        sum += (rms.analyze() - sum) * smooth_factor;

        float rms_scaled=sum*(height/2)*scale;

        ellipse(width/2, height/2, rms_scaled, rms_scaled);
        println(rms_scaled);
    }

void handleButtonEvents(GImageButton button, GEvent event){
if(button == btnPlaySeq3){
    loop();
    seq3.play(k, 1.0);
    }

if(button == btnStopSeq3){
    loop();
    seq3.stop();
    mode = 3;
  }

after press the play button only appears 0.0 and never change. Also, when the soundfile finish, an error appears and I need to reopen the file.

Note: I put only the main code of the problem because I have a lot of Tabs to create a visual interface

how can we change color of the GLabel i.e labels which appear in the sub window ?

How would something like this Moving Brand magic be made?

$
0
0

from 15 seconds and onwards processing is being used to make interactive graphics.

How was this made, I see ControlP5, but what else is in the making here?

I just want to say I'm just starting to understand processing and I freaking love it. Amazing piece of software!

Thank you so much!

Why does processing.sound make horrible screeching?

$
0
0

I am creating a click sound, and it works and plays (no looping), but as soon as the file is over, processing makes a horrible screech through my speakers. Very rarely it works with no screech, but more often than not it is there. Im sure it can't be good for the speakers...or my ears.

Why Libraries don't work in all Processing versions? Is there a "one time fix" ???

$
0
0

As a beginner i am exploring basics and few libraries.I am messed up that some libraries don't work which i feel are very useful for me.Many suggested using multiple versions of Processing.Can Processing makers come up with a fix to this ??? Processing is powerful and i don't take the Contributor's work so far for granted.But small/big problem like this annoy a lot and become hurdles from exploring the possibilities.

Colors from array running only once within draw()

$
0
0

Hi there guys,

Have been struggling with this piece of code. Basically creating an array of rotated rectangles in a circle. I want to use my specific color palette but since the code is in the draw() function it keeps changing the color on every frame. If I move to setup() the colors get distributed but my slider won't work.

How can I get multicolored rectangles that I can control with each rectangle having a random color pulled out from my array? Thanks!

import controlP5.*;

ControlP5 cp5;

// noise parameters
float xoff = 0.0;
float xincrement = 0.001;

// design parameters
int numberOfElements = 24;
float circularAngle = radians(360);


void setup() {
  size(1000, 1000, P3D);

  cp5 = new ControlP5(this);
  cp5.addSlider("numberOfElements")
    .setPosition(100, 50)
      .setRange(0, 255)
        ;
}


void draw() {
  background(0);
  noStroke();

  for (int i = 0; i < numberOfElements; ++i) {

    pushMatrix();

    //apply a noise or wiggle effect to the rectangles
    xoff += xincrement;
    float n = noise(xoff) * 5;

    //centre each rectangle and displace along Z-axis
    translate(width/2, height/2, 10);

    //rotate and space out equally
    rotate((circularAngle/numberOfElements)*i);

    // setting up my color array/palette
    color [] colarray = {
      #FFFFFF, #F7F7F7, #ECECEC, #333333, #0095a8, #00616f, #FF3300, #FF6600, #FFD800
    };
    int col = colarray[(int)random(0, colarray.length)];

    //ISSUE: This is where the color keeps changing on every frame as we are in draw() mode.
    //If i take the entire draw() code and put it in setup then it runs only once with no access to the slider
    //How do we get each rectangle with different colors as per my chosen color palette without changing on every frame?
    fill(col, 100);
    rect(10*n, 0, 20, 300);

    popMatrix();
  }
}

Fast Fourrier Transform fft

$
0
0

I want to do a fast fourier transform (fft) with 2^15 = 32768 bands. Even if it basically works I get often crashes while starting the sektch : Java(TM) Platform SE binary does not function So I need to start the same sketch 2 - 3 times before it runs. I am worrying because of stability issues?

A further question is: how can I determine when a new value for a frequency (fft - bin) is computed and available? this sketch gives every 1500 ms a new value because with 2^15 bands one fft frame computation needs 2*bands/sampleRate = 2 * 2^15 /44100 = 1.486 sec = 1486 ms. with frameRate 30 this is achieved within 45 frames so 1500 ms. Is there any event Detection for a new FFT frame or need I to count frames?

import processing.sound.*;

FFT fft;
AudioIn in;

int bands = 32768;
float[] spectrum = new float[bands];

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

   // Create an Input stream which is routed into the Amplitude analyzer
  fft = new FFT(this, bands);
  in = new AudioIn(this, 0);

   // start the Audio Input
  in.start();

   // patch the AudioIn
  fft.input(in);
}

void draw() {
  fft.analyze(spectrum);
  println("spectrum["+149+"]: "+spectrum[149]+" time: "+millis());
}

ControlP5 controller dynamically added when mouse clicked from class

$
0
0

Hi Everyone, I am on beginner level in processing and have been writing a code using ControlP5, yet having issues how to add a button in a class triggered by mouse click. Found this sourcehttps://forum.processing.org/one/topic/having-a-controlp5-controller-inside-a-class.html, which nearly answers my question, without mouseClick. I don't use processing in another environment (so eliminated static+PApplet parts completely). Was also checking the ControlP5 examples, but none of them use ControlEvent in class (or I couldn't find it with my beginner level). I have a solution, but outside of class. The final aim is to collect values assigned to the same objects coming from different controllers. And later on, want to compare those objects based on values. Right now, I only have one controller (textfield, but will create more) "assigned" to objects. Hope I make sense. Any help/recommendation/advice very much appreciated. Thank you!!! first part

import controlP5.*;
Object obj=new Object();
ControlP5 cp5;

int c=0; //object counter
int a=0; //attribute counter

PImage img;
ArrayList<Object> objSet=new ArrayList();
ArrayList<Textfield> t =new ArrayList();
ArrayList s=new ArrayList();
ArrayList temp=new ArrayList();

void setup() {
  size(640, 600);
  img= loadImage("room1.jpg");
  img.resize(320, 300);
  cp5=new ControlP5(this);
}

void draw() {
  background(0);
  image(img, 0, 0);
  //println(objSet.size());
  for (int i=0; i<objSet.size(); i++) {
    Object obj1=(Object) objSet.get(i);
    obj1.display();
  }
}

void mousePressed() {
  if (mouseX<320 && mouseY<300) {
    obj.press();
    a=0;
  }
}

void mouseReleased() {
  if (mouseX<320 && mouseY<300) {
    obj.release();
    objSet.add(obj);
    t.add(cp5.addTextfield("object"+c, 330, 10+c*100, 200, 20)
      .setId(c));
    c+=1;
  }
}

void controlEvent (ControlEvent theEvent) {
  println("got an event from controller id:" +theEvent.getId()+":"+ theEvent.getStringValue());
  temp.add(theEvent.getId()); //collected Id
  s.add(theEvent.getId(), theEvent.getStringValue()); //textField into arrayList
  int tempC=theEvent.getId(); //actual Id
  checker(s,temp,tempC);
  println(s);
}
//you have to fill in with data first, but responds to modification
ArrayList checker(ArrayList toFilter, ArrayList helperA, int helperN) { //removes false values
  int counter=0;
  for (int i=0; i<helperA.size(); i++) {
    if ((int)helperA.get(i)-helperN==0) {
      counter+=1;
      if (counter%2==0) {
        toFilter.remove(helperN+1);
        helperA.remove(i);
        counter=0;
      }
    }
  }
  return toFilter;
}

and the class itself: class Object {

  boolean done=false;
  //ArrayList<Object> objSet=new ArrayList();
  public ArrayList mouseV=new ArrayList();
  ArrayList<String> attributeN=new ArrayList();
  ArrayList attributeV=new ArrayList();

  Object () {
  }

  void press() {    //make first part of rect
    mouseV.add(new PVector(mouseX, mouseY));
    done=false;
  }

  void release() { //finish rect
    mouseV.add(new PVector(mouseX, mouseY));
    done=true;
  }


  PShape display() {
    PVector centroid= new PVector();
    PShape rect=new PShape();
    if (done==true) {
      noFill();
      stroke(0, 255, 0);
      for (int i=1; i<mouseV.size()+1; i+=2) {
        PVector v1= (PVector)mouseV.get(i-1);
        PVector v2= (PVector)mouseV.get(i);
        rect= createShape(RECT, v1.x, v1.y, v2.x-v1.x, v2.y-v1.y);
        shape(rect, 0, 0);
        centroid.x=(v1.x+v2.x)/2;
        centroid.y=(v1.y+v2.y)/2;
      }
    }
    return rect;
  }
}

Saito,objloader uv problem

$
0
0

Hello,i made i model that corresponds to my original model,it was based to the example of the saito library,but i want also to transfer the texture.I can take the uv in 3d space coordinates from the model,but i cannot correspond them to each face.The saito libary give me space coordinates but the processing takes 0,1 or 100,200.Here is the code.Can anyone help?I want this to be part of my degree.

Here is the code

import saito.objloader.*;

OBJModel model ;
OBJModel tmpmodel ;

float rotX, rotY;
float k = 0.0;

void setup()
{
  size(800, 600, P3D);
  frameRate(30);
  model = new OBJModel(this, "Model1.obj", "absolute", TRIANGLES);
  model.enableDebug();

  model.scale(100);
  model.translateToCenter();

  tmpmodel = new OBJModel(this, "Model1.obj", "absolute", TRIANGLES);
  tmpmodel.enableDebug();

  tmpmodel.scale(100);
  tmpmodel.translateToCenter();

  stroke(255);
  noStroke();
}



void draw()
{
  background(129);
  lights();

  pushMatrix();
  translate(width/2, height/2);
  beginShape(TRIANGLES);
  float face = model.getFaceCount();

  for (int i =0; i< face; i++) {

    PVector [] orgv = model.getFaceVertices(i);


    for (int k =0; k< orgv.length; k++) {

      PVector  uv = model.getUV(k);
      PVector m = new PVector();


      println("uv "+uv);
      m = orgv[k];
      //m.x= m.x+noise(100);

      //int g = i/3;

      vertex(orgv[k].x, orgv[k].y, orgv[k].z, uv.x, uv.y);
    }
  }

  endShape();
  popMatrix();

  pushMatrix();
  translate(width/2, height/2, 0);
  rotateX(rotY);
  rotateY(rotX);

  //model.draw();
  //tmpmodel.draw();
  //model.clear();
  popMatrix();
}

Thanks in advance

Array of points, nullpointer exception

$
0
0

Hello all; If you look at another one of my discussions you will see I have been working on a genetic algorithm. I currently am experiencing a problem whilst trying to plot points of data in another window I have created. I get a null pointer exception after a little bit while running the code. The points do not show up. Please take a look at the code and please advise. Thanks. import org.gicentre.utils.stat.*; //import graph library

    import g4p_controls.*;

    ArrayList<Ball> balls = new ArrayList(); // arraylist for ball objects
    ArrayList<Point> points = new ArrayList();
    float gcorX, gcorY; // goal coords
    int timeIter = 300; //time step- internal clock

    float bscore; //best score

    String[] str_a;   //one copy of scorelist (use to copies to determine best and worst)
    String[] str_b;   //one copy of scorelist (use to copies to determine best and worst)
    float[] scores;   //scorelist
    final int pop = 10; //population size- final bc it shouldnt be changed in the program
    int cur_sub;      //current iteration- OLD METHOD, but still in just in case
    public int gen_num = 0; //count generation number
    int countDone; // count how many balls in the population finished their run in that generation
    float diameter = 30;
    float globmin = 1000; //base var
    float [] generations; // array of generations

    GWindow window;

    Ball globalBall = new Ball(-1, "0"); // starter/ global best ball


    public void windowDraw(PApplet app, GWinData data) {

      app.background(0);
      app.stroke(255);
      app.strokeWeight(8);
      //app.point((gen_num*2), min(scores));
      for ( int j = 0; j < gen_num; j++ ) {
        points.add( new Point(gen_num*2, min(scores) ) );
      }

      for ( int i=0; i < points.size(); i++ ) points.get(i).display();
    }

    public void windowMouse(PApplet app, GWinData data, MouseEvent event) {
    }

    public void windowKey(PApplet app, GWinData data, KeyEvent event) {
    }

    void setup() {
      size(800, 800);
      background(0);

      generations = new float[gen_num]; // init generations with size

      window =  GWindow.getWindow(this, "Graph", 100, 50, 500, 500, JAVA2D);

      window.addDrawHandler(this, "windowDraw");
      window.addMouseHandler(this, "windowMouse");
      window.addKeyHandler(this, "windowKey");

      bscore = dist(0, 0, width, height); // calc score
      gcorX= random(width);
      gcorY= random(height);

      ellipseMode(CENTER);

      //begin init scorestrings
      str_a = new String[pop];
      str_b = new String[pop];
      scores = new float[pop];
      for (int j = 0; j<pop; j++) {
        str_a[j] = starterString();
        scores[j] = 0;
      }
      //end init scorestrings

      //for every done ball, add a new one/replace it
      cur_sub = -1;
      countDone = 0;
      for ( int i=0; i < pop; i++ ) balls.add( new Ball( i, str_a[i] ) );
    }


    //begin init of starter string( Initial) so that the mutation has a place to begin

    String starterString() {
      String mut = "" + char( '0' + int( random(4) ) ); //  + "00000000" ;
      return( mut );
    }

    //end init

    //begin init instructions and strings of values- cr and hr refer to the textlines explaining each movement. r is a placeholder string so that the strings return a value to it based on the results of the cr loop

    String hr( String cr ) {
      String r = "";
      for ( int t = 0; t < cr.length(); t++) {
        if ( cr.charAt(t) == '0' ) r+= 'N';
        if ( cr.charAt(t) == '1' ) r+= 'L';
        if ( cr.charAt(t) == '2' ) r+= 'R';
        if ( cr.charAt(t) == '3' ) r+= 'A';
      }
      return( r );
    }

    //end init instructions and cr/hr

    void draw() {
      background(0); //layer 2
      fill(255, 0, 0); //red
      //starting pad
      pushMatrix();
      stroke(255, 200);
      fill(0, 255, 0, 200);
      ellipse(width/2, height/2, 25, 25);
      popMatrix();
      //end starting pad


      String extra = ""; //message
      if ( bscore < 20 ) extra = "That's close enough! Click the mouse to move the goal."; //message

      //text inits and placements
      pushMatrix();
      fill(255, 0, 0);
      text("| Best ever: (" + hr(globalBall.genome) + ") = " + int(bscore) + " |", 50, 20 );
      popMatrix();

      pushMatrix();
      fill(255, 200);
      text("| key: A = accelerate, R = right, L = left, N = do nothing | ", 500, height-20);
      popMatrix();

      pushMatrix();
      fill(0, 0, 255);
      text(extra, 30, height -20);
      popMatrix();

      pushMatrix();
      fill(#3FB73F);
      text("| Generation " + gen_num+ " |", 280, 20 );
      text("| minimum of gen:" + (min(scores))+ " |", 400, 20); //why does this get a NullPointer Exception? and why does it not plot the points? Frustrated.
      text("| best:" + (bscore)+ " |", 600, 20);

      popMatrix();
      //end text inits and placements

      //globmin = min(globmin, min(scores));
      //text("globmin: " + globmin, 250, 34);


      //text for genome (hr/cr);
      for ( int tt=0; tt< pop; tt++) {
        fill (balls.get(tt).col);
        text( "(" + hr( balls.get(tt).genome ) + ")", 10, 48 + 14 * tt);
      }
      //text for genome (hr/cr);

      // If no ball, last ball is done, simulate next one.
      // If all balls done, simulate next generation.
      if ( countDone == pop ) { // balls.size() == 0 ) {
        while ( balls.size () > 0 ) balls.remove(0);
        //cur_sub++;
        // If all balls in this generation simulated, create next generation.
        //if ( cur_sub == gen_size ) {
        countDone = 0; // cur_sub = 0;
        //println( "Making next generation..." );


        // Always keep the best one, and toss the worse.
        arrayCopy( str_a, str_b ); //copy for scrambling later
        int bestIndex = 0;
        int worstIndex = 0;
        for ( int j = 0; j < pop; j++ ) {
          if ( scores[bestIndex] > scores[j] ) {
            bestIndex = j;
          } //getting best score for index

          if ( scores[worstIndex] < scores[j] ) {
            worstIndex = j;
          }
          //getting worst score for index
        }

        str_b[worstIndex] = str_b[bestIndex]; // Replace the worst with a copy of the best for breeding.

        // Scramble.
        for ( int j = 0; j < pop; j++ ) {
          str_a[j] = scramble( j, str_b[int(random(pop))], str_b[int(random(pop))] ); //scrambles initial a(stored in b) and replaces old a with new values
        }
        str_a[0] = str_b[bestIndex]; // Always keep the best.
        //Add all the balls to simulate.

        for ( int j = 0; j < pop; j++ ) {
          balls.add( new Ball( j, str_a[j] ) );
        }

        gen_num++; //increment generation counter

        //}
      }

      globalBall.render(); // draw best as red(see coloring above in beginning of draw)


      for ( int i=0; i < balls.size(); i++ ) balls.get(i).move(); //init move function for balls

      //begin goal init

      stroke(255);
      fill(255, 140);
      ellipse(gcorX, gcorY, diameter, diameter);

      //end goal init
    } // end draw

    String scramble( int which, String a, String b ) { // begin switching random values with substring r as the intermediate
      String r;
      int pos = int(random(min(a.length(), b.length())));
      r = a.substring(0, pos) + b.substring(pos, b.length());

      // Mutation! //change or add a random value between position 0 and length of r
      if ( random(1) < .5 ) {
        pos = int(random(r.length()));
        if ( random(1) < .5 ) {
          String mut = "" + char( '0' + int( random(4) ) );
          //println( "New Ball #" + which + ": Mutation! Adding a char: '" + mut + "' at position " + pos );
          r = r.substring(0, pos) + mut + r.substring(pos, r.length());
        } else {
          if ( r.length() > 0 ) {
            pos = int(random(r.length()-1));
            //println( "New Ball #" + which + ": Mutation! Losing the char at position " + pos );
            r = r.substring(0, pos) + r.substring(pos+1, r.length());
          }
        }
      }
      return( r ); //return the value to change the initial strings, reset w/change basically
    }

    //begin goal changing
    void mousePressed() {
      if (mouseButton == LEFT) {
        gcorX = random(width);
        gcorY = random(height);
        bscore = dist(0, 0, width, height);
        gen_num=0;
      }
    }
    //end goal changing


    class Ball {
      float x, y, z, v; //position related
      color col; //color of balls
      int current_inst;//current instruction
      int inst_time;//time between instructions
      int[] instructions; //array of instructions
      boolean dis = false; //disable ball
      int num; //uuuhhhh... i forget
      String genome; //GENOME
      int checknum; //check number for genome val to ensure smooth transition

      boolean inst_a, inst_b, inst_c; //instructions

      Ball(int cknum, String input) {
        //x = width/2;
        //y = height-20;
        x = width/2;
        y = height/2;
        if (cknum == -1) {
          x = -20;
          y = -20;
        }
        z =0;
        v = 0;

        col=color(random(40, 255), random(40, 255), random(40, 255), 200);
        inst_a = inst_b = inst_c = false;
        checknum = cknum; //making sure the numbers are the same to avoid glitches
        current_inst = 0;
        checkString( input );
        inst_time = millis() + timeIter;
        dis = false; //not disabled
        genome = input; //read input (parse/checkstring) and input it into the genome
      }

      void checkString(String in) {    //parsing function
        instructions = new int[in.length()];
        for ( int j = 0; j < in.length(); j++ ) {
          instructions[j] = int( in.charAt(j) - '0' );
        }
        //reads each character in the input string and puts it into instructions to be enacted
      }

      //begin scoreReport- uses an array to store the scores of the generation so that a best and a worst can be calculated

      void scoreRep() {
        scores[checknum] = dist(x, y, gcorX, gcorY) + genome.length(); //uses the distance between the translated ball(at x, y) and the goal at the gcords. //also, just added a penalty for length of genome, to try and promote a more direct route
        if ( scores[checknum] < bscore ) { // if the score is not the best score, change the scores to be recalculated by the next generation
          bscore = scores[checknum];
          globalBall.x = x;
          globalBall.y = y;
          globalBall.z = z;
          globalBall.col = col;
          globalBall.genome = genome; //checks the best aspects and records the genome, moves the values for position
        }
        countDone++;
        //if ( scores[checknum] < 20 ) {
        //  gcorX = random(width);
        //  gcorY = random(height);
        //}
        //balls.remove(0);
      }

      void move() {
        if ( millis() > inst_time && !dis) { // if the millisecond function (internal clock) is greater than the instance time and not disabled,
          inst_time = millis() + timeIter; //time between things
          if ( current_inst < instructions.length ) { //for every instruction in the instruction array
            int i = instructions[current_inst++]; //i is used to represent the value of the instruction at the current instruction value
            switch( i ) { //switches between actions for instruction. For example, if the value "i" is 2, it would enact instruction case 2. it reads and enacts on the instructions based on their value and reads them in sequence based on their position in the array
            case 0:
              // Do nothing.
              break;
            case 1:
              inst_a = !inst_a;
              break;
            case 2:
              inst_b = !inst_b;
              break;
            case 3:
              inst_c = !inst_c;
              break;
            default:
              //println( "Bum instruction: " + i )//instruction does not exist
              break;
            }
          } else { // Terminate run.
            inst_a=inst_b=inst_c=false;
            v=0;
            dis = true; // disable is true, end run, set v to 0, set instructions to false, and statify the scoreReport
            scoreRep();
          }
        }
        // movement systems follow.
        z+=(inst_a?-.1:0)+(inst_b?.1:0); //conditional operator/ternary operator. I dont want to explain it here, it is a shorthand. Go here for more: http://stackoverflow.com/questions/798545/what-is-the-java-operator-called-and-what-does-it-do
        v+=(inst_c?.1:0); //conditional
        //x=(x+width+v*cos(z))%width;
        //y=(y+height+v*sin(z))%height;
        x=x+v*cos(z); //math for x based on angle of movement (v is basically serving as a hypotenuse here)
        y=y+v*sin(z); //math for y based on angle of movement (v is basically serving as a hypotenuse here)
        v*=.99;
        render(); //calls a display function
      }
      void render() {
        pushMatrix(); //layer 4
        translate(x, y); //move the thing by the x and y calculated in move
        rotate(z); //rotate by z
        noStroke();
        fill(col); //fill with color

        if ( checknum==-1) fill(255, 0, 0); //if it is the best ball, color it red
        ellipseMode(CENTER); //put measurements in center
        ellipse(0, 0, 25, 25); //ball size
        stroke(0);//black edge

        noFill(); //triangle no fill
        triangle(-6, -5, 8, 0, -6, 5); //  triangle(-5, -8.66, 0, 10, 5, -8.66);
        popMatrix();
      }
    }

    class Point {

      float xpos;
      float  ypos;


      Point(float x, float y) {
        xpos = x;
        ypos = y;
      }

      void display() {
        pushMatrix();
        fill(255, 0, 0);
        strokeWeight(6);
        point(xpos, ypos);
        popMatrix();
      }
    }

Accessing selected list elements from ControlP5 dropdown list

$
0
0

Hi guys,

What should I do to be able to print the relevant item? eg: I want the console to print out just the word 'ADD' or 'SUBTRACT' and so on. I want to later use this as part of a String Variable to pass into the default blendMode() function. That way I will be able to allow for user input/choice of blendMode. That way it would read as blendMode(ADD) or blendMode(SUBTRACT).

I tried getName(), etc but was not able to access it. Right now it prints:

1 {text=SUBTRACT, color=bg (0,45,90), fg (0,116,217), active (0,170,255), captionlabel (255,255,255), valuelabel (255,255,255), name=SUBTRACT, state=false, value=1, view=controlP5.ScrollableList$1@66a35419}

import controlP5.*;
import java.util.*;


ControlP5 cp5;

void setup() {
  size(400, 400);
  cp5 = new ControlP5(this);
  List l = Arrays.asList("ADD", "SUBTRACT", "DARKEST ", "LIGHTEST ", "DIFFERENCE", "EXCLUSION",
  "MULTIPLY", "SCREEN", "OVERLAY", "HARD_LIGHT", "SOFT_LIGHT", "DODGE", "BURN");
  /* add a ScrollableList, by default it behaves like a DropdownList */
  cp5.addScrollableList("dropdown")
    .setPosition(100, 100)
      .setSize(200, 100)
        .setBarHeight(20)
          .setItemHeight(20)
            .addItems(l)
              .setType(ScrollableList.DROPDOWN) // currently supported DROPDOWN and LIST
                ;
}

void draw() {
  background(240);
}

void dropdown(int n) {
  /* request the selected item based on index n */
  println(n, cp5.get(ScrollableList.class, "dropdown").getItem(n));

  //--------------------------------------------------------------------------------------------------------
  //MY NOTE: what should I do to be able to print the relevant item? eg: I want the console to print out
  // just the word Add or Subtract. I want to later use this as part of a String Variable to pass into
  // the default blendMode() function. That way I will be able to allow for user input/choice of blendMode.
  // right now it prints:

  // 1 {text=SUBTRACT, color=bg (0,45,90), fg (0,116,217), active (0,170,255), captionlabel (255,255,255),
  //valuelabel (255,255,255), name=SUBTRACT, state=false, value=1, view=controlP5.ScrollableList$1@66a35419}
  //--------------------------------------------------------------------------------------------------------


  /* here an item is stored as a Map  with the following key-value pairs:
   * name, the given name of the item
   * text, the given text of the item by default the same as name
   * value, the given value of the item, can be changed by using .getItem(n).put("value", "abc"); a value here is of type Object therefore can be anything
   * color, the given color of the item, how to change, see below
   * view, a customizable view, is of type CDrawable
   */

  //   CColor c = new CColor();
  //  c.setBackground(color(255,0,0));
  //  cp5.get(ScrollableList.class, "dropdown").getItem(n).put("color", c);
}


/*
a list of all methods available for the ScrollableList Controller
 use ControlP5.printPublicMethodsFor(ScrollableList.class);
 to print the following list into the console.

 You can find further details about class ScrollableList in the javadoc.

 Format:
 ClassName : returnType methodName(parameter type)


 controlP5.Controller : CColor getColor()
 controlP5.Controller : ControlBehavior getBehavior()
 controlP5.Controller : ControlWindow getControlWindow()
 controlP5.Controller : ControlWindow getWindow()
 controlP5.Controller : ControllerProperty getProperty(String)
 controlP5.Controller : ControllerProperty getProperty(String, String)
 controlP5.Controller : ControllerView getView()
 controlP5.Controller : Label getCaptionLabel()
 controlP5.Controller : Label getValueLabel()
 controlP5.Controller : List getControllerPlugList()
 controlP5.Controller : Pointer getPointer()
 controlP5.Controller : ScrollableList addCallback(CallbackListener)
 controlP5.Controller : ScrollableList addListener(ControlListener)
 controlP5.Controller : ScrollableList addListenerFor(int, CallbackListener)
 controlP5.Controller : ScrollableList align(int, int, int, int)
 controlP5.Controller : ScrollableList bringToFront()
 controlP5.Controller : ScrollableList bringToFront(ControllerInterface)
 controlP5.Controller : ScrollableList hide()
 controlP5.Controller : ScrollableList linebreak()
 controlP5.Controller : ScrollableList listen(boolean)
 controlP5.Controller : ScrollableList lock()
 controlP5.Controller : ScrollableList onChange(CallbackListener)
 controlP5.Controller : ScrollableList onClick(CallbackListener)
 controlP5.Controller : ScrollableList onDoublePress(CallbackListener)
 controlP5.Controller : ScrollableList onDrag(CallbackListener)
 controlP5.Controller : ScrollableList onDraw(ControllerView)
 controlP5.Controller : ScrollableList onEndDrag(CallbackListener)
 controlP5.Controller : ScrollableList onEnter(CallbackListener)
 controlP5.Controller : ScrollableList onLeave(CallbackListener)
 controlP5.Controller : ScrollableList onMove(CallbackListener)
 controlP5.Controller : ScrollableList onPress(CallbackListener)
 controlP5.Controller : ScrollableList onRelease(CallbackListener)
 controlP5.Controller : ScrollableList onReleaseOutside(CallbackListener)
 controlP5.Controller : ScrollableList onStartDrag(CallbackListener)
 controlP5.Controller : ScrollableList onWheel(CallbackListener)
 controlP5.Controller : ScrollableList plugTo(Object)
 controlP5.Controller : ScrollableList plugTo(Object, String)
 controlP5.Controller : ScrollableList plugTo(Object[])
 controlP5.Controller : ScrollableList plugTo(Object[], String)
 controlP5.Controller : ScrollableList registerProperty(String)
 controlP5.Controller : ScrollableList registerProperty(String, String)
 controlP5.Controller : ScrollableList registerTooltip(String)
 controlP5.Controller : ScrollableList removeBehavior()
 controlP5.Controller : ScrollableList removeCallback()
 controlP5.Controller : ScrollableList removeCallback(CallbackListener)
 controlP5.Controller : ScrollableList removeListener(ControlListener)
 controlP5.Controller : ScrollableList removeListenerFor(int, CallbackListener)
 controlP5.Controller : ScrollableList removeListenersFor(int)
 controlP5.Controller : ScrollableList removeProperty(String)
 controlP5.Controller : ScrollableList removeProperty(String, String)
 controlP5.Controller : ScrollableList setArrayValue(float[])
 controlP5.Controller : ScrollableList setArrayValue(int, float)
 controlP5.Controller : ScrollableList setBehavior(ControlBehavior)
 controlP5.Controller : ScrollableList setBroadcast(boolean)
 controlP5.Controller : ScrollableList setCaptionLabel(String)
 controlP5.Controller : ScrollableList setColor(CColor)
 controlP5.Controller : ScrollableList setColorActive(int)
 controlP5.Controller : ScrollableList setColorBackground(int)
 controlP5.Controller : ScrollableList setColorCaptionLabel(int)
 controlP5.Controller : ScrollableList setColorForeground(int)
 controlP5.Controller : ScrollableList setColorLabel(int)
 controlP5.Controller : ScrollableList setColorValue(int)
 controlP5.Controller : ScrollableList setColorValueLabel(int)
 controlP5.Controller : ScrollableList setDecimalPrecision(int)
 controlP5.Controller : ScrollableList setDefaultValue(float)
 controlP5.Controller : ScrollableList setHeight(int)
 controlP5.Controller : ScrollableList setId(int)
 controlP5.Controller : ScrollableList setImage(PImage)
 controlP5.Controller : ScrollableList setImage(PImage, int)
 controlP5.Controller : ScrollableList setImages(PImage, PImage, PImage)
 controlP5.Controller : ScrollableList setImages(PImage, PImage, PImage, PImage)
 controlP5.Controller : ScrollableList setLabel(String)
 controlP5.Controller : ScrollableList setLabelVisible(boolean)
 controlP5.Controller : ScrollableList setLock(boolean)
 controlP5.Controller : ScrollableList setMax(float)
 controlP5.Controller : ScrollableList setMin(float)
 controlP5.Controller : ScrollableList setMouseOver(boolean)
 controlP5.Controller : ScrollableList setMoveable(boolean)
 controlP5.Controller : ScrollableList setPosition(float, float)
 controlP5.Controller : ScrollableList setPosition(float[])
 controlP5.Controller : ScrollableList setSize(PImage)
 controlP5.Controller : ScrollableList setSize(int, int)
 controlP5.Controller : ScrollableList setStringValue(String)
 controlP5.Controller : ScrollableList setUpdate(boolean)
 controlP5.Controller : ScrollableList setValue(float)
 controlP5.Controller : ScrollableList setValueLabel(String)
 controlP5.Controller : ScrollableList setValueSelf(float)
 controlP5.Controller : ScrollableList setView(ControllerView)
 controlP5.Controller : ScrollableList setVisible(boolean)
 controlP5.Controller : ScrollableList setWidth(int)
 controlP5.Controller : ScrollableList show()
 controlP5.Controller : ScrollableList unlock()
 controlP5.Controller : ScrollableList unplugFrom(Object)
 controlP5.Controller : ScrollableList unplugFrom(Object[])
 controlP5.Controller : ScrollableList unregisterTooltip()
 controlP5.Controller : ScrollableList update()
 controlP5.Controller : ScrollableList updateSize()
 controlP5.Controller : String getAddress()
 controlP5.Controller : String getInfo()
 controlP5.Controller : String getName()
 controlP5.Controller : String getStringValue()
 controlP5.Controller : String toString()
 controlP5.Controller : Tab getTab()
 controlP5.Controller : boolean isActive()
 controlP5.Controller : boolean isBroadcast()
 controlP5.Controller : boolean isInside()
 controlP5.Controller : boolean isLabelVisible()
 controlP5.Controller : boolean isListening()
 controlP5.Controller : boolean isLock()
 controlP5.Controller : boolean isMouseOver()
 controlP5.Controller : boolean isMousePressed()
 controlP5.Controller : boolean isMoveable()
 controlP5.Controller : boolean isUpdate()
 controlP5.Controller : boolean isVisible()
 controlP5.Controller : float getArrayValue(int)
 controlP5.Controller : float getDefaultValue()
 controlP5.Controller : float getMax()
 controlP5.Controller : float getMin()
 controlP5.Controller : float getValue()
 controlP5.Controller : float[] getAbsolutePosition()
 controlP5.Controller : float[] getArrayValue()
 controlP5.Controller : float[] getPosition()
 controlP5.Controller : int getDecimalPrecision()
 controlP5.Controller : int getHeight()
 controlP5.Controller : int getId()
 controlP5.Controller : int getWidth()
 controlP5.Controller : int listenerSize()
 controlP5.Controller : void remove()
 controlP5.Controller : void setView(ControllerView, int)
 controlP5.ScrollableList : List getItems()
 controlP5.ScrollableList : Map getItem(String)
 controlP5.ScrollableList : Map getItem(int)
 controlP5.ScrollableList : ScrollableList addItem(String, Object)
 controlP5.ScrollableList : ScrollableList addItems(List)
 controlP5.ScrollableList : ScrollableList addItems(Map)
 controlP5.ScrollableList : ScrollableList addItems(String[])
 controlP5.ScrollableList : ScrollableList clear()
 controlP5.ScrollableList : ScrollableList close()
 controlP5.ScrollableList : ScrollableList open()
 controlP5.ScrollableList : ScrollableList removeItem(String)
 controlP5.ScrollableList : ScrollableList removeItems(List)
 controlP5.ScrollableList : ScrollableList setBackgroundColor(int)
 controlP5.ScrollableList : ScrollableList setBarHeight(int)
 controlP5.ScrollableList : ScrollableList setBarVisible(boolean)
 controlP5.ScrollableList : ScrollableList setItemHeight(int)
 controlP5.ScrollableList : ScrollableList setItems(List)
 controlP5.ScrollableList : ScrollableList setItems(Map)
 controlP5.ScrollableList : ScrollableList setItems(String[])
 controlP5.ScrollableList : ScrollableList setOpen(boolean)
 controlP5.ScrollableList : ScrollableList setScrollSensitivity(float)
 controlP5.ScrollableList : ScrollableList setType(int)
 controlP5.ScrollableList : boolean isBarVisible()
 controlP5.ScrollableList : boolean isOpen()
 controlP5.ScrollableList : int getBackgroundColor()
 controlP5.ScrollableList : int getBarHeight()
 controlP5.ScrollableList : int getHeight()
 controlP5.ScrollableList : void controlEvent(ControlEvent)
 controlP5.ScrollableList : void keyEvent(KeyEvent)
 controlP5.ScrollableList : void setDirection(int)
 controlP5.ScrollableList : void updateItemIndexOffset()
 java.lang.Object : String toString()
 java.lang.Object : boolean equals(Object)

 created: 2015/03/24 12:21:22

 */

MQTT - Qatja ability to connect using username and password ?

$
0
0

Many cloud services use MQTT and they require an initial connection using a username and password. I have not found the ability to set these parameters with any of the MQTT type libraries i have found for processing. Is this capability available ?

processing and phones

$
0
0

For a project I need to interact with a phone menu (like Computer Telephony Integration voice/tones menu) How can I do this? Is there an interface to connect a land phone and hear Text-to speech scripts that could receive tones?


How to control tint of image in Processing with audio output volume

$
0
0

Ok, so I'd like to project a few pictures to the wall. I'd like the tint to change gradually, depending on the volume of audio output. The audio is coming from audio samples (so not MIDI instruments, if that makes any difference) in Ableton Live Suite, which I'm controlling in real-time. Any codes/links would be super helpful - stressed postgrad student :) Thank you!

Custom generator/processor in Sound Library

$
0
0

Is there a way to implement a custom generator/processor using the Sound Library? I did it very easily with the minim library (e.g. I implemented my custom reverb) but I cannot find any example with the Sound library.

Keepin 0,0 translate on Cp5-elements but not on the rest.

$
0
0

I would like to pushMatrix before the translate statement and pop it after the text statement. But it's no possible. Is there another way to keep the cp5 elements from listening to the translate(400, 400) and make them (0,0)

import controlP5.*; ControlP5 cp5;

public float sliderBredd = 0; public float sliderHojd = 0;

PFont myFont;

void setup() { size(800, 800); cp5 = new ControlP5(this);

cp5.addSlider("sliderBredd") .setRange(-255, 255) .setPosition(40, 40) .setSize(200, 29) ;

cp5.addSlider("sliderHojd") .setRange(-255, 255) .setPosition(40, 80) .setSize(200, 29) ; }

void draw () { background(255, 255, 255); myFont = createFont("Times-Roman", 48); textFont(myFont, 272); translate(400, 400);

for (int i=0; i<12; i=i+1) {

fill(14, 105, 237);
textAlign(CENTER);
rotate(PI*1/3);
text("Q", sliderBredd, sliderHojd);

} }

recording a video

$
0
0

Hello,

I wrote a programme for audio-reactive visuals … usually I perform live in clubs (like here), but this time I need to record a video (sound doesn’t matter). I tried to write out jpegs, and a screen capture with Quicktime, but both slows down the programme a bit. However it is pretty essential that the visuals react precisely to the audio.

Does anybody have some advice maybe?

Cheers!

Weather Data Library - Missing Links

$
0
0

Hi all,

I'm looking for a library or piece of code that can link processing to weather data, either real time, or in the form of the standard typical meteorological year (TMY) of EnergyPlus.

Any ideas of existing implementations? I spotted a Yaoo weather library by onformative on processing.org but the link is broken.

Any help is greatly appreciated.

Viewing all 2896 articles
Browse latest View live