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

Processing 3 + SublimeText 3 + HYPE - Duplicate method setup() in type build

$
0
0

I'm trying to get SublimeText3 setup using Processing3 and the HYPE library. I'm trying to run some sample code but keep getting an error.

When I build my sketch I keep getting this: build.pde:1:0:1:0: Duplicate method setup() in type build

Here's the code I'm trying to run...

import hype.*;

void setup() {
    size(640,640);
    H.init(this).background(#242424);

    HRect rect1 = new HRect(100);
    rect1.rounding(10);         // set corner rounding
    rect1.strokeWeight(6);      // set stroke weight
    rect1.stroke(#000000, 150); // set stroke color and alpha
    rect1.fill(#FF6600);        // set fill color
    rect1.anchorAt(H.CENTER);   // set where anchor point is / key point for rotation and positioning
    rect1.rotation(45);         // set rotation of the rect
    rect1.loc(100,height / 2);  // set x and y location
    H.add(rect1);

    // here's the same code / with method chaining

    HRect rect2 = new HRect(100);
    rect2
        .rounding(10)
        .strokeWeight(6)
        .stroke(#000000, 150)
        .fill(#FF9900)
        .anchorAt(H.CENTER)
        .rotation(45)
        .loc(247,height / 2)
    ;
    H.add(rect2);

    // here's the same code / minus the hard returns and tabbing

    HRect rect3 = new HRect(100);
    rect3.rounding(10).strokeWeight(6).stroke(#000000, 150).fill(#FFCC00).anchorAt(H.CENTER).rotation(45).loc(394,height / 2);
    H.add(rect3);

    H.drawStage(); // paint the stage

    // here is the non HYPE version / basic processing syntax

    pushMatrix();
        strokeWeight(6);
        stroke(#000000, 150);
        fill(#FF3300);
        translate(width - 100, (height / 2));
        rotate( radians(45) );
        rect(0, 0, 100, 100, 10, 10, 10, 10);
    popMatrix();

    /*

    thoughts : well in the processing version you'd have to use push and pop
    matrix to perform the rotation and positioning. I find this difficult to explain
    to designers that you're not rotating the rect but the entire stage.

    not having the ability to adjust an "anchor" position means we have to calculate
    the rect's y coordinate to get it centered so trying to subract half of the rect's height

    translate(width - 100, (height / 2) - 50); // nope still doesn't center

    this is because a 100 x 100 rectangle rotated 45 degrees now sits at 141 x 141 (approx)
    this would mean we'd have to offset like so :

    translate(width - 100, (height / 2) - 70.5);

    */

    // draw where the horiz line is

    strokeWeight(1);
    stroke(#0095a8);
    line(0, height/2, width, height/2);

    noLoop();
}

void draw() {

}

Any help would be greatly appreciated!!! Thanks


How to stop audio from overlapping?

$
0
0

I'm fairly new to processing, started in september. In my class right now were making experments based off of pacman. Right now I'm trying to have the waka waka sound play upon a key press and use loop to repeat it. The problem is that as I continue to use the keys the sound starts over again mutiple times overlapping each over. How can I make the audio run once until the key is released to stop the sound and repeat itself again.

Live Audio Translating Into Hue Change

$
0
0

Hello everyone!

So for this assignment I have to take either an audio file or live audio input and have it translate to a hue change on a photo! Overall it seems pretty simple but I'm stuck on how to put the information in to change the hue. I've inserted what I have so far below.

    import ddf.minim.*;
    import ddf.minim.signals.*;
    import ddf.minim.analysis.*;
    import ddf.minim.effects.*;
    PImage img;

    Minim minim;
    AudioInput in;

    void setup()
    {
        img = loadImage("Ash.jpg");
        size( 540, 687 );
        smooth();

        minim = new Minim( this );

        in = minim.getLineIn( Minim.STEREO, 512 );

        background(img);
    }

    void draw()
    {
    }
    void stop()
    {
        in.close();
        minim.stop();
        super.stop();
    }

Emojis Over OSC / UDP

$
0
0

The oscP5 library (for sending/receiving OSC over UDP) is stuck in UTF-8 character encoding. I've tried playing with byte-converting code, but everything I can find on character encoding is from processing v1/2 circa 2007.

I don't expect these emojis to display properly in the console, but i'm working with a JSON file that contains user generated content. I'd love some help figuring out how to move emojis from one processing sketch to another, across the network over OSC.

thx in advance

How to get a sound to play when I click an object

$
0
0
import ddf.minim.*;
int rad = 30;                                   // Width of the shape
float xpos, ypos;                               // Starting position of shape
float xspeed = 4.5;                             // Speed of the shape
float yspeed = 4.5;                             // Speed of the shape
int xdirection = 1;                             // Left or Right
int ydirection = 1;                             // Top to Bottom
int score=0;                                     //Inital score
int lives=5;                                     //Number of lives you start with
boolean lost=false;                              //Have you lost yet?
int speed=1;
PImage bg;
int y;
AudioPlayer player;
Minim minim;

void setup()
{
  size(1297, 736);
  minim = new Minim(this);
  fill(0,0,0);
  noStroke();
  frameRate(60);
  ellipse(xpos, height/10,100,100);
  xpos = width/2;                               // Set the starting position of the shape
  ypos = height/2;
  bg = loadImage("stem.jpg");                   //Load Image (jpg,png,gif)
  player = minim.loadFile("Song.wav");          //Load Audio File (mp3,wav)
  player.loop();

}

void draw()
{
  background(bg);

  xpos = xpos + ( xspeed * xdirection );         // Update the position of the shape
  ypos = ypos + ( yspeed * ydirection );


  if (xpos > width-rad || xpos < rad) {          // Test to see if the shape exceeds the boundaries of the screen
                                                 // If it does, reverse its direction by multiplying by -1
    xdirection *= -1;
  }
  if (ypos > height-rad || ypos < rad) {
    ydirection *= -1;
  }


  ellipse(xpos, ypos, rad, rad);                    //Draw the shape
  text("score = "+score,10,10);                     //Print the score on the screen
  text("lives = "+lives,width-80,10);               //Print remaining lives
  if (lives<=0)                                     //Check to see if you lost
  {
    textSize(50);
    text("Click to Restart", 450,200);
    noLoop();                                       //Stop looping at the end of the draw function
    lost=true;
    textSize(13);
  }
}
void mousePressed()                                 //Runs whenever the mouse is pressed
{
  if (dist(mouseX, mouseY, xpos, ypos)<=rad)        //Did we hit the target?
  {
    score=score+speed;                              //Increase the speed
    speed=speed+1;                                  //Increase the Score
  }
  else                                              //We missed
  {
    if (speed<1)                                    //If speed is greater than 1 decrease the speed
    {
    speed=speed-1;
    }
    lives=lives-1;                                  //Take away one life
  }
  if (lost==true)                                   //If we lost the game, reset now and start over
  {
    speed=1;                                        //Reset all variables to initial conditions
    lives=5;
    score=0;
    xpos=width/2;
    xdirection=1;
    lost=false;
    loop();                                         //Begin looping draw function again
  }
}

As shown above, i'm able to get a song to play in the background using the minim library, i have a spare 'ding' sound effect, which i would love to add to the click of my mouse when i click the ball, the only problem is i'm unsure on how to do so. So basically, everytime the ball is clicked it produces a 'ding' sound. Thankyou to everyone who can take the time to help me!

Clear data and rerun program.

$
0
0

This is a portion of code, the part I need help with, that sends data to Arduino to run a motor. Everything works great, the motor runs in the right direction, and for the number of rotations entered, so that's all good.

But what I want to do is hit the reset button, and have the previously entered data cleared, and start over.

Keep in mind, I'm 62, and self taught, and while I know enough to be dangerous, a lot of this is a mystery as to how it works.

(code below)

Thanks for any help.

How do I duplicate an oscilloscope?

$
0
0

I took some codes off the internet for an oscilloscope, but I'm having trouble making copies of it and moving it around. I want to create duplicates of the oscilloscope and scatter them all over the screen. I'm also trying to manipulate the shape of the waveforms that are created by the audio input. How do I do these? Please point me into the right direction. Thank you all in advance!

John

How To Get The Colors To Stay Transparent

$
0
0

Ok! So I have this code where I want to change the color of a photo based off of the input audio the code receives. I got it to do this, however, the biggest issue is that after saying a few words it changes to a solid color and stays that way. Does anyone know how to make it stay transparent? Help is appreciated! I'll post the code below.

import ddf.minim.*;
import ddf.minim.signals.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
PImage img;

Minim minim;
AudioInput in;

void setup()
{
    size( 540, 687 );
    img = loadImage("Ash.jpg");
    image(img,0,0);
    }

 {
    minim = new Minim( this );

    in = minim.getLineIn( Minim.STEREO, 512 );
}

void draw()
{
      float p = 0;
    for ( int i = 0; i < in.bufferSize(); i++ ) {
        p += abs( in.mix.get( i ) ) * 1;
    }
  loadPixels();

    for (int i=0; i<(width*height); i++){
      float r = red(pixels[i]);
      float g = green(pixels[i]);
      float b = blue(pixels[i]);

      pixels[i] = color(r*p,g/p,b+p);

}
  updatePixels();
}

void stop()
{
    in.close();
    minim.stop();
    super.stop();
}

Passing Capture reference

$
0
0

Hi,

I am trying to pass a Capture reference. This somehow always returns false even thought camera is available.

boolean readCamera() {

//The variable cam is a Capture function and is global.

  if (!cam.available()) {
    return false;
  }

  cam.read();
  return true;
}

Can someone give me some pointers please.

Thanks

S

Multiple instances of a PShape in a GROUP

$
0
0

I understand from reading the JavaDocs, that Translate is not allowed within a createShape. I tried it anyways in the code below and it does not work, so my question is, what do I use to translate the multiple children that I want to add to the GROUP. I have also done some troubleshooting and it appears that no matter how many addChild() I use, it only adds a single instance of the "cube" that I created. My goal is to make 6 of the cubes in different colors and add one of the 6 cubes based on criteria, but one step at a time, first, how do I make a 20X20X20 3D matrix of these cubes. I can do it by drawing all of the cubes, but I am trying to make this completely object oriented.

I have tried commenting out the PeasyCam in order to make sure it not causing any issues. If I comment out the cam= statement, the program still only draws out ONE cube, but it will be in the top left corner instead of the center due to PeasyCam coordinates.

Any and all suggestions are welcomed.

import processing.opengl.*;
import peasy.*;
PeasyCam cam;
PShape cube, world, world2;
float CS = .25;
int CPS = 20;
float offset = 0;


void setup()  {
  size(640, 640, P3D);
  cam = new PeasyCam(this, CPS*10);  //If commented out, cube moves to top left corner
  noStroke();

  cube = createShape();
  cube.beginShape(QUADS);
  cube.fill(0x44FF0000); cube.vertex(-CS,  CS,  CS);cube.vertex( CS,  CS,  CS);cube.vertex( CS, -CS,  CS);cube.vertex(-CS, -CS,  CS);
  cube.fill(0x4400FF00); cube.vertex( CS,  CS,  CS);cube.vertex( CS,  CS, -CS);cube.vertex( CS, -CS, -CS);cube.vertex( CS, -CS,  CS);
  cube.fill(0x440000FF); cube.vertex( CS,  CS, -CS);cube.vertex(-CS,  CS, -CS);cube.vertex(-CS, -CS, -CS);cube.vertex( CS, -CS, -CS);
  cube.fill(0x44FFFF00); cube.vertex(-CS,  CS, -CS);cube.vertex(-CS,  CS,  CS);cube.vertex(-CS, -CS,  CS);cube.vertex(-CS, -CS, -CS);
  cube.fill(0x4400FFFF); cube.vertex(-CS,  CS, -CS);cube.vertex( CS,  CS, -CS);cube.vertex( CS,  CS,  CS);cube.vertex(-CS,  CS,  CS);
  cube.fill(0x44FF00FF); cube.vertex(-CS, -CS, -CS);cube.vertex( CS, -CS, -CS);cube.vertex( CS, -CS,  CS);cube.vertex(-CS, -CS,  CS);
  cube.endShape(CLOSE);

  world=createShape(GROUP);
  world.addChild(cube);// This is the cube in the center or top left corner.
  for (int i = 0; i < CPS; i++) {
      for (int j = 0; j < CPS; j++) {
          for (int k = 0; k < CPS; k++) {
          cube.translate(i,j,k);               //This is not allowed and does not work.
          world.addChild(cube);           //This only adds the cube once.
          }}}
 }

void draw()  {
  background(127);
  scale(90);
  shape(world,0,0);
}

Averaging a few seconds of a video feed pixel

$
0
0

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

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

What would be an approach to making this happen?

Can't make the shading of the letters was a gradient,please help

$
0
0
import peasy.*;

PeasyCam cam;
int zoom = 0;
int offset = 0;

// Constants
int Y_AXIS = 1;
int X_AXIS = 2;
color b1, b2, c1, c2;
void setup()
{
size(480, 400,P3D);
cam = new PeasyCam(this, 10);
cam.setMinimumDistance(300);
cam.setMaximumDistance(1000);
cam.setSuppressRollRotationMode();
 // Define colors
 b1 = color(255);
 b2 = color(0);
 c1 = color(204, 102, 0);
 c2 = color(0, 102, 153);

}
  void setGradient(int x, int y, float w, float h, color c1, color c2, int axis ) {

  noFill();

   if (axis == Y_AXIS) {  // Top to bottom gradient
    for (int i = y; i <= y+h; i++) {
      float inter = map(i, y, y+h, 0, 1);
     color c = lerpColor(c1, c2, inter);
     stroke(c);
     line(x, i, x+w, i);
     }
  }
  else if (axis == X_AXIS) {  // Left to right gradient
   for (int i = x; i <= x+w; i++) {
     float inter = map(i, x, x+w, 0, 1);
     color c = lerpColor(c1, c2, inter);
     stroke(c);
    line(i, y, i, y+h);
      }
  }
 }


void keyPressed()

 {
    if(keyCode==UP) zoom++;
      if(keyCode==DOWN) zoom--;
   }

void draw()

 {
scale(zoom);
pushMatrix();
background(#FFFFFF);
if (key=='w')

   {
  beginShape(LINE_STRIP);
  vertex(-70,-50,15); //     1
  vertex(-30,-50,15); //     2
  vertex(0,-20,15); //     3
  vertex(30,-50,15); //     4
  vertex(70,-50,15); //     5
  vertex(-30,50,15); //     6
  vertex(-70,50,15); //     7
  vertex(-20,0,15); //     8
 vertex(-70,-50,15); //     9
   endShape(CLOSE);

 beginShape(LINE_STRIP);
 vertex(-70,-50,15); //     1
 vertex(-70,-50,-15); //    1'
 vertex(-30,-50,-15); //       2'
 vertex(-30,-50,15); //     2
 vertex(0,-20,15); //       3
 vertex(0,-20,-15); //     3'
 vertex(30,-50,-15); //    4'
  vertex(30,-50,15); //     4
 vertex(70,-50,15); //   5
 vertex(70,-50,-15); //   5'
 vertex(-30,50,-15); //   6'
 vertex(-30,50,15); //   6
 vertex(-70,50,15); //    7
 vertex(-70,50,-15); //   7'
    vertex(-20,0,-15); //     8'
   vertex(-20,0,15); //     8
 vertex(-70,-50,15); //   9
 vertex(-70,-50,-15); //   9'
 endShape(CLOSE);

 beginShape(LINE_STRIP);
  vertex(-70,-50,-15); //     1
  vertex(-30,-50,-15); //     2
 vertex(0,-20,-15); //     3
  vertex(30,-50,-15); //     4
  vertex(70,-50,-15); //     5
  vertex(-30,50,-15); //     6
  vertex(-70,50,-15); //     7
   vertex(-20,0,-15); //     8
  vertex(-70,-50,-15); //     9
  endShape(CLOSE);

    }

       else

   {
   beginShape();
    if (keyCode=='5')
   {fill(#5AEDFF);}
    else fill(#7AEDFF);
    vertex(-70,-50,15); //     1
     vertex(-30,-50,15); //     2
    vertex(0,-20,15); //     3
    vertex(30,-50,15); //     4
    vertex(70,-50,15); //     5
      vertex(-30,50,15); //     6
       vertex(-70,50,15); //     7
        vertex(-20,0,15); //     8
      vertex(-70,-50,15); //     9
          endShape(CLOSE);

       beginShape(QUAD_STRIP);
       vertex(-30,-50,15); //     2
      vertex(-30,-50,-15); //       2'
       vertex(0,-20,15); //       3
        vertex(0,-20,-15); //     3'
       vertex(30,-50,15); //     4
         vertex(30,-50,-15); //    4'
        vertex(70,-50,15); //   5
      vertex(70,-50,-15); //   5'
          vertex(-30,50,15); //   6
        vertex(-30,50,-15); //   6'
       vertex(-70,50,15); //    7
      vertex(-70,50,-15); //   7'
      vertex(-20,0,15); //     8
    vertex(-20,0,-15); //     8'
     vertex(-70,-50,15); //   9
      vertex(-70,-50,-15); //   9'
      vertex(-70,-50,15); //     1
      vertex(-70,-50,-15); //    1'
      vertex(-30,-50,15); //    2
        vertex(-30,-50,-15); //    2'
           endShape(CLOSE);

        beginShape();
            vertex(-70,-50,-15); //     1
            vertex(-30,-50,-15); //     2
            vertex(0,-20,-15); //     3
            vertex(30,-50,-15); //     4
            vertex(70,-50,-15); //     5
            vertex(-30,50,-15); //     6
            vertex(-70,50,-15); //     7
            vertex(-20,0,-15); //     8
            vertex(-70,-50,-15); //     9
            endShape(CLOSE);
               }
            popMatrix();
   }

Pausing draw function.

$
0
0

Is there a way where I can pause my draw function so I can have new backgrounds also those backgrounds should be behind the buttons from ControlP5 library. Because I am creating a GUI that needs to show the rPi Camera but needs to have a clicked button first. Any help can be considered! Thanks and more powers.

Make Video

$
0
0

How can I make video from Processing? I Want to export my work on video.

Multiple songs + multiple beatlisteners

$
0
0

Hi everyone! I'm learning Processing for the first time for one of my modules at university. The task is to essentially create something with processing, and I did a small equalizer reminiscing of the old windows media player with the weird effects. I seem to keep getting in line 38 NullPointerExpection error when I added multiple beatlisteners since it is part of what's randomizing the graphics.

I managed to get the multiples files playing once, but with only 1 beatlistener working. So when I changed to the other equalizer screen it didn't (beat).

I've tried multiple things, but can't find the solution. Can anyone spot where the problem lies?

(The initial problem is fixed, I was missing the .mp3 in the song description)

I am now back to my other problem after managing to get multiple songs to load yesterday, the beatlistener only "listens and beats" to one of the songs, in the current code it only does it to playlist [2]. When I choose the other songs the color stops changing and the graphics stop animating,

Any way to make the beatlistener read all the 3 songs?

Thank you!

Main window

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

                    Minim minim;
                    AudioPlayer[] playlist;
                    AudioPlayer player;
                    AudioInput input;
                    BeatDetect beat;
                    BeatListener bl;

                    float unit, theta;
                    float kickSize, snareSize, hatSize;
                    float r = random(0, 500);
                    int pageNumber = 1;
                    int num = 50, frames=180;
                    int radius = 40;
                    int sides = 10;
                    int depth = 0;
                    PWindow win;

                    public void settings() {
                      size(500, 500);
                    }

                    void setup() {
                      win = new PWindow();
                      minim = new Minim(this);
                      unit = width/num;
                      noStroke();


                      playlist = new AudioPlayer [3];
                      playlist[0] = minim.loadFile("the_trees.mp3");
                      playlist[1] = minim.loadFile("marcus_kellis_theme.mp3");
                      playlist[2] = minim.loadFile("eternal_snowflake.mp3");


                      beat = new BeatDetect(playlist[1].bufferSize(), playlist[1].sampleRate());
                      beat.setSensitivity(50);
                      kickSize = snareSize = hatSize = 1600;
                      bl = new BeatListener(beat, playlist[1]);

                        beat = new BeatDetect(playlist[0].bufferSize(), playlist[0].sampleRate());
                      beat.setSensitivity(50);
                      kickSize = snareSize = hatSize = 1600;
                      bl = new BeatListener(beat, playlist[0]);

                      beat = new BeatDetect(playlist[2].bufferSize(), playlist[2].sampleRate());
                      beat.setSensitivity(50);
                      kickSize = snareSize = hatSize = 1600;
                      bl = new BeatListener(beat, playlist[2]);



                    }
                    void draw() {

                      if (keyPressed) {
                        if (key == 'j')
                          playlist[0].play();
                        else
                          playlist[0].pause();

                        if (keyPressed)
                          if (key == 'k')
                            playlist[1].play();
                          else
                            playlist[1].pause();

                        if (keyPressed)
                          if (key == 'l')
                            playlist[2].play();
                          else
                            playlist[2].pause();
                      }
                      if (pageNumber == 1) {
                        background(0);
                        for (int y=0; y<=num; y++) {
                          for (int x=0; x<=num; x++) {


                            if (keyPressed) {
                              if (key == 'r')
                                fill(255, 0, 0); //sphere colour
                            }

                            if (keyPressed) {
                              if (key == 'g')
                                fill(0, 255, 0);
                            }

                            if (keyPressed) {
                              if (key == 'b')
                                fill(0, 0, 255);
                            }
                            if (beat.isHat()) {
                              fill(random(0, 255), random(0, 255), random(0, 255));
                              radius = int(random(1, 100)); // randomly choose radius for sphere
                              depth = int(random(1, 100)); // randomly set forward/backward translation distance of sphere
                              // test if beat is snare

                              if (beat.isSnare()) {
                                fill(random(0, 255), random(0, 255), random(0, 255));
                                radius = int(random(10, 200)); // randomly choose radius for sphere
                                depth = int(random(10, 100)); // randomly set forward/backward translation distance of sphere
                              }
                              // test id beat is Hat
                              if (beat.isKick()) {
                                fill(random(0, 255), random(0, 255), random(0, 255));
                                radius = int(random(10, 500)); // randomly choose radius for sphere
                                depth = int(random(25, 220)); // randomly set forward/backward translation distance of sphere
                              }
                            }

                            pushMatrix();
                            float distance = dist(width/2, height/2, x*unit, y*unit);
                            float offSet = map(distance, 56, sqrt(sq(width/2)+sq(height/17)), 0, TWO_PI);
                            float sz = map(sin(theta+distance), 1, 10, unit*.2, unit*.1);
                            float angle = atan2(y*unit-height/11, x*unit-width/2);
                            float px = map(sin(angle+offSet+theta), 110, 56, 18, 159);
                            translate(251, -115);
                            rotate(random(271)); //rotates to a random angle
                            ellipse(random(-209, 730), random(-767, 105), -2, random(-59, 35)); //godcode
                            popMatrix();
                          }


                          theta -= TWO_PI/frames;
                        }
                      }


                      if (pageNumber == 2) {
                        background(0);
                        for (int y=50; y<=num; y++) {
                          for (int x=41; x<=num; x++) {

                            if (keyPressed) {
                              if (key == 'r')
                                fill(255, 0, 0); //sphere colour
                            }

                            if (keyPressed) {
                              if (key == 'g')
                                fill(0, 255, 0);
                            }

                            if (keyPressed) {
                              if (key == 'b')
                                fill(0, 0, 255);
                            }
                            if (beat.isHat()) {
                              fill(random(0, 255), random(0, 255), random(0, 255));
                              radius = int(random(1, 50)); // randomly choose radius for sphere
                              depth = int(random(1, 505)); // randomly set forward/backward translation distance of sphere
                              // test if beat is snare

                              if (beat.isSnare()) {
                                fill(random(0, 255), random(0, 255), random(0, 255));
                                radius = int(random(0, 500)); // randomly choose radius for sphere
                                depth = int(random(0, 100)); // randomly set forward/backward translation distance of sphere
                              }
                              // test id beat is Hat
                              if (beat.isKick()) {
                                fill(random(0, 255), random(0, 255), random(0, 255));
                                radius = int(random(1, 500)); // randomly choose radius for sphere
                                depth = int(random(23, 220)); // randomly set forward/backward translation distance of sphere
                              }
                            }

                            pushMatrix();
                            float distance = dist(width/2, height/2, x*unit, y*unit);
                            float offSet = map(distance, 53, sqrt(sq(width/2)+sq(height/17)), 0, TWO_PI);
                            float sz = map(sin(theta+distance), 1, 10, unit*.2, unit*.1);
                            float angle = atan2(y*unit-height/2, x*unit-width/2);
                            float px = map(sin(angle+offSet+theta), 2, 29, 50, 152);
                            translate(245, 245);
                            rotate(random(59)); //rotates to a random angle
                            ellipse(random(102, 74), random(31, 20), 4, random(599, 234)); //godcode
                            popMatrix();
                          }


                          theta -= TWO_PI/frames;
                        }
                      }

                      if (pageNumber == 3) {
                        background(0);
                        for (int y=0; y<=num; y++) {
                          for (int x=0; x<=num; x++) {

                            if (keyPressed) {
                              if (key == 'r')
                                fill(255, 0, 0); //sphere colour
                            }

                            if (keyPressed) {
                              if (key == 'g')
                                fill(0, 255, 0);
                            }

                            if (keyPressed) {
                              if (key == 'b')
                                fill(0, 0, 255);
                            }
                            if (beat.isHat()) {
                              fill(random(0, 255), random(0, 255), random(0, 255));
                              radius = int(random(1, 500)); // randomly choose radius for sphere
                              depth = int(random(1, 500)); // randomly set forward/backward translation distance of sphere
                              // test if beat is snare

                              if (beat.isSnare()) {
                                fill(random(0, 255), random(0, 255), random(0, 255));
                                radius = int(random(1, 500)); // randomly choose radius for sphere
                                depth = int(random(1, 500)); // randomly set forward/backward translation distance of sphere
                              }
                              // test id beat is Hat
                              if (beat.isKick()) {
                                fill(random(0, 255), random(0, 255), random(0, 255));
                                radius = int(random(1, 500)); // randomly choose radius for sphere
                                depth = int(random(1, 500)); // randomly set forward/backward translation distance of sphere
                              }
                            }

                            pushMatrix();
                            float distance = dist(width/2, height/2, x*unit, y*unit);
                            float offSet = map(distance, 10, sqrt(sq(width/2)+sq(height/2)), 0, TWO_PI);
                            float sz = map(sin(theta+distance), 1, 10, unit*.2, unit*.1);
                            float angle = atan2(y*unit-height/2, x*unit-width/2);
                            float px = map(sin(angle+offSet+theta), -1, 10, 0, 100);
                            translate(x*unit, y*unit);
                            rotate(r*angle); //rotates to a random angle
                            ellipse(px, 0, sz, sz); //godcode
                            popMatrix();
                          }


                          theta -= TWO_PI/frames;
                        }
                      }
                    }


                    void keyPressed() {
                      if (key == '1') {
                        redraw();
                        pageNumber = 1;
                      }
                      if (key == '2') {
                        redraw();
                        pageNumber = 2;
                      }
                      if (key == '3') {
                        redraw();
                        pageNumber = 3;
                      }
                    }
                    void mousePressed() {
                      println("mousePressed in primary window");
                    }

BeatListener window

            class BeatListener implements AudioListener
            {
              private BeatDetect beat;
              private AudioPlayer source;

              BeatListener(BeatDetect beat, AudioPlayer source)
              {
                this.source = source;
                this.source.addListener(this);
                this.beat = beat;
              }

              void samples(float[] samps)
              {
                beat.detect(source.mix);
              }

              void samples(float[] sampsL, float[] sampsR)
              {
                beat.detect(source.mix);

              }
            }

Correlations library

$
0
0

Hi, First post overhere.

Any idea about correlations library for processing http://www.muehlseife.de/ It is a really awesome tool. Right now i am trying to delete nodes, but i havent succeed. Maybe there is other tool - library i can use for the same purpose = GUI noded based Any help i will appreciate it.

Best Regards.

How to upload image for the ball as well as adding a sound to ball everytime it's clicked (URGENT)

$
0
0

Hey Guys! So can someone please help!! I have 3 day's left to hand in this project and I need 2 things.

  1. I need code so that i'm able to upload a PNG/JPG image for the ball that's moving around the screen.

  2. I need code so that a sound can be played every time the ball is clicked using the minim library.

Feel free to modify the code and hand it back, any help is appreciated and is well needed.

import ddf.minim.*;
int rad = 60;                                   // Width of the shape
float xpos, ypos;                               // Starting position of shape
float xspeed = 2.0;                             // Speed of the shape
float yspeed = 2.0;                             // Speed of the shape
int xdirection = 1;                             // Left or Right
int ydirection = 1;                             // Top to Bottom
int score=0;                                     //Inital score
int lives=5;                                     //Number of lives you start with
boolean lost=false;                              //Have you lost yet?
int speed=1;
PImage bg;
int y;
AudioPlayer player;
Minim minim;

void setup()
{
  size(1297, 736);
  minim = new Minim(this);
  fill(0,0,0);
  noStroke();
  frameRate(120);
  ellipse(xpos, height/10,100,100);
  xpos = width/2;                               // Set the starting position of the shape
  ypos = height/2;
  bg = loadImage("stem.jpg");                   //Load Image (jpg,png,gif)
  player = minim.loadFile("Song.wav");          //Load Audio File (mp3,wav)
  player.loop();

}

void draw()
{
  background(bg);

  xpos = xpos + ( xspeed * xdirection );         // Update the position of the shape
  ypos = ypos + ( yspeed * ydirection );


  if (xpos > width-rad || xpos < rad) {          // Test to see if the shape exceeds the boundaries of the screen
                                                 // If it does, reverse its direction by multiplying by -1
    xdirection *= -1;
  }
  if (ypos > height-rad || ypos < rad) {
    ydirection *= -1;
  }


  ellipse(xpos, ypos, rad, rad);                    //Draw the shape
  text("score = "+score,10,10);                     //Print the score on the screen
  text("lives = "+lives,width-80,10);               //Print remaining lives
  if (lives<=0)                                     //Check to see if you lost
  {
    textSize(50);
    text("Click to Restart", 450,200);
    noLoop();                                       //Stop looping at the end of the draw function
    lost=true;
    textSize(12);
  }
}
void mousePressed()                                 //Runs whenever the mouse is pressed
{
  if (dist(mouseX, mouseY, xpos, ypos)<=rad)        //Did we hit the target?
  {
    score=score+speed;                              //Increase the speed
    speed=speed+1;                                  //Increase the Score
  }
  else                                              //We missed
  {
    if (speed<1)                                    //If speed is greater than 1 decrease the speed
    {
    speed=speed-1;
    }
    lives=lives-1;                                  //Take away one life
  }
  if (lost==true)                                   //If we lost the game, reset now and start over
  {
    speed=1;                                        //Reset all variables to initial conditions
    lives=5;
    score=0;
    xpos=width/2;
    xdirection=1;
    lost=false;
    loop();                                         //Begin looping draw function again
  }
}

What is ddf and minim?

$
0
0

I'm new to processing and whenever I copy source code from examples it does not seem to run. May I know what does ddf and minim mean?

Pen pressure issues with tablet library and OpenGL

$
0
0

I'll try and keep this brief: If anybody is familiar with the P2D/P3D issues with using codeanticode's tablet library (returning 0.0 pressure), have they got a workaround that isn't using UDP or using the default renderer? The issue was stated as fixed with release 6 but it's exactly the problem that's happening to me with release library 2.0-alpha3 using Processing 3.2.3 on OSX 10.12. I've tried with a combination of older releases with no luck.

There's more detail on the github page: https://github.com/codeanticode/tablet/issues/6 but codeanticode himself appears to be busy at the moment and isn't responding.

Cannot override the final method from papplet

$
0
0

I got this error while running a code by someone that posted it online. How do I fix it?

Viewing all 2896 articles
Browse latest View live