Quantcast
Channel: Processing Forum
Viewing all 1768 articles
Browse latest View live

Problem with VertexShader operation

$
0
0
Hello !

I'm trying to apply a custom shader on a textured plane. 
I want to add custom attributes that represent the position (XYZ) , the rotation (XYZ) and the scale (XYZ) and apply the transformation inside the vertexShader. 

I maybe wrong but I suppose that pushMatrix method create a new Matrix3D instance , so it means one Matrix by DisplayObject and a very complex calcul for each (easy to use but deeply complex inside). It's actually possible to do not use matrix operation at all, and replace it by a few simple operations , and that's exactly what I want to do , but it doesn't work in my processing code (it works well in other languages)

My code is strongly inspired from this very old Flash-5 code that you can find here

The interesting function is here 

  1. var sx = Math.sin(axisRotations.x);
  2. var cx = Math.cos(axisRotations.x);
  3. var sy = Math.sin(axisRotations.y);
  4. var cy = Math.cos(axisRotations.y);
  5. var sz = Math.sin(axisRotations.z);
  6. var cz = Math.cos(axisRotations.z);
  7.         
  8. // rotation around x
  9. xy = cx*y - sx*z;
  10. xz = sx*y + cx*z;
  11. // rotation around y
  12. yz = cy*xz - sy*x;
  13. yx = sy*xz + cy*x;
  14. // rotation around z
  15. zx = cz*yx - sz*xy;
  16. zy = sz*yx + cz*xy;
  17. scaleFactor = focalLength/(focalLength + yz);
  18. x = zx*scaleFactor;
  19. y = zy*scaleFactor;
  20. z = yz;

This code apply a rotationX,rotationY,rotationZ on a point. 
Scale operation are only multiplications, translation are additions ; so it's all we need to create the transformation without a matrix object.

Scale and translation can be applyed after this calculation 
  1. projmodelviewMatrix * inVertex

and it works without problem.


But the rotations must be applyed on the vertex before using the projection, and the results are very weird.
If all rotations are set to zero, there is no problem ; if not, it work a little bit but it's like other calculations were applyed before and the transformations are wrong.


Here is the whole code (sorry for the very long post, I know it's not a pleasure to read it...)

  1. import java.nio.*;

  2. PImage img;
  3. PShader testShader;
  4. PGL pgl;

  5. float[] scaleXYZ;
  6. float[] positionXYZ;
  7. float[] rotationXYZ;
  8. float[] colors;

  9. FloatBuffer scaleData;
  10. FloatBuffer positionData;
  11. FloatBuffer rotationData;
  12. FloatBuffer colorData;

  13. int scaleLoc;
  14. int positionLoc;
  15. int rotationLoc;
  16. int colorLoc;

  17. void setup() {
  18.   size(640, 640, P3D);
  19.   img = loadImage("Desert.jpg");
  20.   testShader = loadShader("fragment.glsl","vertex.glsl");
  21.   
  22.   int i;
  23.   scaleXYZ = new float[12];
  24.   scaleXYZ[0] = scaleXYZ[3] = scaleXYZ[6] = scaleXYZ[9] = 200;
  25.   scaleXYZ[1] = scaleXYZ[4] = scaleXYZ[7] = scaleXYZ[10] = 200;
  26.   scaleXYZ[2] = scaleXYZ[5] = scaleXYZ[8] = scaleXYZ[11] = 1;

  27.   positionXYZ = new float[12];
  28.   positionXYZ[0] = positionXYZ[3] = positionXYZ[6] = positionXYZ[9] = 0;
  29.   positionXYZ[1] = positionXYZ[4] = positionXYZ[7] = positionXYZ[10] = 0;
  30.   positionXYZ[2] = positionXYZ[5] = positionXYZ[8] = positionXYZ[11] = 0;
  31.   
  32.   rotationXYZ = new float[12];
  33.   rotationXYZ[0] = rotationXYZ[3] = rotationXYZ[6] = rotationXYZ[9] = 0;
  34.   rotationXYZ[1] = rotationXYZ[4] = rotationXYZ[7] = rotationXYZ[10] = 0;
  35.   rotationXYZ[2] = rotationXYZ[5] = rotationXYZ[8] = rotationXYZ[11] = 0;

  36.   colors = new float[16];
  37.   colors[0] = colors[4] = colors[8] = colors[12] = 1;
  38.   colors[1] = colors[5] = colors[9] = colors[13] = 0;
  39.   colors[2] = colors[6] = colors[10] = colors[14] = 0;
  40.   colors[3] = colors[7] = colors[11] = colors[15] = 1;
  41.   
  42.   
  43.   scaleData = allocateDirectFloatBuffer(12);
  44.   scaleData.put(scaleXYZ);
  45.   scaleData.position(0);  
  46.   
  47.   positionData = allocateDirectFloatBuffer(12);
  48.   positionData.put(positionXYZ);
  49.   positionData.position(0);  
  50.   
  51.   rotationData = allocateDirectFloatBuffer(12);
  52.   rotationData.put(rotationXYZ);
  53.   rotationData.position(0); 
  54.   
  55.   colorData = allocateDirectFloatBuffer(16);
  56.   colorData.put(colors);
  57.   colorData.position(0);  
  58.   
  59.   noStroke();
  60.  
  61. }

  62. void draw() {
  63.   background(0);
  64.   translate(width / 2, height / 2);
  65.   rotateY(map(mouseX, 0, width, -PI, PI));
  66.   //rotateZ(PI/6);
  67.   
  68.   pgl = beginPGL();
  69.   
  70.   scaleLoc = pgl.getAttribLocation(testShader.glProgram, "inScale");
  71.   pgl.enableVertexAttribArray(scaleLoc);
  72.   pgl.vertexAttribPointer(scaleLoc, 3, PGL.FLOAT, false, 0, scaleData);
  73.   
  74.   positionLoc = pgl.getAttribLocation(testShader.glProgram, "inPosition");
  75.   pgl.enableVertexAttribArray(positionLoc);
  76.   pgl.vertexAttribPointer(positionLoc, 3, PGL.FLOAT, false, 0, positionData);
  77.   
  78.   rotationLoc = pgl.getAttribLocation(testShader.glProgram, "inRotation");
  79.   pgl.enableVertexAttribArray(rotationLoc);
  80.   pgl.vertexAttribPointer(rotationLoc, 3, PGL.FLOAT, false, 0, rotationData);
  81.   
  82.   colorLoc = pgl.getAttribLocation(testShader.glProgram, "inColour");
  83.   pgl.enableVertexAttribArray(colorLoc);
  84.   pgl.vertexAttribPointer(colorLoc, 4, PGL.FLOAT, false, 0, colorData);
  85.   
  86.   endPGL();
  87.   
  88.   shader(testShader);
  89.   
  90.   beginShape();
  91.   texture(img);
  92.   vertex(-0.5, -0.5, 0, 0, 0);
  93.   vertex(0.5, -0.5, 0, img.width, 0);
  94.   vertex(0.5, 0.5, 0, img.width, img.height);
  95.   vertex(-0.5, 0.5, 0, 0, img.height);
  96.   endShape();
  97.   
  98.   resetShader();
  99. }

  100. FloatBuffer allocateDirectFloatBuffer(int n) {
  101.   return ByteBuffer.allocateDirect(n * Float.SIZE/8).order(ByteOrder.nativeOrder()).asFloatBuffer();
  102. }

Here is the VertexShader

  1. uniform mat4 projmodelviewMatrix;

  2. //custom attributes
  3. attribute vec3 inScale;
  4. attribute vec3 inPosition;
  5. attribute vec3 inRotation;
  6. attribute vec4 inColour; //inColor cannot be overrided (it always a white color)
  7.                          //so I renamed it 'colour' for the test.                         
  8. attribute vec4 inVertex;
  9. attribute vec2 inTexcoord;

  10. varying vec2 vertTexcoord;
  11. varying vec4 vertColor;


  12. void main() {
  13.  
  14.   vec4 pos = projmodelviewMatrix * inVertex;
  15.   float cx = cos(inRotation.x);
  16.   float cy = cos(inRotation.y);
  17.   float cz = cos(inRotation.z);
  18.   float sx = sin(inRotation.x);
  19.   float sy = sin(inRotation.y);
  20.   float sz = sin(inRotation.z);
  21.   pos = inVertex;
  22.  
  23.   float xy = cx*pos.y - sx*pos.z;
  24.   float xz = sx*pos.y + cx*pos.z;
  25.  
  26.   float yz = cy*xz - sy*pos.x;
  27.   float yx = sy*xz + cy*pos.x;
  28.   
  29.   float zx = cz*yx - sz*xy;
  30.   float zy = sz*yx + cz*xy;
  31.   
  32.   vec4 position = vec4(zx,zy,yz,1);
  33.   
  34.   // Vertex in clip coordinates
  35.   pos = projmodelviewMatrix * position;
  36.   
  37.   
  38.   pos.xyz *= inScale.xyz;
  39.   pos.xyz += inPosition.xyz;
  40.   
  41.   gl_Position = pos;
  42.   
  43.   vertTexcoord = inTexcoord;
  44.   vertColor = inColour;
  45. }

And the FragmentShader

  1. #ifdef GL_ES
  2. precision mediump float;
  3. precision mediump int;
  4. #endif

  5. uniform sampler2D textureSampler;
  6. varying vec2 vertTexcoord;
  7. varying vec4 vertColor;

  8. void main() {
  9.   vec4 texture = texture2D(textureSampler, vertTexcoord);
  10.   texture.xyz *= vertColor.xyz;
  11.   gl_FragColor = texture;
  12. }

Thanks you for your help !


Re : choose your own adventure game with video transition

$
0
0
Please help!! Really need to get this done and Im super stumped!

Re : choose your own adventure game with video transition

$
0
0
So i think I have it really close to being done now. its not giving me any errors but isnt playing any of the videos.
Here is the code i have up to now.

int currentPage = 0;
Page[] pages = new Page[11]; //state how many pages there are.
PFont font;
int timelength = 8000;
boolean playing1, playing2;
import processing.video.*;

void setup() {
  size(864, 468);
  background(0);    
 font = loadFont("TimesNewRomanPS-BoldMT-48.vlw"); //type of font.
  textFont(font,24);  //size of font.
  for(int i = 0; i < pages.length; i++){
    pages[i] = new Page(i+".mov", i+".jpg");
    
  }
  
  {
  pages[0].setBodyText("You wake up in a forest. Cold, confused, alone. You have no idea how you ended up here. A dark presence raises the hairs on the back of your neck. Find a way to escape… with your life.\n\n\nup) travel down path    right) walk into the trees"); // text for different pages set by BodyTExt string.
  pages[0].playVideo("0.mov");
  int[] options0 = {8,0,2};//set page number to go to with the corresponding variable in the keyPressed utilizing the chooseOption object.
  pages[0].setOptions(options0);

  pages[1].setBodyText("An icy river flows before you. Attempting to cross it could prove fatal; however, the presence you have been sensing seems to be drawing nearer…\n\n\nup) Cross river     down) Go back");
  int[] options1 = {8,8};
  pages[1].setOptions(options1);
  
  pages[2].setBodyText("As you journey deeper into the woods you feel more lost than ever before. A weathered cardboard box rests beside a tree. Your curiosity is overpowering, but your urge to flee increases by the second…\n\n\nup) Travel Deeper     down) Open box");
  int[] options2 = {8,3};
  pages[2].setOptions(options2);
  
  pages[3].setBodyText("The mysterious map reveals your precise location, as though someone, or something, is playing a game with you. With four directions to choose from surely one must lead to safety, but the others may lead to your demise…\n\n\nup) North     down) South     left) East     right)West");
  int[] options3 = {4,8,8,8};
  pages[3].setOptions(options3);
  
  pages[4].setBodyText("Hours of walking has resulted in sore feet and shortness of breath. Fatigue sets in like a disease, sapping you of strength. The road before you offers a glimmer of hope, but an abandoned car intensifies your suspicion that a pursuer is not far behind…\n\n\nup) Walk along a road     down) Try door     right) Check for key");
  int[] options4 = {5,9,7};
  pages[4].setOptions(options4);
  
  pages[5].setBodyText("Traveling along the road has proven to be rewarding. A skateboard resting in the ditch might be the answer to your problems, however walking has brought you success thus far…\n\n\nup) Keep walking     left) Examine bike");
  int[] options5 = {8,5,5,8};
  pages[5].setOptions(options5);
  
  pages[6].setBodyText("The car appears empty. Fresh tire tracks mark the soft ground. Your impulse to escape overpowers your moral obligations, and it is clear that this vehicle is your only option left…\n\n\ndown) Try door     up) Check for key");
  int[] options6 = {3,2};
  pages[6].setOptions(options6);
  
  pages[7].setBodyText("As you sit in the driver’s seat you feel certain that you are not alone. Your adventure has left you parched, and an unknown beverage sitting in the cup holder could offer quick relief. The rear view mirror is adjusted incorrectly, however the thought of viewing whatever has been following you is petrifying…\n\n\ndown) Try the drink     up) Check rear view mirror     right) Start car");
  int[] options7 = {8,8,10};
  pages[7].setOptions(options7);
  
  pages[8].setBodyText("\n\n\n Press any arrow key to restart");
  int[] options8 = {0,0,0,0};
  pages[8].setOptions(options8);
  
  pages[9].setBodyText("Locked\n\n\n up)go backwards");
  int[] options9 = {4};
  pages[9].setOptions(options9);
  
  pages[10].setBodyText("Shady man win? \n\n CONGRADULATIONS              Press any arrow key to restart");
  int[] options10 = {0,0,0,0};
  pages[10].setOptions(options10);
  }

  
/*  // First movie is playing.
  mov1 = new Movie(this, "backseatpsycho.mov");
  mov1.play();
  playing1 = true;
  
  // Second movie is paused.
  mov2 = new Movie(this, "0.mov");
  mov2.pause();
  playing2 = false;*/
}

void keyPressed() { // sets up different keys to choose different options when on a certian page.
  if (key == CODED) {
    if (keyCode == UP) {
      pages[currentPage].chooseOption(0);

    }else if (keyCode == DOWN) {
      pages[currentPage].chooseOption(1);
    }else if(keyCode == RIGHT){
      pages[currentPage].chooseOption(2);
    }else if(keyCode == LEFT){
      pages[currentPage].chooseOption(3);
    }
  }
}

//void movieEvent(playVideo){
//  playVideo.play();
//}

void draw() {
  background(0);
  pages[currentPage].display();

}

class Page {
  String bodyText; //string used for displaying the text
  PImage backImg;
  int[] options;
  String playVideo;
  
   Page( String playVideo, String nameImage){
     //  bodyText = theString;
         playVideo = playVideo;
     backImg = loadImage(nameImage);
     // myMovie = new Movie (this, nameMovie);
     // myMovie.play(); 
  }
  
  void setBodyText(String theString) {// sets a string for the bodytext object
    bodyText = theString;
  }
  
  void setOptions(int[] theOptions) {
    options = new int[theOptions.length];
    arrayCopy(theOptions, options);
  }
  
  void playVideo(String theString){
    playVideo = theString;
  }
  
  
  void display() { //sets display option for text to be centered and have a buffer zone of 20 pixels.
    image(backImg, 0, 0);
    textAlign(CENTER);
    fill(#03FF00);
    text(bodyText, 20, 20, width-20, height-20);
  }
  void chooseOption(int theNum) {
    if (theNum < options.length) 
      currentPage = options[theNum];
  }
  }

Get zbuffer in Processing v2b6

$
0
0
Hi,

I am trying to access the zbuffer of a Scene in Processing 2b6.
The idea is to port this project to processing v2.

It seems that the object FloatBuffer hasn't got the array zbuffer anymore.
So I tried with the commented code that tries to acces the zbuffer using OpenGL:

  1. PGraphicsOpenGL pogl = (PGraphicsOpenGL) g;
  2. FloatBuffer zbuff = FloatBuffer.allocate(1);
  3. pogl.gl.glReadPixels( mouseX, mouseY, 1, 1, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, zbuff);
  4. float z = zbuff.get();
At first I had some issues with the 5fth parameter GL.GL_DEPTH_COMPONENT, but by switching it to GL2.GL_DEPTH_COMPONENT I solved that first obstacle.
But now I am receiving z = 1 for every mouse position.

Any ideas?

Thanks!

Re : Get zbuffer in Processing v2b6

$
0
0
first, one detail with the glReadPixels() call: you should use height - mouseY - 1 instead of mouseY, because of the inverted Y axis in Processing with respect to OpenGL.

Any of the two following code options are valid:
  1. import java.nio.*;
  2. void setup() {
  3.   size(640, 360, P3D);
  4.   fill(204);
  5. }
  6. void draw() {
  7.   lights();
  8.   background(0);
  9.   camera(30.0, 300, 220.0,
  10.          0.0, 0.0, 0.0,
  11.          0.0, 1.0, 0.0);
  12.   noStroke();
  13.   box(90);
  14.   stroke(255);
  15.   line(-100, 0, 0, 100, 0, 0);
  16.   line(0, -100, 0, 0, 100, 0);
  17.   line(0, 0, -100, 0, 0, 100);

  18.   PGraphicsOpenGL pg = (PGraphicsOpenGL) g;
  19.   PGL pgl = pg.beginPGL();
  20.   FloatBuffer zbuff = FloatBuffer.allocate(1);
  21.   pgl.readPixels(mouseX, height - mouseY - 1, 1, 1, PGL.DEPTH_COMPONENT, PGL.FLOAT, zbuff);
  22.   float z = zbuff.get();
  23.   pg.endPGL();

  24.   println(z);
  25. }
or
  1. import java.nio.*;
  2. import javax.media.opengl.GL;
  3. import javax.media.opengl.GL2;
  4. void setup() {
  5.   size(640, 360, P3D);
  6.   fill(204);
  7. }
  8. void draw() {
  9.   lights();
  10.   background(0);
  11.   camera(30.0, 300, 220.0,
  12.          0.0, 0.0, 0.0,
  13.          0.0, 1.0, 0.0);
  14.   noStroke();
  15.   box(90);
  16.   stroke(255);
  17.   line(-100, 0, 0, 100, 0, 0);
  18.   line(0, -100, 0, 0, 100, 0);
  19.   line(0, 0, -100, 0, 0, 100);

  20.   PGraphicsOpenGL pg = (PGraphicsOpenGL) g;
  21.   PGL pgl = pg.beginPGL();
  22.   FloatBuffer zbuff = FloatBuffer.allocate(1);
  23.   pgl.gl.glReadPixels(mouseX, height - mouseY - 1, 1, 1, GL2.GL_DEPTH_COMPONENT, GL.GL_FLOAT, zbuff);
  24.   float z = zbuff.get();
  25.   pg.endPGL();
  26.   
  27.   println(z);
  28. }
But testing both on 2.0b6 I get 0 for all positions on the screen, so there seems to be something off here. But running them on the latest revision from the repo gives non-zero values that appear to be correct. So the upcoming 2.0b7 should solve this issue.


Re : How to use PShader.bind / PShader.unbind ?

$
0
0
You should bind after beginPGL() and unbind before endPGL().

Re : Get zbuffer in Processing v2b6

$
0
0
Yes it works!

The first implementation with the processing-core repo at google code worked.

The second one throwed an exception,

Caused by: java.lang.IncompatibleClassChangeError: Expected static field processing.opengl.PGL.gl
at:
pgl.gl.glReadPixels(mouseX, height - mouseY - 1, 1, 1, GL2.GL_DEPTH_COMPONENT, GL.GL_FLOAT, zbuff);

But anyways thank you very much Andrés

--
Ing. David Alberto Montaño

reading and writing audio buffers with minim

$
0
0
      When I read an audio buffer with a FOR loop (L, R, Mixed) I get a corrupt wave forms.  I looks like processing/minim gets part way through the buffer and it's overwritten by the audio card hardware.  I think processing/minim can't read 16 bit words fast enough.  The buffers are being overwritten about 4 times with a 1024 length buffer.  The 16 bit words in the buffer represent samples at a 44100 Hz rate so if i pick a waveform frequency that's a multiple of 2 the buffer will always have the same data and the waveform will look correct even while the buffer has been overwritten. When I use a 344.5313 Hz (44100/128) the waveform in the buffer is static and uncorrupted.  (Note 128 = 2^7)  

      My question is if processing/minim can read all 1024 16 bit words with a read array buffer command?  This may be faster than by reading each element with the FOR loop.   What do you think?  As I am very new to minim could you include some code with your comments.

      My next question is if minim can take raw 16 bit data from processing to generate periodic sounds?  Can you write to the audio buffers.  What do you think?  Please include some code with your comments.

Re : Problem with VertexShader operation

$
0
0
You are applying the projection-modelview matrix two times in your vertex shader:
  1. vec4 pos = projmodelviewMatrix * inVertex;
and
  1. pos = projmodelviewMatrix * position;
That might be causing the problem.

How I stop soundfiles from overlapping when using the Minim library?

$
0
0
So I'm triggering a bunch of audio snippets using the AudioSnippet object, rather than trigger which had this weird doubling effect. How I can stop one file from playing when another is selected? I have about 20 files. Any help appreciated!

Re : How I stop soundfiles from overlapping when using the Minim library?

$
0
0
if (snippet1.isPlaying()) {
  snippet2.pause();
}

Re : Problem with VertexShader operation

$
0
0
Hello Andres !

It's an error... I forgot to remove it before posting the code...  
(At the end I tryed everything like apply this function at the beginning of the code to see if something happened (because I have no problem with the code located after the projection-modelview...)

Actually, this extra line of code shouldn't do anything because I didn't use the result of the calcul anywhere 


Thank you !


how to video capture only a portion of the screen

$
0
0
I've been working on this code which has a live feed of a webcam in the centre of the screen, and when you press 'a' it takes a screen shot, and then displays it in a grid on the screen around the live feed. The problem is that it takes a full screen shot, so all the photos around the web cam are smaller, can anyone suggest something?
Thanks
heres the code so far:

import processing.video.*;

int w = 640;  
int h = 480; 
int fps = 25;  
int i = 0;
PImage img;
PImage img2;
PImage img3;
PImage img4;
PImage img5;
PImage img6;
PImage img7;
PImage img8;
Capture cam;  

void setup()
{
  size(screen.width, screen.height, P3D);  

  frameRate(fps);    

  cam = new Capture(this, w, h);  
  img = loadImage("person-1.tif" );
  img2 = loadImage("person-2.tif" );
   img3 = loadImage("person-3.tif" );
    img4 = loadImage("person-4.tif" );
     img5 = loadImage("person-5.tif" );
      img6 = loadImage("person-6.tif" );
       img7 = loadImage("person-7.tif" );
        img8 = loadImage("person-8.tif" );
}

void draw()
{
//drop blue moon logog in here
  if (cam.available() == true) {  
    cam.read();
  }

  image(cam, width/3, height/3, width/3, height/3); 
  //}else{
  //image(
  //  image(
  //}

  tint(17);             
  noTint();           
 image(img, 0, 0, width/3, height/3);
 image(img2, width/3, 0, width/3, height/3);
 image(img3, 2*width/3, 0, width/3, height/3);
 image(img4, 0, 266, width/3, height/3);
 image(img5, 2*width/3, 266, width/3, height/3);
 image(img6, 0, 532, width/3, height/3);
 image(img7, width/3, 532, width/3, height/3);
 image(img8, 2*width/3, 532, width/3, height/3);
  
  if (keyPressed == true) {
    if (key == 'a') {
      filter( BLUR, 3 );
      filter( POSTERIZE, 12 );
      if (i < 8) {
        i++;
      }
      else i = 0;
      saveFrame ("person-"+i);
    }
//    if (key == 'b') {
//      image(img, 0, 0, 200, 200);
//    }
  }
}

Re : how to video capture only a portion of the screen

$
0
0
You can grab a rectangular section of the screen with "get(x,y,w,h);" which returns a PImage.

Re : how to video capture only a portion of the screen

$
0
0
i was wanting it to be part of the saveframe section, i dont know if thats possible?

Re : how to video capture only a portion of the screen

$
0
0
  1. PImage img = get(some part of the sketch);
  2. img.save(savePath(insertFrame(filename)));
The second line is what is in the saveFrame() function.

There is also an article that might interest you:
From several variables to arrays

Issues with controlling video clips.

$
0
0
Fairly new to Processing, and could use some help and input. I'm working on a project in which it's necessary to control at least two video clips. I've been using the Processing Movie reference and also this tutorial from Elie Zananiri.

The basic gist is, one video should play constantly on a loop, until a switch (like a key press) makes a second video play, and once that video is done playing, the first video should return to automatic loop, until that switch goes off again.

Through these resources I've been able to set up a basic code, where pressing a key ('1') makes one video loop, pressing another ('2') makes that loop stop and play a second video. That's where I run into problems, so here are my questions:
  1. Pressing '2' again does not make the second video play again. Once it's played one time, it can't be played a second or third. Is there a workaround?
  2. The videos load in layers. Even though I can't make the second video play a second time, I can get the first video to begin looping again after pressing '1'. However, because they load in layers, it is covered by the second, unplayable video. How do I get it to play on top, or to not load in layers?
  3. I need to find a way to make the first video play as soon as the second video is finished, but all the commands within the Processing reference only allow them to play simultaneously. I have considered using a timer for this but am not sure how to proceed or if that's even the right answer. I've had friends and mentors suggest state machines, but that seems like it might be a little complicated for something that ought to be simple. 
  4. Do if/then statements exist within Processing? The book I have on the subject only covers if/else statements and a Google search turned up no answers, so I'm thinking they might not.
Code:

  1. import processing.video.*;

  2. Movie dobBark; // adds variable for Doberman Bark video
  3. Movie dobStop; // adds variable for Doberman Stop video

  4. void setup() { 
  5.   size(480, 272); // defines size of the video window -- needs tweeking.
  6.    dobBark = new Movie(this, "dobBark.m4v"); // loads Doberman Bark vid.
  7.    dobStop = new Movie(this, "dobStop.m4v"); // loads Doberman Stop vid.
  8. }

  9. void draw() { 
  10.    image(dobBark, 0, 0); // without this code, none of the videos will show up
  11.    image(dobStop, 0, 0);

  12. void movieEvent(Movie m) { 
  13.   m.read(); // not really sure what this does but you need it.

  14. void keyPressed() { 
  15.   if(key=='1'){ 
  16.     dobBark.loop(); // if you press the 1 key, Doberman Bark video will loop.
  17.   }
  18.   
  19.   if(key=='2') {
  20.     dobBark.stop(); // if you press the 2 key, the Doberman Bark video will stop
  21.     dobStop.play(); // and the Doberman Stop video will play only once.
  22.   }
I have tried placing a loop command directly after dobStop.play();, and have tried using an if/else statement (if no input, play dogBark, else play dobStop) to no avail, but that might have been due to my inexperience with syntax. Please help! And deepest apologies if I'm doing something totally stupid and haven't noticed.

sound output from an array of floats from processing

$
0
0
      Is it possible for minim to play an array of foats generated in processing?   My processing sketch produces arrays representing signal amplitude as a function of time.  It's basically pulse code modulation (PCM), and is the simplest way of representing sampled audio.

writing sound file formats in processing and minim

$
0
0
Can Processing write sound files directly so they could be played with Minim?

Re : video playlist

$
0
0
Hey
I am trying to work with a videoplaylist. I would like to choose one video out of an array, play it and if the clip is finished, play the next video.

If the current time of the first clip is bigger than the 90 percent of the durration, the current clip stops, but no other movie clip out ouf the array starts to play. Why?

I have even tried to paint a image over the last frame of the clip. But even this does not work.
Do you know if my if-claus? And if not, why not?

It would be great if anyone could help me :)

Many thanks

  1. import processing.video.*;
    //PImage img;
    Movie[] movies = new Movie[5];
    int rnd = int(random(0, 4));
    int w = 640;
    int h = 480;

    void setup()
    {
      size(w, h);

      background(255);

      //img = loadImage("screenshot_320.jpg");
      movies[0] = new Movie(this, "Sequence 01_1_1.mov");
      movies[1] = new Movie(this, "Sommer.mov");
      movies[2] = new Movie(this, "Sequence 01_1_1.mov");
      movies[3] = new Movie(this, "Sommer.mov");
      movies[4] = new Movie(this, "Sequence 01_1_1.mov");

      movies[rnd].play();
    }

    void draw()
    {

      background(255);
      image(movies[rnd], 0, 0);

      float currTime = movies[0].time();
      float duration = movies[0].duration();
      if (currTime > duration*0.9) {
        movies[rnd].stop();
        rnd = int(random(0, 4));
        movies[rnd].play();
        image(movies[rnd], 0, 0);
       // image(img, 0, 0);
      }
    }


    // Called every time a new frame is available to read
    void movieEvent(Movie m) {
      m.read();
    }

Viewing all 1768 articles
Browse latest View live