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

ControlP5 Icon class calls controlEvent method when setBroadcast is set to false

$
0
0

Hi,

Basically as described in the title. I'm working with the icon class which is great but when I set it to being a switch, setting broadcast to false does not affect whether it calls the controlEvent function. In code:

controlP5.get(Icon.class, "Iconcontroller") .setBroadcast(false) .setOn() .setBroadcast(true) ;

Does not function like I would expect it too. Has anybody encountered or solved this problem before. Thanks


Combining separate sketches in one processing file

$
0
0

Hello everyone. I have a question. We are doing a new media art postgraduate project,our lecturer wants to get us involved with processing. I have seven different sketches. They are all separately. I want to combine them like a slideshow or with a mouse click in one pde file, because its a story . But i have "if mousepressed" comment some of my sketches. Maybe a button can solve my problem. But i have no idea how to do this because I'm a beginner. I am attaching my sketches. Can you please help me? Thank you all warmly.

sketch1:

import ddf.minim.*;
import ddf.minim.ugens.*;

Minim minim;
AudioOutput out;


class SineInstrument implements Instrument
{
  Oscil wave;
  Line  ampEnv;

  SineInstrument( float frequency )
  {

    wave   = new Oscil( frequency, 0, Waves.SINE );
    ampEnv = new Line();
    ampEnv.patch( wave.amplitude );
  }

  void noteOn( float duration )
  {
    ampEnv.activate( duration, 0.5f, 0 );

    wave.patch( out );
  }

  void noteOff()
  {
    wave.unpatch( out );
  }
}


float x, y; // X and Y coordinates of text
float hr, vr;  // horizontal and vertical radius of the text
void setup() {


size(640, 360, P3D);
  fill(25);
  textFont(createFont("Georgia", 36));
  textAlign(CENTER, CENTER);
vr = (textAscent() + textDescent()) / 2;
  noStroke();
  x = width / 2;
  y = height / 2;
    minim = new Minim(this);


  out = minim.getLineOut();


  out.playNote( 0.0, 0.9, new SineInstrument( 97.99 ) );
  out.playNote( 1.0, 0.9, new SineInstrument( 123.47 ) );

  // we can use the Frequency class to create frequencies from pitch names
  out.playNote( 2.0, 2.9, new SineInstrument( Frequency.ofPitch( "C3" ).asHz() ) );
  out.playNote( 3.0, 1.9, new SineInstrument( Frequency.ofPitch( "E3" ).asHz() ) );
  out.playNote( 4.0, 0.9, new SineInstrument( Frequency.ofPitch( "G3" ).asHz() ) );
}


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

  // Change height of the camera with mouseY
  camera(10.0, mouseY, 300.0, // eyeX, eyeY, eyeZ
         0.0, 0.0, 0.0, // centerX, centerY, centerZ
         0.0, 1.0, 0.0); // upX, upY, upZ

  noStroke();
  box(120);
  stroke(0);
  line(0, 0, 0, 0, 0, 0);
  line(0, 0, 0, 0, 0, 0);
  line(0, 0, 0, 0, 0, 0);
 text("KARANLIK BİR ODA...", width-mouseX, height-mouseY);

}

sketch 2:

import ddf.minim.*;
import ddf.minim.ugens.*;

Minim minim;
AudioOutput out;
Oscil       wave;
Oscil       mod;

PFont font;
String[] words = {"uyanıyorum...", "uyanıyorum...", "uyanıyorum...", "uyanıyorum...", "uyanıyorum...", " "};

int whichWord = 0;

void setup() {
  minim = new Minim(this);

  // use the getLineOut method of the Minim object to get an AudioOutput object
  out = minim.getLineOut();

  // create a triangle wave Oscil, set to 440 Hz, at 1.0 amplitude
  // in this case, the amplitude we construct the Oscil with
  // doesn't matter because we will be patching something to
  // its amplitude input.
  wave = new Oscil( 440, 1.0f, Waves.TRIANGLE );

  // create a sine wave Oscil for modulating the amplitude of wave
  mod  = new Oscil( 2, 0.4f, Waves.SINE );

  // connect up the modulator
  mod.patch( wave.amplitude );

  // patch wave to the output
  wave.patch( out );
  size(640, 360);
  font = createFont("Times New Roman", 50);
  textFont(font);
  textAlign(CENTER);
  frameRate(20);
  fill(204);
}

void draw() {
  background(0);
  text(words[whichWord], width/2, 200);
  whichWord++;
  if (whichWord == words.length) {
    whichWord = 0;
  }
}

sketch 3:

import ddf.minim.*;
import ddf.minim.ugens.*;

// create all of the variables that will need to be accessed in
// more than one methods (setup(), draw(), stop()).
Minim minim;
AudioOutput out;
Delay myDelay;
int savedTime;
int totalTime = 10000;

int i1=0;
int i2=0;
int i3=0;
int i4=0;
int i5=0;
int i6=0;
int newline = 150;
int flag = 0;
int x = 250;
int y = 250;

int time;
int wait = 100;
boolean tick;


String[] adjective = {
 "düşünceler...",

};
String[] noun = {
  "içimdeki","başkalarının",

};

String[] verb = {
  "sesleri",
};



String[] adverb = {
 "hızlı", "geçen",

};

String[] determiner = {
 "düşünceler", "onlar","benim","değil"
};

void setup()
{
//font = loadFont("Trebuchet MS.ttf");
  size(640, 360);
 //fullScreen();
  background(0);//
  color(255);
  textSize(18);
  smooth();
  strokeWeight(3);
   minim = new Minim(this);
  out = minim.getLineOut();

  // initialize myDelay with continual feedback and audio passthrough
  myDelay = new Delay( 0.4, 0.5, true, true );

  // sawh will create a Sawtooth wave with the requested number of harmonics.
  // like with Waves.randomNHarms for sine waves,
  // you can create a richer sounding sawtooth this way.
  Waveform saw = Waves.sawh( 15 );
  // create the Blip that will be used
  Oscil myBlip = new Oscil( 245.0, 0.3, saw );

  // Waves.square will create a square wave with an uneven duty-cycle,
  // also known as a pulse wave. a square wave has only two values,
  // either -1 or 1 and the duty cycle indicates how much of the wave
  // should -1 and how much 1. in this case, we are asking for a square
  // wave that is -1 90% of the time, and 1 10% of the time.
  Waveform square = Waves.square( 0.9 );
  // create an LFO to be used for an amplitude envelope
  Oscil myLFO = new Oscil( 1, 0.3, square );
  // offset the center value of the LFO so that it outputs 0
  // for the long portion of the duty cycle
  myLFO.offset.setLastValue( 0.3 );

  myLFO.patch( myBlip.amplitude );

  // and the Blip is patched through the delay into the output
  myBlip.patch( myDelay ).patch( out );
}

void draw()
{
  textSize(18);
    i1 = round(random(0,(adjective.length-1)));  // generating a Random element index for the Subject Array
    i5 = round(random(0,(adjective.length-1)));
    i2 = round(random(0,(noun.length-1)));  // generating a Random element index for the Verb Array
    i3 = round(random(0,(verb.length-1)));  // generating a Random element index for the Object Array
    i4 = round(random(0,(adverb.length-1)));
    i6 = round(random(0,(determiner.length-1)));

  if(flag==0) //initial screen when no buttons have been pressed
  {
     initial();
   noLoop();
   textSize(18);
   // text(noun[i3] + " " + verb[i2] + " " + determiner[i6] + " " + noun[i3], (width/1)-250, height);
   text(adjective[i1] + " " + adjective[i5] + " " +  noun [i2] +" " + verb[i3] + " " + adverb[i4], (width/2-125), height/2);
    textSize(14);
   //text("Left Click - To Randomize" +" " + " --||-'S'- To Save-||-- " + " " +"Right Click - To Stop", (width/2)-600, 60);

  }
  if(flag==1) //when left mouse is clicked
  {
    background (0);
    text(adjective[i1] + " " + adjective[i5] + " " +  noun [i2] +" " + verb[i3] + " " + adverb[i4], (width/2)-125, height/2);
    // text(noun[i3] + " " + verb[i2] + " " + determiner[i6] + " " + noun[i3], (width/1.5)-250, height);
  }

   //textSize(15);
   //text("Left Click - To Randomize" +" " + " --||-'S'- To Save-||-- " + " " +"Right Click - To Stop", (width+CENTER), 60);

}
void mousePressed()
{
  if(mouseButton==LEFT)
  {
     flag = 1;
     loop();
  }
if(mouseButton==RIGHT)
  {
    flag = -1;
    loop();
  }
  if(mouseButton==CENTER)
  {
    flag=0;
    noLoop();
  }
}

void sentence() //defines the sentence
{
  text(noun[i3] + " " + verb[i2] + " " + determiner[i6] + " " + noun[i3], (width/2)-125, height);
   text(adjective[i1] + " " + adjective[i5] + " " + verb[i2] + " " + noun[i3] + " " + adverb[i4], (width/2)-125, height);
}

void initial() //
{
 background(0);
  textSize(25);
  for(int a = 0; a < adjective.length; a++)
  {

 // text(adjective[a] + " " + verb [a] + " " + noun[a] + " " + adverb[a], (width/2)-250 , newline);
    newline = newline + 50;
  }

}
 void keyPressed() { //hit the "s" key and save my image
  if (key=='s')
  {
    saveImage();
  }
}

void saveImage() {
  saveFrame("keep_going_##.png"); //when running on the web it will put the PNG in a new browser tab
}

sketch 4:

import ddf.minim.*;
import ddf.minim.ugens.*;

// create all of the variables that will need to be accessed in
// more than one methods (setup(), draw(), stop()).
Minim minim;
AudioOutput out;

// the Oscil we use for modulating frequency.
Oscil fm;
String msg;
PFont font;
  PFont font1;
void setup(){
   minim = new Minim( this );
  out   = minim.getLineOut();

  // make the Oscil we will hear.
  // arguments are frequency, amplitude, and waveform
  Oscil wave = new Oscil( 200, 0.8, Waves.TRIANGLE );
  // make the Oscil we will use to modulate the frequency of wave.
  // the frequency of this Oscil will determine how quickly the
  // frequency of wave changes and the amplitude determines how much.
  // since we are using the output of fm directly to set the frequency
  // of wave, you can think of the amplitude as being expressed in Hz.
  fm   = new Oscil( 10, 2, Waves.SINE );
  // set the offset of fm so that it generates values centered around 200 Hz
  fm.offset.setLastValue( 200 );
  // patch it to the frequency of wave so it controls it
  fm.patch( wave.frequency );
  // and patch wave to the output
  wave.patch( out );

  int i;
  //frameRate(30);
  size(640, 360); //determina el tamaño de la pantalla
  size(640, 360);
  //smooth sirve para mejorar el aspecto de los gráficos, la calidad del renderizado 2,3,4 o 8
  smooth();
  frameRate(50);
  //font cargamos la tipografía desde Tools
//PFont es una variable tipográfica
 font = createFont("aileronultralight", 30);
 font1 = createFont("aileronthin", 10);
  //msg escribimos el mensaje
  msg = "[ yine aynı baş ağrısı ] ";

}

void draw(){
  background(0);

  pushMatrix();
  textFont(font1,65);
  fill(255,0,0,random(0,255));
  translate(width/2, height/2);
  textAlign(CENTER);
  text(msg, 0, 0);
  popMatrix();

  pushMatrix();
  textFont(font1,random(50,100));
  fill(random(0,255),255,255,random(0,255));
  translate(width/2,height/2);
  textAlign(CENTER);
  text(msg,0,0);
  popMatrix();

}

sketch 5:

import ddf.minim.*;

Minim minim;
AudioPlayer player;
PFont myfont;

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

  myfont = createFont("Serif",80);
  minim = new Minim(this);

  // loadFile will look in all the same places as loadImage does.
  // this means you can find files that are in the data folder and the
  // sketch folder. you can also pass an absolute path, or a URL.
  player = minim.loadFile("Footsteps_on_Cement-Tim_Fryer-870410055.mp3");

  // play the file from start to finish.
  // if you want to play the file again,
  // you need to call rewind() first.
  player.play();
}

void draw()

{
  if (mousePressed)
  {
    background (0);
  translate(width/2, height/2);
  fill(255,255,255);

  textFont (myfont);
  textSize(48);
  textAlign(CENTER,CENTER);
  text("yakınlaşan ayak seslerim", 0, 0);
  }

  else
  {
    background(255);
    translate(width/2, height/2);
    fill(0);

    textFont (myfont);
    textSize(24);
    textAlign(CENTER, CENTER);
    text("uzaklaşan içimdeki ses", 0, 0);
  }


}

sketch 6:

PFont myfont;


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

myfont = createFont("san serif", 80);
}

void draw()
{
   if (mousePressed)
  {
    background (255);
  translate(width/2, height/2);
  fill(255,255,255);
   textFont(myfont);
  fill(0);
  textSize(40);
  textAlign(CENTER, CENTER);
  text("nüchtern", 0, 0);

  }
  else
  {
  background(random(255),random(255),random(255));
  translate( 0,height/2);
  rotate(millis()/500.0);
  fill(random(255),random(255),random(255));
 float a = sin(millis()/400.0);
  textFont(myfont);
  textSize(90);
  textAlign(LEFT, CENTER);
  text("BERAUSCHT", 0, a*100);
}
}

sketch 7:

import ddf.minim.*;

Minim minim;
AudioPlayer player;

PFont typo;

void setup()
{
  size (640, 360);
  typo = createFont("BrushScriptStd", 80);
   minim = new Minim(this);

  // loadFile will look in all the same places as loadImage does.
  // this means you can find files that are in the data folder and the
  // sketch folder. you can also pass an absolute path, or a URL.
  player = minim.loadFile("jarboe-kris-force-safe-song-the-path.mp3");

  // play the file from start to finish.
  // if you want to play the file again,
  // you need to call rewind() first.
  player.play();
  //println(PFont.list());
}

void draw()
{

  //background(255,0,255);
  translate(width/2, height/2);

  if (mousePressed == false)
  {
    background(255, 255, 255);

    fill(0);

    pushMatrix();
    rotate(millis()/100.0);
    textFont(typo);
    textSize(30);
    textAlign(CENTER, CENTER);
    text("bu dönme hissi hayal mi?", 0, 0);
    popMatrix();

    pushMatrix();
    textFont(typo);
    textSize(40);
    fill(255, 255, 255, 150);
    float x = sin(millis()/2500);
    float y = cos(millis()/2500);
    //rotate(millis()/500.0);
    //text("Hello", 220*x, 220*y);
    popMatrix();



    pushMatrix();
    textFont(typo);
    textSize(20);
    fill(0);
    rotate(millis()/600.0);
    fill(0);
    text("başka gerçek",150,150);
    text("olabilir", -150,-150);
    text("gerçek gibi", -150,150);
    text("ayrım yapamıyorum", 150,-150);
    popMatrix();



  } else if ( mousePressed == true)
  {
    background(0);
    textFont(typo);
    textSize(20);
    textAlign(CENTER, CENTER);
    fill(255);
    text("Gerçek gerçeklik normal,", 0, 13);
    text("sıradan bir insanın algılamasına denk düşerken, ", 0, 40);
  text("ikinci gerçeklik sağlıklı bir insanın anlayamayacağı,", 0, 70);
  text("çoğu kez belli bir sisteme dayalı bir gerçekliktir.", 0, 100);
}
}

G4P GtextArea scrolling to bottom as you type

$
0
0

I am trying to figure out a way to scroll down to the last line of the GTextArea after each time text is set.

If you try my code you can see when the text reaches the bottom of the view nothing happens. I tried using getTextAsArray in combination with moveCaretTo in order to place caret at the end of the text, hoping it would scroll down. But getTextAsArray always returns an array with only one element, even after text goes to a new line.

   import g4p_controls.*;
   import g4p_controls.GCScheme;
   import java.awt.Font;
   import java.awt.*;

   GTextArea textArea;
   String txtMain ="";
   int screenWidth;
   int screenHeight;

   void setup() {
     screenWidth = 400;
     screenHeight = 300;
     size(screenWidth, screenHeight, JAVA2D);
     smooth();
     background(255);

     textArea = new GTextArea(this, 5, 0, screenWidth - 10, screenHeight);
     textArea.setFont(new Font("", Font.PLAIN, 80));
     textArea.setText("", screenWidth - 20);
     textArea.setTextEditEnabled(false);
   }

   void draw() {
     background(255);
    }

   void keyPressed() {
     txtMain = txtMain + key;
     textArea.setText(txtMain);
   }

MIDI. Load and play MIDI files with Java code in Processing 3. HELP!!!!

$
0
0

I’m trying to play a midi file, using java classes

I don’t get any errors, but the file doesn’t play

Here is the processing code:

    import javax.sound.midi.*;
    import java.io.*;

    Sequencer playMidi;
    File selection;

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

      try
      {
        File selection = new File("Mozart_Coda.mid");
        playMidi = MidiSystem.getSequencer();
        playMidi.open();
        Sequence fileSequence = MidiSystem.getSequence(selection);
        playMidi.setSequence(fileSequence);
        playMidi.start();
      }catch(Exception e)
      {
        println("FILE NOT FOUND!!");
      }
    }

    /*void draw()
    {
    }*/

I keep getting a ‘FILE NOT FOUND’ in the console message. The file doesn't play. :( Please help.

ArrayList of PVectors Setup and Display

$
0
0

Hi, I was wondering if anyone here can help me getting my head around PVectors. I am creating a visualization of points on Earth. For this I am creating an arrayList of PVectors, which get their data from a csv (Longitude, Latitute). My problem is the csv has over 88 000 lines and slows down the program when drawn in void draw() Therefore I wanted to initialize the PVectors in void createLocationPoints()) and only display them in draw with another funciton... For instance with giving the points a stroke weight. Can someone explain how I can display the function LocationVectors.add(new PVector(x, y, z)); in this example? I was thinking of something similar like Daniel Schiffmans simple particle example from the documentation but I can't quite get my head around it. Please be gentle, I am quite new to processing. Thanks a lot!

import peasy.*;

PeasyCam cam;

//Radius Earth
float radius = 6371000/50000; //global scale

//Tables
Table dataTable;
Table locationTable;

//Data lists
FloatList AffordabilityIndex;
FloatList LongituteAI;
FloatList LatituteAI;
FloatList AltituteAI;

//Locations Lists
FloatList settlementPoint;
FloatList Longitute;
FloatList Latitute;
FloatList Altitute;

float x;
float y;
float z;

PVector LocationVector;
//PShape points;

ArrayList<PVector> LocationVectors;

void setup() {
  size(800, 800, P3D);
  smooth();
  dataTable = loadTable("dataTable.csv", "header");
  locationTable = loadTable("locationTable.csv", "header");

  LocationVectors = new ArrayList<PVector>();

  cam = new PeasyCam(this, 4000);
  cam.setMinimumDistance(250); //0
  cam.setMaximumDistance(500); //8000

  ////LOCATIONS
  ////create location lists
  Longitute = new FloatList();
  Latitute = new FloatList();
  Altitute = new FloatList();
  //Read and store CSV
  for (int i = 0; i < locationTable.getRowCount(); i++) {
      TableRow rowLocationTable = locationTable.getRow(i);
      Longitute.append(rowLocationTable.getFloat("Longitute"));
      Latitute.append(rowLocationTable.getFloat("Latitute"));
      Altitute.append(rowLocationTable.getFloat("Altitute"));
    }


  //DATA
  //create data lists
  AffordabilityIndex = new FloatList();
  LongituteAI = new FloatList();
  LatituteAI = new FloatList();
  //Read and store CSV
  for (int i = 0; i < dataTable.getRowCount(); i++) {
    TableRow rowDataTable = dataTable.getRow(i);
    AffordabilityIndex.append(rowDataTable.getFloat("Affordability Index")*1);
    LongituteAI.append(rowDataTable.getFloat("Longitute"));
    LatituteAI.append(rowDataTable.getFloat("Latitute"));
    //println(Longitute, Latitute, AffordabilityIndex);
  }

  createLocationPoints();

}

void draw() {

  background(255);
  shape(points);
  displayLocationPoints();

  //DRAW DATA

  AltituteAI = AffordabilityIndex;

  strokeWeight(4);
  stroke(0);
  beginShape(POINTS);

  for (int i = 0; i < LongituteAI.size(); i++) {
    //Convert to Cartesian Coordinates
    //float a = pow( 1, 3);  // Sets 'a' to 1*1*1 = 1
    float f = 0; // flatening
    float lambda = atan(pow((1 - f), 2) * tan(radians(LatituteAI.get(i))));    // lambda

    float y = radius * cos(lambda) * cos(radians(LongituteAI.get(i))) + AltituteAI.get(i) * cos(radians(LatituteAI.get(i))) * cos(radians(LongituteAI.get(i))); //swaped x&y
    float x = radius * cos(lambda) * sin(radians(LongituteAI.get(i))) + AltituteAI.get(i) * cos(radians(LatituteAI.get(i))) * sin(radians(LongituteAI.get(i)));
    float z = radius * sin(lambda) + AltituteAI.get(i) * sin(radians(LatituteAI.get(i)));

    vertex(x, y, z);
  }
  endShape();

  noStroke();
  sphere(radius*0.98);

}

void createLocationPoints(){
    //DRAW ALL LOCATIONS
  //strokeWeight(1);
  //stroke(0);
  //beginShape(POINTS);
   //points = createShape();
   //points.beginShape();

  for (int i = 0; i < Longitute.size(); i++) {
    //Convert to Cartesian Coordinates
    //float a = pow( 1, 3);  // Sets 'a' to 1*1*1 = 1
    float f = 0; // flatening
    float lambda = atan(pow((1 - f), 2) * tan(radians(Latitute.get(i))));    // lambda

    float y = radius * cos(lambda) * cos(radians(Longitute.get(i))) + Altitute.get(i) * cos(radians(Latitute.get(i))) * cos(radians(Longitute.get(i))); //swaped x&y
    float x = radius * cos(lambda) * sin(radians(Longitute.get(i))) + Altitute.get(i) * cos(radians(Latitute.get(i))) * sin(radians(Longitute.get(i)));
    float z = radius * sin(lambda) + Altitute.get(i) * sin(radians(Latitute.get(i)));

    vertex(x, y, z);

    LocationVector = new PVector(x, y, z);
    LocationVectors.add(new PVector(x, y, z));

  }

  //endShape();
  //points.endShape();
  println(LocationVectors);
}

void displayLocationPoints(){
  strokeWeight(10);
  stroke(0);

}

dynamically show videos added to a folder

$
0
0

hej –

i know how to play/loop an existing video. but what if i have a folder in which videos will be copied (from an external source – in my case a raspberry pi that uploads captured video clips) dynamically?

can i add videos to my canvas on runtime? there is a function to list folder contents – but i don't know HOW TO dynamically add video sources to a running project.

is there any help? or a definitive "NO" …? thanks anyways!

– stephan

how do I change an original image to show when there is a loud noise, and the filtered image

$
0
0

I am still a beginner with code and I was hoping to get some help in changing original image to show when there is a loud noise, and the filtered image show when it is quiet. I wasn't really shown how to complete this in my past class and want to learn how to edit it so I know how to in the future. My past teacher didn't really teach it to well.

Here is code I have so far:

// libraries
import processing.sound.*;

// global variables
Amplitude amp; // audio amplifier
AudioIn in; // audio input
PImage original; // original image
PImage filtered; // image that will receive filtering
float volume = 0;

void setup() {
  size(740, 920); //was 640, 360
  background(0, 255, 255);
  // Create an Input stream which is routed into the Amplitude analyzer
  amp = new Amplitude(this);
  // set the input the mic channel 0
  in = new AudioIn(this, 0);
  // turn on the mic
  in.start();
  // feed the mic data to the amp
  amp.input(in);
  // give image files to the image variables
  original = loadImage("Musical Note.png");
  filtered = loadImage("Musical Note.png");
}

void draw() {
  //Draw normal
  if (mousePressed && (mouseButton == LEFT)) {
    ellipse(mouseX, mouseY, 40, 40);
    fill(random(255), random(255), random(255));
    noStroke();
    //erases
  } else if (mousePressed && (mouseButton == RIGHT)) {
    ellipse(mouseX, mouseY, 40, 40);
    fill(0, 255, 255);
    noStroke();
  }

  float volume = amp.analyze();
  if (volume > 0.5) { // check if volume is above threshold
    image(original, 0, 0); // display original image
  } else {

    // YOUR FILTER CODE GOES HERE

    image(filtered, 0, 0); // display filtered image
    PImage img;
    img = loadImage("Musical Note.png");
    image(img, 0, 0);
    image(filtered, 0, 0); // display filtered image
  }
}

How to make a video stop playing and screen++;

$
0
0

Hi guys, I have a basic set up of an animation storyline in which when the user clicks the mouse or does certain interactions, it then runs the next 'screen' or next animation. The issue I'm having is that on screen 5 a click of the mouse plays a video I made in after effects. However, this video then stops on the last frame and stays. I cannot work out how to 'screen++' after the video stops. I have tried duration, millis, etc. and nothing seems to be working. Could somebody please shed some light on what might be going on, or how I could achieve this?

import processing.video.*;
Movie myMovie;

Cell[] cells= new Cell[1000];

float x, y;
PFont Baskerville;
int screen=1;
int drawRandomLines = 0;
int ellipseSize = 0;
int totalCells = 0;

void setup () {
  size(1024, 768);
  smooth(3);
  noStroke();
  Baskerville = createFont("Baskerville", 30);
  textFont(Baskerville);
  textAlign(CENTER);
  noStroke();
  x = width/2;
  y = 0;
  myMovie = new Movie(this, "dominant_species.mov");
  //myMovie.play();
}

void draw () {

  if (screen==1) {
    background(4, 16, 36);
    fill(255, 219, 157);
    noStroke();
    //draw first screen
    ellipse(512, 384, 16, 16);
    text("Here is a cell.", width/2, height/2-40);

    // } if (y >= 384) {

    //y = height/2;

    text("Here is a cell.", width/2, height/2-40);
  } else if (screen==2) {
    background(4, 16, 36);

    fill(255, 219, 157, 20);
    rect(mouseX, 0, -mouseX, 768);
    fill(255, 219, 157);
    text("One of millions in the body.", width/2, height/2-40);

    cells[totalCells] = new Cell();

    totalCells ++ ;

    if (totalCells >= cells.length) {
      totalCells = 0;
    }

    for (int i = 0; i < totalCells; i++) {
      cells[i].move();
      cells[i].display();
    }

    if (mouseX >= 900) {
      screen++;
    }

    if (mouseY < 10 ) {
      screen++; //add one onto screen
    }
  } else if (screen==3) {
    background(255, 219, 157);
    //background(4,16,36);
    //draw third screen
    //testing to see if the mouse is inside a circle
    fill(4, 16, 36);
    text("Throughout our daily lives...", width/2, height/2-40);
  } else if (screen==4) {
    background(255, 219, 157);
    noStroke();

    text("our cells duplicate in order to heal and develop.", width/2, height/2+200);


    fill(4, 16, 36);
    ellipse(width/2-40, height/2-40, ellipseSize, ellipseSize);
    ellipse(width/2+40, height/2+40, ellipseSize, ellipseSize);
  } else if (screen==5) {
    background(4, 16, 36);
    noStroke();

    fill(255, 219, 157);
    text("That's how we've gone from a single celled organism...", width/2, height/2-20);
    image(myMovie, 0, 0);

    fill(4, 16, 36);
    ellipse(width/2-40, height/2-40, ellipseSize, ellipseSize);
    ellipse(width/2+40, height/2+40, ellipseSize, ellipseSize);
    //draw fifth screen
    //image(myMovie, 0, 0);
  }
}

//called only once when the user presses the mouse
void mousePressed () {
  if (screen==1) {
    //testing for a button notice it is the same bounds as the
    //rect we are drawing in the test for screen==1 inside draw
    //you could just write 170 instead of 130+40 but I left this
    //here so you can see how the test values relate to the rect coordinates
    float d = dist(mouseX, mouseY, 512, 384);

    if (d<20) {
      screen++;
      //myMovie.play();
    }
  } else if (screen==5) {

    myMovie.play();
  } else if (screen==3) {
    screen++;
  }
}


//called whenever the mouse is movoed
void mouseMoved () {
  if (screen == 4) {
    ellipseSize=ellipseSize+5;
    if (ellipseSize > width) {
      println("threshold");
      //take us back to the beginning
      //reset all of our variables
      //screen=1;
      drawRandomLines = 0;
      ellipseSize = 0;
      screen++;
    }
  } else if (screen == 6) {
    //take a look inside the screen==5 inside draw
    //ellipseSize++;
    //if (ellipseSize > width) {
    //println("threshold");
    //take us back to the beginning
    //reset all of our variables
    //screen=1;
    //drawRandomLines = 0;
    //ellipseSize = 0;
  }
}


void movieEvent(Movie m) {
  m.read();
}


//NEW TAB__ CELL CLASS

class Cell {

  float x, y;   // Variables for location of raindrop
  float speed; // Speed of raindrop
  color c;
  float r;     // Radius of raindrop

  Cell() {
    r = 8;                 // All raindrops are the same size
    x = random(mouseX);     // Start with a random x location
    y = -r*4;              // Start a little above the window
    speed = random(1, 5);   // Pick a random speed
    c = color(255,219,157); // Color
  }

  // Move the raindrop down
  void move() {
    // Increment by speed
    y += speed;
  }

  // Check if it hits the bottom
  boolean reachedBottom() {
    // If we go a little beyond the bottom
    if (y > height + r*4) {
      return true;
    } else {
      return false;
    }
  }

  // Display the raindrop
  void display() {
    // Display the drop
    fill(c);
    noStroke();
    ellipse(x, y, r*2, r*2);
  }

}
`

Analyze sound spectrum and sound visualization

$
0
0

Hi colleagues, which tools/libraries are good for scanning sound samples and extracting values. The values again should work as a driver for the visualization. As I saw a few, not sure where/how to start...

Hello, in the code below I try to give a random value to textSize in the sphere class, but it copies

Problem with DXF Exported sketch from Processing to Rhino

$
0
0

hi everyone, i just exported my sketch to Rhino for making 3d model but i realized that each of my lines exported as 2 parallel and make them useless for lofting!! is it possible to fix them in processing and make only one Cv line for each of them or is just a way processing generate them?!

(image from exported lines in rhino) paraLines

Thanks

Problem with "Sound" library

$
0
0

I'm trying to run the example in the documentation for the "Sound" library (https://processing.org/reference/libraries/sound/SoundFile.html) but I'm getting an error. I'm running v1.3.2 of the library, under Processing 3.1.1 and Windows 7 Pro. I tried both the 32-bit and 64-bit versions of Processing. The only change I made to the code was to change line 9 to point to the mp3 file on my hard drive. But when I try to open the file, I get this error message:

The constructor "SoundFile(SoundFile, String)" does not exist.

The error message doesn't make any sense, at least to me. I'm passing "this" as the first parameter, just as in the example, and a string with the full path name of the mp3 file as the second parameter. Why does it think "this" is a SoundFile?

Is the "Sound" library still working?

Here's my code, although as I said, I only changed the one line which opens the file.

import processing.sound.*;
SoundFile file;

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

  // Load a soundfile from the /data folder of the sketch and play it back
  file = new SoundFile(this,"C:\\Users\\owner\\Music\\% Attac\\01 Tonino Carotone & Manu Chao - La Trampa.mp3");
  file.play();
}

void draw() {
}

Rotate video from IP Webcam

$
0
0

Good evening to everyone and beg your pardon for my english. I'm new here even if it's a little while i'm working on Processing. In fact I use Processing to control arduino2009 board on my ROV, but I've only a problem to fix before I go to explore the abyss! On the front of the ROV there's a IPwebcam that I had to mount orizzontally to insert it into an acrilic cilynder. Webcam's video is correctly shown on my processing screen, but obviously it's 90 degrees clockwise rotated. I'm not able to turn the video counterclockwise, is there someone who can help me? (Of course i cannot mount webcam in other way because now i can rotate it to look up-forward-down). Every help is really really welcome! Thanks in advance. Andrew

PS: i put some lines of the program i've to improve with rotating 90deg counterclockwise, now it's only flips video horizontally.. (i'm not able to do more...)

Capture cam;
PImage camMirror;
void setup(){
  size(640,480,P2D);
  cam = new Capture(this,width,height,30);
  cam.start();
  camMirror = new PImage(cam.width,cam.height);
}
void draw(){
  if(cam.available() == true){
   cam.read();
  }
  cam.loadPixels();
  //Mirroring the image
  for(int x = 0; x < cam.width; x++){
    for(int y = 0; y < cam.height; y++){
      camMirror.pixels[x+y*cam.width] = cam.pixels[(cam.width-(x+1))+y*cam.width];
    }
  }
 camMirror.updatePixels();
  image(camMirror,0,0);
          }

How can I make this idea possible?

$
0
0

Hi. I'm 22yo design major student.

Sorry for the bad english. I might be suck to understand. I try to make some kind of interaction work that by writing some words, It becomes a short melody on processing. And you can see your typewriting like usual web environment. It don't have to be a certain word and I try to make them sound when enterkey pressed.

this is the example)

In blank space, cursor blinking. You write some short sentences. You press enterkey. It becomes little melody that matched the keycode that you pressed. Like if you write 'a little butterfly' It became 'a' note melody~ 'l' note melody~ 'i' note melody~.

I used Pfont function for the text and Minim for the sound part. However I can't make them work togher.

A little example will helps me to understand, I really appreciate.

Thanks for reading this mess.

How do you enable Mouse Wheel Events on "G4P-GUI Designer" controls

$
0
0

I am using G4P GUI Designer creating a PID Controller Screen to interface serially with a custom designed Arduino PID Controller. I created many Custom Sliders using the GUI Designer, but I do not get Mouse Wheel events through the G4P Slider Control Event Method. I want to use mouseWheel Events since it provides greater control of value settings than with mouseDragged Events, when considering my old shaky hands. I DO GET the G4P Control mouseWheel Events in my "Main Window", but how do I translate the mouseWheel(Event) to spSliderChange(Object, Event)? Or better yet, how do I get the mouseWheel Events to occur in the GUI slider event handlers?

Example Slider generated by GUI Designer (I have 10 of them total in GUI) which do not get mouseWheel Events, however the G4P controls do get mouse drag and steady events:

public void spSliderChange(GCustomSlider source, GEvent event) { //_CODE_:spSlider:950263:
  println("custom_slider1 - GCustomSlider >> GEvent." + event + " @ " + millis());
} //_CODE_:spSlider:950263:

public void createGUI() {
    G4P.messagesEnabled(false);
    G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME);
    G4P.setCursor(ARROW);
    surface.setTitle("Sketch Window");
    spSlider = new GCustomSlider(this, 120, 410, 300, 80, "blue18px");
    spSlider.setShowValue(true);
    spSlider.setShowLimits(true);
    spSlider.setRotation(PI/2, GControlMode.CORNER);
    spSlider.setLimits(0.5, 1.0, -1.0);
    spSlider.setShowTicks(true);
    spSlider.setNumberFormat(G4P.DECIMAL, 2);
    spSlider.setOpaque(false);
    spSlider.addEventHandler(this, "spSliderChange");
}

GCustomSlider spSlider;

And this in my "Main Window" which does get mouseWheel Events on slider:

void mouseWheel(MouseEvent event) {
    println(" - mouseWheel >> GEvent." + event + " @ " + millis());
}

I appreciate your input, who ever responds. I am not a GUI designer, but rather a low level 'C' and 'C++' coder. Your help is appreciated!

Thank you!


Multiple materials on an .obj? Sketchup, Meshlab

$
0
0

I have designed some 3D objects in Sketchup that I would like to display in processing. Different surfaces of the model are painted with different textures. I then export as .dae with textures which creates a folder with .jpgs of each texture. I then import into MeshLab where my textures do show up correctly. I then export as a .obj which also creates a .mtl. That mtl has a list of the "materials" and their .jpg file name. When I show the obj in processing it only paints on the last material/texture in the mtl list over the entire model, including areas which should have the earlier materials. It's either only accepting the last one or is possibly painting each material over the entire model showing only the last one.

Is there a way to get processing to accept multiple materials/textures? If I open the .obj (not the dae) in mesh lab it shows the textures correctly so I believe it's exporting correctly.

Alternatively, is there a way in mesh lab to create a single jpg from the repeated (tiled) and multiple jpgs given? I think this might be called baking. UV mapping is another keyword I don't full understand...do I need to export this separately in meshlab and can it be used by processing?

Thanks

Motion Detection

$
0
0

What's wrong with my code. When I run the code, it pops out a grey windows nothing inside there. The camera should be activated and detect motion in the screen

import processing.video.*;
int numPixels;
int[] previousFrame;
Capture video;

void setup(){
  size (640, 480);
  video = new Capture (this, width, height);
  numPixels = video.width * video.height;
  previousFrame = new int[numPixels];

}

void draw() {
  if (video.available()){
    video.read();
    video.loadPixels();
    int movementSum=0;
    loadPixels();

    for (int i = 0; i < numPixels; i++){
      color currColor = video.pixels[i];
      color prevColor = previousFrame[i];

      int currR = (currColor >> 16) & 0xFF;
      int currG = (currColor >> 8) & 0xFF;
      int currB = currColor & 0xFF;

      int prevR = (currColor >> 16) & 0xFF;
      int prevG = (currColor >> 8) & 0xFF;
      int prevB = currColor & 0xFF;

      int diffR = abs(currR - prevR);
      int diffG = abs(currG - prevG);
      int diffB = abs(currB - prevB);

      movementSum += diffR + diffG + diffB;
      pixels[i] = color(diffR,diffG,diffB);
      previousFrame[i] = currColor;
    }

   if (movementSum > 0){
     updatePixels();
     println(movementSum);
   }
  }
}

JSONObject is ambiguous - how to choose Processing's class?

$
0
0

I'm currently working on a project that uses the Twitter4j library which, along with Processing, also implements JSONObjects. I'm getting an error that reads "The type JSONObject is ambiguous" because of this. I know how to specify it so that is uses the Twitter4j JSONObject class, but how do I specify for it to use the Processing JSONObject class?

Thanks!

How can I make the text to sound?

$
0
0

Hi guys, I asked this once, but still can't make it works..

I want to make the sentence I make to convert little melody when enterkey pressed.

those are codes

import ddf.minim.*;

Minim minim;
AudioPlayer c, d, e, f, g, a, b;

PFont font;
int num = 500;
char t[] = new char[num];
int key_num = 0;
int text_w_gap = 30;
int text_h_gap = 50;
int ypos = 50;
int xpos = 10;
int val;

boolean playSong=false;

void setup() {
  size(500, 400);
  font = createFont("whiteday10-48.vlw", 14);
  textFont(font, 32);
  fill(7,161,8);
  minim = new Minim(this);

  c = minim.loadFile("c.mp3");
  d = minim.loadFile("d.mp3");
  e = minim.loadFile("e.mp3");
  f = minim.loadFile("f.mp3");
  g = minim.loadFile("g.mp3");
  a = minim.loadFile("a.mp3");
}

void draw() {
  background(0);

  if (playSong) {
    for (int i=0; i<key_num; i++) {
      playNote(t[i]);
    }
  } else
  {
    for (int i=0; i<key_num; i++) {
      text(t[i],
        (xpos+(i*text_w_gap))%width,
        ypos+( (int(xpos+(i*text_w_gap))) / width * text_h_gap));
    }
    if (key_num >= num) {
      key_num = 0;
    }
  }
}

void keyPressed() {
  if (key!=8) {
    t[key_num] = key;
    key_num++;
  } else if (key==RETURN||key==ENTER) {
    playSong=true;
  } else if (key==8) {
    key_num--;
  }
  println("pressed " + int(key) + " " + keyCode);
}

void playNote(int KeyCode) {
  if (KeyCode==65) {
    c.play();
  }
  if (KeyCode==66) {
    d.play();
  }
  if (KeyCode==67) {
    e.play();
  }
  if (KeyCode==68) {
    f.play();
  }
  if (KeyCode==69) {
    g.play();
  }
  if (KeyCode==70) {
    a.play();
  }
  if (KeyCode==71) {
    b.play();
  }
}

keycodes are just examples..

I hope someone shows me the functional code that I can understand. thanks for reading..

Hermes compatibility

$
0
0

Hi I programing a game and I discovered the framework Hermes. First I have never used a Framework so I'd like to know if i need to know some things about the code or anything and also if i can freely use it for my project. Then when I tryed to launch some of the examples from the folder, I have a compilation error which says that some of the function doesn't work.

Thanks for helping :)

Viewing all 2896 articles
Browse latest View live