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

how to introduce speech recognition into game.

$
0
0

Hi,

I am currently working on a university final year project, where I am taking an existing piece of work and adding a useful element to it. I have started building the classic brick breaker game but I am not sure how can i use the speech-to-text library to introduce speech commands into the game, such as 'Run' to start the game and move the paddle by saying 'L' or 'R' (Left and Right).. I would like to configure the commands to the amount of pixels the paddle moves across..such as have default commands set as '30 pixels' and further commands such as 'L1' and 'R2' could be used to move a further distance '40pixels' maybe.

Thank you.

Current Code:

        float ballX;        // x coordinate of the ball
        float ballY;        // y  coordinate of the ball
        float ballW;        // width of the ball
        float ballH;        // height of the ball
        float moveBallX;    // move the ball from left to right randomly
        float moveBallY;    // move the ball from top to bottom randomly
        float paddleX;      // x coordinate of the paddle
        float paddleY;      // y coordinate of the paddle
        float paddleW;      // width of the paddle
        float paddleH;      // height of the paddle
        float movePaddleX;  // move the paddle left or right by 30 pixels



        void setup () {

          size (350, 400);

          // Ball parameters; initial x, y coordinates, and width, height of the ball.
          ballX = 20;
          ballY = 20;
          ballW = 15;
          ballH = 15;

          // Move the ball's coordinate positions randomly in the game.
          moveBallX = random(1, 4);
          moveBallY = random(1, 4);

          // Paddle parameters; initial x, y coordinates, and width, height of the paddle.
          paddleX = width/2;
          paddleY = height - 20;
          paddleW = 50;
          paddleH = 10;

          // Move the Paddle's coordinate position
          movePaddleX = 30;
        }

        void draw () {
          background (0);
          ellipse (ballX, ballY, ballW, ballH); // ball
          noStroke();
          rect (paddleX, paddleY, paddleW, paddleH); // paddle

          // Add the moving motion to the ball.
          ballX = ballX + moveBallX;    //the current x position of the ball is moved by the variable moveBallX.
          ballY = ballY + moveBallY;    ///the current y position of the ball is moved by the variable moveBallY.


          //IF statements to control the ball's x coordinate, rebounce the ball when it hits the right or left edge.

          if (ballX > width) {
            moveBallX = -moveBallX; // The values become the opposite, and allow a rebounce.
          }

          if (ballX < 0) {

            moveBallX = -moveBallX;  // The values become opposite, and allow a rebounce.
          }

          //IF statements to control the ball's y, rebounce the ball when it hits the top or bottom edge.

          if (ballY > paddleY)       // 'paddleY' is used instead of 'height'. to show a bounce on the paddle.
          {
            moveBallY = -moveBallY; // The values become the opposite, and allow a rebounce.
          }

          if (ballY < 0) {

            moveBallY = -moveBallY; // The values become the opposite, and allow a rebounce.
          }

        }

        void keyPressed() {
          if (key == CODED) {
            if (keyCode == LEFT) {         //when the LEFT key is pressed, the paddle is moved to the left by 30 pixels.

              paddleX = paddleX - movePaddleX;
            } else if (keyCode == RIGHT) {  //when the RIGHT key is pressed, the paddle is moved to the right by 30 pixels.

              paddleX = paddleX + movePaddleX;
            }
          }
        }


        //Help acquired from the following sources:
        //https://processing.org/examples/
        //http://www.openprocessing.org/sketch/134612
        //http://drdoane.com/thinking-through-a-basic-pong-game-in-processing/

g4p: Scale text according to panel size

$
0
0

Hello,

is there a way to scale a text according to the size of the superior container? The size of the container depends on the sketch size which is set before running. I could change font size for every possible case, but i still hope there is an easier and more accurate solution for my problem.

Thanks and Greetings

How can I change the sprite in S4P during the game?

$
0
0

I want to change the image loaded in an instance of a sprite in S4P, just as in Pacman when the image of a ghost changes. I cannot find any method in the library to do this. Shall I create an instance for each sprite, hide a sprite and show the other one at the same place when needed? Any thoughts appreciated.

Webcam and video on 64 bit

$
0
0

I've been working for some time on a program using the usual import processing.video.*; and had no problem with it. Now for no apparent reason processing is telling me that video is only compatible with 32 bit applications, but it worked just fine until yesterday. I've been programming on win 7 ultimate 64 bit. I just need to get an image from my webcam, if there is some easy workaround please tell me...

Live Video Streaming

$
0
0

i have a problem, when i live stream my video ,it will record but when i make it stop . it will make all my program hang and then i need to reset . can anyone of you let me know how i can overcome with this issue and it will not disturbed my other code and work perfectly

here is my code :

// Save video file import processing.video.*; //import org.jcodec.api.awt.AWTSequenceEncoder8Bit;

import org.apache.log4j.BasicConfigurator; import java.awt.image.BufferedImage; import java.io.File;

Capture cam; AWTSequenceEncoder8Bit enc; String videoName; String audioName; boolean recording;

void setup() { size(640, 480); background(0); BasicConfigurator.configure(); cam = new Capture(this, width, height); videoName = "beat.mp4"; recording = false; int fRate = 10; frameRate(fRate); cam.start(); try { enc = AWTSequenceEncoder8Bit.createSequenceEncoder8Bit(new File(dataPath(videoName)), fRate); } catch (IOException e) { e.printStackTrace(); } }

void draw() { image(cam, 0, 0); if (recording) { BufferedImage b = (BufferedImage) cam.getNative(); try { enc.encodeImage(b); } catch (IOException e) { e.printStackTrace(); } } }

void captureEvent(Capture c) { c.read(); }

void mousePressed() { recording = !recording;

}

void keyPressed() {

if (keyCode == 32) {

try {

  enc.finish();
}
catch (IOException e) {

  e.printStackTrace();
}

}

}

How can I make this sound play every time the snake eats a square?

$
0
0

So i'm makin' a snake game as a project, and fortunately i'm almost there. The last thing I need is to make a sound every time the snake eats one of the random squares, but as it is right now, it only plays the sound the first time. How can I fix this?

Another thing I don't know how to do is to make a restart button for the game over screen. How can I make a function that makes the game start all over again as if you closed the window and run the code over again?

Project file here, and make sure to have the minim audio extension installed!

http://www.filedropper.com/snake_2

controlP5 : changing color of bang, button, sliders.

$
0
0

How to change the colors of bang, button and sliders? TIA.

Methods not visible in self made library

$
0
0

Hi.

I have made a library to enable some quicker and easier interaction. I made it in eclipse, which does not find any errors. I have also tried to import it into Processing, which at least does not seem to give an errors about importing the library or declaring class instances. But it can not use any of the methods defined in the library. For example, when I try to call a constructor:

import quickInteraction.*; QuickInteraction qi = new QuickInteraction(this);

I get the error "The constructor QuickInteraction(PApplet) is not visible". However I know that the constructor with that parameter are in the library and both class and constructor are public.

If anyone can help, please do. And if more code pieces from the library are needed, please ask, and I shall deliver. Thank you.


look At

$
0
0

can someone help me with this :

if i want to make/code something like " look at " (trekking object ,locking it and then make my camera follow that object automatically ). how can i do that , can you guide me on that ?

Horizontal scrolling

$
0
0

hello, i would like to add a horizontal scolling bar to this sketch since i "lost" some data at the end of the windows

partialSave

i can't use the example in the reference since it uses an immage. Really i tried to use it but without good results. any idea? maybe i miss a library that could help me?

Can Minim play more than one song at the same time?

$
0
0

Hi everyone!

I was wondering if you guys know if minim could play more than one song at a time? I am trying to use an fsr sensor to detect when someone is pressing on a certain area of a mouse pad (which is already working in arduino) which then communicates with processing and plays the song according to the fsr sensor.

The problem is that i'm not sure if minim can support playing 2 .mp3's at once.

Thanks in advance!!

Import location and velocity data from txt

$
0
0

Hello, I have a txt file that contains the location and velocity data for particles and I am trying to import it in processing but I have problem with the syntax. Here is an example of my txt file:

0.671470046043 0.0592122897506 -0.597842812538 0.165664941072 2.11239433289 0.165294915438,0.734478414059 0.0503597855568 -0.534131884575 0.207550317049 1.82068312168 -0.327298223972,0.784207165241 0.0618093051016 -0.443658143282 0.095640823245 2.19577264786 -0.197497576475

which is actually loc1.x loc1.y loc1.z vel1.x vel1.y vel1.z, loc2.x loc2.y loc2.z vel2.x vel2.y vel2.z, .....

here is the code that I am trying to write

  void importPts() {
    String[] pointsA = loadStrings(loadPts);
    importParticles = new Particle[pointsA.length];
    for (int i = 0; i < pointsA.length; i++) {
      String a = pointsA[i];
      String[] a1 = split(a, ',');
      float x1 = float(a1[0]);
      float y1 = float(a1[1]);
      float z1 = float(a1[2]);
      float v1 = float(a1[3]);
      float v2 = float(a1[4]);
      float v3 = float(a1[5]);
      Vec3D loc1 = new Vec3D(x1, y1, z1);
      Vec3D vel1 = new Vec3D(v1,v2,v3);
      Particle pt = new Particle(loc1,vel1);
      importParticles[i]=pt;
    }
  }

for some reason I don't seem to be getting any results. Any idea of what I'm doing wrong?

thank you for the help!

Making a basic music sequencer with minim

$
0
0

I've started on a project to create a music sequencer with minim using instrument classes and playNote functions etc. I've got a sequence of notes working ok, but I have no way of looping them. Here's the main code:

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

Minim       minim;
AudioOutput out;
Delay myDelay;
int i;
int endSeq;

public void settings() {
  size(800, 300, P2D);
}

void setup() {

  minim = new Minim(this);
  out = minim.getLineOut();
  myDelay = new Delay(1.5,0.5, false,false);
  bassSeq(); // starts bass sequence function
  chordSeq(); // starts chord sequence function
}

void draw() {
}

And here's the bassSeq function which describes the whole bass sequence:

void bassSeq(){
float[] stepArray = {0.00, 0.75, 2.00, 2.5, 2.75, 3.5, 4, 4.5};
float[] decayArray = {1.0, 0.5, 0.5, 0.5, 0.5, 0.2, 0.5, 1.0};
float[] noteArray = {C2, F2, E2, G2, B2, C2, C2, B2};

for (i = 0; i <= 7; i++){

  out.pauseNotes();
  out.setTempo(125);
  out.playNote(stepArray[i], decayArray[i], new BassInstr(noteArray[i], 0.5, out ) );
  out.resumeNotes();

}
}

The problem is, if I put these functions in setup, they only play once. What ideally I'd want to do is iterate back to the start of i=0 so it gives the instruments the sequence from the start of the array after it is finished one loop. If I put the sequence functions in the draw loop, it sends the instrument notes incredibly fast (prob around 60fps if that's the default for draw). I've put a delay() function in the draw loop which does actually loop the music after the time but there's no way of giving delay a number that is totally accurate so it loops accurately.

Some help would be appreciated.

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

Processing and Phidgets

$
0
0

hi. Somebody here work with Processing and Phidgets? Thank you


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

$
0
0

Hi guys,

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

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

I also get error with permission thing.

say:

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

So I google

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

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

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

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

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

Getting audio and video in sync

$
0
0

Hi,

I have some code to play a video with different soundtracks (or sometimes no sound) and I can't seem to get them in sync. The sound plays noticeably behind the video, maybe by about a third to a half of a second. Any ideas?

import processing.video.*;
import processing.sound.*;

Movie video;
SoundFile audio;

void setup() {
  size(640, 360);
  background(0);
  video = new Movie(this, "test.mp4");
  audio = new SoundFile(this, "test.mp3");

  video.play();
  audio.play();

}

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

void draw() {
  image(video, 0, 0, width, height);
}

Resizing a captured image?

$
0
0

I'm trying to make a program that captures an image from the webcam, then reloads the captured image in different places on the screen. I'll do more with it later, but I want to iron this problem out before I do any more. My problem is that I want to resize the image that I capture from the webcam when it loads into the program, but it justs crops the image. Is there any way to solve this? My current code is as follows:

import processing.video.*;

Capture cam;

PImage still;

void setup() {
  //window size
  size(1280, 720, P3D);
  noCursor();
  //webcam feed
  still = loadImage ("capture.jpg");
  imageMode (CENTER);

  String[] cameras = Capture.list();

  //webcam feed
  if (cameras.length == 0) {
    println("There are no cameras available for capture.");
    exit();
  } else {
    println("Available cameras:");
    for (int i = 0; i < cameras.length; i++) {
      println(cameras[i]);
    }

    cam = new Capture(this, cameras[0]);
    cam.start();
  }
}

void draw() {
  if (cam.available() == true) {
    cam.read();
  }
  //web cam feed position, size
  image(cam, 640, 360, 320, 180);
}

void mousePressed() {
  //image capture
  saveFrame("data/capture.jpg");
  cam.read();

  //loads image capture in
  image (still, 200, 200, 160, 90);
}

How to export video to a folder other than the root of the project

$
0
0

Hey guys!

I'm making a little application that basically allows users to record small video diaries from their webcam and integrated mic. (It'll be used as a design probe). I've made everything work using the VideoExport and Minim libraries, but I can't possibly set it up so the exported videos get saved into another folder! I tried this:

videoExport = new VideoExport(this,"logs/log"+nameid+".mp4",cam);

but it yields "Could not run the sketch (Target VM failed to initialize)".

When I try it with the minim recorder:

recorder = minim.createRecorder(mic,"logs/log"+nameid+".wav");

it yields NullPointerException. Am I doing something wrong? Thanks for the help

Processing - random video array + webcam (to make security camera-type visuals)

$
0
0

I'm attempting to make the visuals for an art installation I'm working on, and I'm not quite sure how to go about it in Processing. Here's what I would like to do (I'll be using an old CCTV monitor):

  • Divide the screen into four quadrants (as if it were displaying feed from security cameras, but I'd be using videos, for the most part)

  • Have videos load randomly to those quadrants (from a total of 8 videos) and have the videos change after a certain number of seconds (they don't all have to change at once, but whatever's easiest)

  • Have a webcam send its feed into one of the quadrants as if it were another video (I can always fix the webcam to one of the fourths of the screen and load random videos onto the other 3 available quadrants, if it simplifies things.)

My Processing skills are quite basic; so far I've managed to split the screen in 4 and load 4 videos, but I honestly don't know how to work with a video array, which sounds like the more reasonable way for the program to do what I would like it to.

Here is the basic code:

import processing.video.*;

Movie mov, mov1, mov2, mov3;

void setup() {
  size(1280, 640);
  frameRate(30);
  mov = new Movie(this,"0.mov");
  mov1 = new Movie(this,"1.mov");
  mov2 = new Movie(this,"2.mov");
  mov3 = new Movie(this,"3.mov");

  mov.play();
  mov1.play();
  mov2.play();
  mov3.play();

  mov.volume(0);
  mov1.volume(0);
  mov2.volume(0);
  mov3.volume(0);
}

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

void draw() {
  image(mov, 0, 0, 640, 320);
  image(mov1, 640, 0, 640, 320);
  image(mov2, 0, 320, 640, 320);
  image(mov3, 640, 320, 640, 320);
}

I started out with the above and then tried working with an array of videos, but only got so far:

import processing.video.*;

Capture cam;

int maxmyMovies = 8;
int myMoviesIndex = 0;
Movie[] myMovies = new Movie[maxmyMovies];

void setup() {

size(640,480);

cam = new Capture(this, 640, 480, 12);
cam.start();
smooth();

   for (int i = 0; i < myMovies.length; i ++ ) {
    myMovies[i] = new Movie(this, i + ".mov");

   }
}

void draw() {
 image(myMovies[myMoviesIndex], 0, 0);

  if (key == 'r') myMoviesIndex = int(random(0,8));

}

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

(The above is just copy/paste from other codes, I don't really want it to randomize when pressing the letter "r" but rather after a set time.) So, you can see I'm at a loss here... I would really appreciate any help.

Thanks!!

Viewing all 2896 articles
Browse latest View live