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

Can i do with Shapes 3D this?

$
0
0

Screenshot (161) Screenshot (162) Screenshot (166) If not,suggestion ? After that can be send it to CNC machine? Thank you.


Why? - "ERROR: /node/set: Control input index 2 out of range for synth 1"

$
0
0

Using the example SineWave Oscillator code from the official library in Processing 3.2.3 always throws up the error: ERROR: /node/set: Control input index 2 out of range for synth 1. Interestingly, the same thing doesn't happen with the SquareWave example?

If anybody is able to offer any insight I would really like to know why this is happening and prevent it from doing so!

Code is as follows:

import processing.sound.*;

SinOsc sine;

float freq=400;
float amp=0.5;
float pos;

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

    // Create and start the sine oscillator.

    sine = new SinOsc(this);

    //Start the Sine Oscillator.
    sine.play();
}

void draw() {

  // Map mouseY from 0.0 to 1.0 for amplitude
  amp=map(mouseY, 0, height, 1.0, 0.0);
  sine.amp(amp);

  // Map mouseX from 20Hz to 1000Hz for frequency
  freq=map(mouseX, 0, width, 80.0, 1000.0);
  sine.freq(freq);

  // Map mouseX from -1.0 to 1.0 for left to right
  pos=map(mouseX, 0, width, -1.0, 1.0);
  sine.pan(pos);
}

Many thanks. :)

Wind map with Processing

$
0
0

Hi there, I'm trying to create some visuals based on a Wind Map. I got the visuals to work with the parameters setting the thickness and turbulence of the particles but I would like to be able to control those parameters through sliders on an interface so I have more control of it.

I added the sliders to control these parameters but It's not changing the visuals live for some reason. I think it might be because of the positioning of the elements in my code, so I will past it here a section of my code and hopefully someone with experience can point me where i'm getting this wrong?

int sParticles = 5000;
int sNoiseScale = 5000;
int sLength = 5;

float sRandomA = .5;
float sRandomB = 2;



int num = sParticles;
Particle[] particles = new Particle[num];
float noiseScale=sNoiseScale, noiseStrength=5; // Turbulence

void setup() {

  cp5 = new ControlP5(this);
  cp5.addSlider("sParticles").setPosition(0,0).setRange(0,10000);
  cp5.addSlider("sNoiseScale").setPosition(160,0).setRange(0,10000);
  cp5.addSlider("sLength").setPosition(330,0).setRange(0,20);

  cp5.addSlider("sRandomA").setPosition(490,0).setRange(0,5);
  cp5.addSlider("sRandomB").setPosition(650,0).setRange(0,5);

  size(1920, 1080);
  noStroke();
  for (int i=0; i<num; i++) {
    PVector loc = new PVector(random(width*1.2),
    random(height), random(sRandomA, sRandomB)); // Thickness

    float angle = random(TWO_PI);
    PVector dir = new PVector(cos(angle), sin(angle));
    float speed = random(.5, 2);
    particles[i]= new Particle(loc, dir, speed);
  }
}

get vertex from an obj file.

$
0
0

hello guys...i've a question.

you can access the vertex of an obj file ?

i try with this...but it doesn't work.

import peasy.*;
PShape shp;
PeasyCam cam;

void setup() {
  size(1000, 1000, P3D);
  shp=loadShape("face.obj");
  println(shp.getVertexCount());
  cam = new PeasyCam(this, 100);
  cam.setMinimumDistance(50);
  cam.setMaximumDistance(500);
}

void draw() {
  lights();
  directionalLight(255, 150, 200, -1, 0, 0);
  background(0);
  shape(shp);
}

the result of println(shp.getVertexCount()) is 0.

thank you!! :)

How to set a password for G4P gui builder

$
0
0

I've got the password box but how do I set it so when the password is correct it does what I ask it to do. For example: If the password is correct, change the background color. Something like that

Why doesn't work MUTE with boolean in my code?

$
0
0

Hey! I'm having trouble to using .mute(); with boolean. As you can see in the code, I want to make processing to mute all my sounds when i hit 'k', and unmute them when I hit 'k' again. It's very important for me to make this program. When i do it with .pause() and .play(), it works, but it's not good for me, because i want to run these sounds in loop. I hope that u guys can help me. Here's my code: (on the start of the draw, wehere my problem is) (Btw.: sorry for my bad english) Thx

import ddf.minim.spi.*;
import ddf.minim.signals.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.ugens.*;
import ddf.minim.effects.*;

Minim m;
AudioInput in;
AudioPlayer hera;
AudioPlayer time;
AudioPlayer hotlinebling;
AudioPlayer kemosabe;


boolean onOff = false;
boolean pOn = false;

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

  m = new Minim(this);
  hera = m.loadFile("1.mp3");
  hera.loop();

  time = m.loadFile("2.mp3");
  time.loop();

  hotlinebling = m.loadFile("hbt.mp3");
  hotlinebling.loop();


  kemosabe = m.loadFile("4.mp3");
  kemosabe.loop();

  in = m.getLineIn(Minim.MONO, 2048);
}

void draw() {

  if (onOff == false) {
    kemosabe.mute();
    time.mute();
    hera.nmute();
    hotlinebling.mute();

    //Mikrofon
    if (keyPressed) {
      if (key == 'p' && !pOn) {
        if (random(0, 6) < 3) {
          in.enableMonitoring();
        } else {
          in.disableMonitoring();
        }
        println(in.isMonitoring());
        pOn = true;
      }
    } else {
      pOn = false;
      in.disableMonitoring();
    }
  } else {
    kemosabe.unmute();
    hera.unmute();
    hotlinebling.unmute();
    time.unmute();
  }

  //Hera koka hallatszik
  if (keyPressed ) {
    if (key=='0')
      time.mute();
  } else {
    time.unmute();
  }

  if (keyPressed ) {
    if (key=='0')
      kemosabe.mute();
  } else {
    kemosabe.unmute();
  }

  if (keyPressed ) {
    if (key=='0')
      hotlinebling.mute();
  } else {
    hotlinebling.unmute();
  }

  //I've had hallatszik
  if (keyPressed ) {
    if (key=='2')
      hera.mute();
  } else {
    hera.unmute();
  }

  if (keyPressed ) {
    if (key=='2')
      kemosabe.mute();
  } else {
    kemosabe.unmute();
  }

  if (keyPressed ) {
    if (key=='2')
      hotlinebling.mute();
  } else {
    hotlinebling.unmute();
  }

  //Hotline bling
  if (keyPressed ) {
    if (key=='5')
      hera.mute();
  } else {
    hera.unmute();
  }

  if (keyPressed ) {
    if (key=='5')
      kemosabe.mute();
  } else {
    kemosabe.unmute();
  }

  if (keyPressed ) {
    if (key=='5')
      time.mute();
  } else {
    time.unmute();
  }

  //Kemosabe hallatszik
  if (keyPressed ) {
    if (key=='8')
      hera.mute();
  } else {
    hera.unmute();
  }

  if (keyPressed ) {
    if (key=='8')
      time.mute();
  } else {
    time.unmute();
  }

  if (keyPressed ) {
    if (key=='8')
      hotlinebling.mute();
  } else {
    hotlinebling.unmute();
  }
}

void keyPressed() {
  if (key == 'm') {
   onOff = !onOff;
  }
}

ControlP5 Button from Class doesn't work when click on it

$
0
0

Hi! I'm creating a simple program with a class for creating all the controlP5 GUI, inside that class are buttons and other stuff but i'd like to manage the state of a button.

`

import controlP5.*;

class CAToolBox{

public ControlP5 cp5;

PFont font;

int caX; int caY; int caWidth; int caHeight;

boolean play = false; boolean generated = false;

CAToolBox(PApplet applet, PFont _font, int _x, int _y, int _caWidth, int _caHeight){ caX = _x; caY = _y; caWidth = _caWidth; caHeight = _caHeight; font = _font; cp5 = new ControlP5(applet);

this.drawCAToolBox(caX + 10, caY + 10);

}

void drawCAToolBox(int _x, int _y){

//Generate Button
cp5.addButton("Generate")
   .setPosition(_x +3 , _y + 65)
   .setSize(50, 22);

//Play & Pause Button
cp5.addButton("PlayPause")
   .setLabel("Pause")
   .setPosition(_x + 3 + 60 , _y + 65)
   .setSize(50, 22);

}

void PlayPause(){ play = !play;

checkLabelState();

}

void checkLabelState(){ if(play == false){ cp5.get(controlP5.Button.class, "PlayPause").setLabel("play"); }else{ cp5.get(controlP5.Button.class, "PlayPause").setLabel("pause"); } } }`

Any on how can i call the button in this class for working with my main window?

Pause in minim

$
0
0

My song only pauses for half a second. How do I fix it?

import ddf.minim.spi.*;
import ddf.minim.signals.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.ugens.*;
import ddf.minim.effects.*;


Minim minim;
AudioPlayer song;
float lvl;
int BG, change;
PImage play, pause, on, off, bg;
boolean power;

void setup()
{
  size(800, 800);
  minim = new Minim(this);
  song = minim.loadFile("Song.mp3");
  song.play();
  change = 100;
  BG = 0;
  power = false;
  play = loadImage("play.png");
  pause = loadImage("pause.png");
  on = loadImage("on.jpg");
  on.resize(100, 100);
  off = loadImage("off.jpg");
  bg = loadImage("download.jpg");
  frameRate(50);
}

void draw() {
  background(BG);
  if (!power) {
    BG=0;
    change = 100;
    image(off, 25, 25);
    song.pause();
    song.rewind();
  } else {
    beat();
    song.play();
    BG = 255;
    image(on, 5, 5);
    beat();
  }
}

void beat() {
  lvl = song.mix.level();
  image(pause, width/2-50, 50);

  if (lvl > 0.1) {
    change = change + 10;
  } else {
    change = change - 5;
  }
  change = constrain(change, 100, 200);
  fill(#F00707);
  ellipse(width/2, height/2, change, change);
}

void mouseClicked() {
  if (mouseX<75 && mouseY<75) {
    power = !power;
  }
}
void keyReleased() {
  //pauses song when spacebar is pressed
  if (key == ' ') {
    if (song.isPlaying()) song.pause();
    else song.play();
  }
}

((newbie)) looking for help with CP5 text field

$
0
0

Hi all! Am a visual artist who knows only very little about coding but is trying to create some code to go with an art piece. The main ideal of the program I'm making is that the user can input text, click submit, and the program will generate a fortune/ritual/poem for them . It doesn't matter what the text entered really is because the poems are generated randomly. I'm using the TextField from ControlP5 to allow user keyboard input but can't seem to be getting it to work properly. When I try to type into it, it only works if I click it a few times, and I need to click it so it will refresh and show what has been written. What am I doing wrong? I would also like it to only appear on the first page (page0), so it is not on screen at the same time as the poem, and haven't been able to figure out how to do that. These seem like they would be relatively easy things to do and yet i'm lost! :,,( help! Thanks! x

import controlP5.*;
ControlP5 cp5;

String textValue = "";
String [] firstWords = {
  "Go to the arcade", "Go to a bar where beers are 1$","Go to your local swimming pool"
  ,"Go to your local swimming pool", "Stand in your mother's kitchen", "Go outside your front door"
  , "Go to your local graveyard", "Go to the supermarket", "Go to the park",
"Go thirty-five steps north of your house", "Go stand near the statue of an important historical figure",
"Stay on a bus for its entire route", "Go to the library", "Go to a dinner party", "Go to your local diner" };

String [] secondWords = {
  "Wear a blue raincoat", "Wear your favorite pair of shoes","Wear a hat someone would wear to church",
"Tie your shoes in a double knot","Eat a good breakfast", "Check the weather","Leave as early as possible",
"Leave as late as possible", "Wash your hair", "Put on someone else's perfume", "Braid your hair", "Apply some blush on one cheek",
"Wear a disguise"};

String [] thirdWords = {
  "On your way, take a picture of the three first things you see that are red, send these pictures to",
"On your way, take two flowers from a passing garden, place them on",
"On your way, look avidly for any small change until you find some, place it on",
"On your way, draw two detailed illustrations of passers-by. These can be done on restaurant napkins or receipts you find on the ground. Give them to",
"On your way, find a waiting room where people are waiting. Sit with them. Imagine what each person’s three favorite things to do are. Leave when you have finished imagining all the people’s lives. Take a brochure, and give it to",
};

String [] fourthWords = {
  "a man you’ve quietly followed for exactly ten minutes and fourty-threee seconds",
"the river","a friend you haven’t talked to in a while","the person you have most recently eaten dinner with",
"the gravestone of someone who looked like they might have they might have locked themselves out of their house more than once",
"a bus that runs from north to south and goes through downtown", "The gravestone of someone who seems friendly",
"the gravestone of someone who looked like they wrote three unpopular books on personal finance", "the gravestone of someone who looks like they have never seen a black bear except for in other people's travel photographs",
"a mailbox twenty houses down from yours", "a mailbox next to your house", "a mailbox of a house you lived in a while ago",
"the mailbox of a house you lived in a while ago", "a woman who vaguely reminds you of the aunt that you don’t like",
"a woman who vaguely reminds you of your favorite aunt",
"a bus that runs of east to west and goes through downtown",
"a small mound of dirt",
"a mountain",
"the top of your head",
"the top of your friend's head",
"a couple who look very in love",
"a small angry dog"};

String [] fifthWords = {
  "elegantly", "with the attitude of someone who is very wealthy","slowly","with passion",
"dreamily", "with your eyes closed", "gracefully", "angrily", "with your fists clenched", "without looking"};

String [] sixthWords = { "One you have arrived, try and make eye contact with everyone in the room", "Once you have arrived, try not to make eye contact with anyone in the room",
"Once you have arrived, find a person with grey hair. Take something you have in your pocket, or is on the ground, or that you have bought in a convenience store, and ask them if they have dropped it."

};

PFont Arial;
PImage img;
String url1, url2;

final static int MAX = 2, GAP = 50, DIM = 120, RAD = DIM >> 1;
int page, cx, cy;

Button back, submit;

void setup() {
  size(1000, 700);
  background(255);
  Arial = createFont("Arial",24);

  frameRate(200);
  noLoop();
  smooth();

  rectMode(CORNER);
  ellipseMode(CENTER);
  textAlign(CENTER, CENTER);

  stroke(0);
  strokeWeight(1);

  cx = width  >> 1;
  cy = height >> 1;

back = new Button("BACK", 70, height - Button.H - GAP);
submit = new Button("SUBMIT", width - Button.W - GAP, height - Button.H - GAP);
img = loadImage("magic82ball.jpg");

   cp5 = new ControlP5(this);
  cp5.addTextfield("input")
    .setPosition(400, 375)
    .setSize(200, 40)
    .setInputFilter(ControlP5.STRING);
}


void draw() {
  background(255);
  textFont(Arial,10);
  textSize(0020);
  fill(Button.TXTC);

  textSize(015);
  if (page > 0)     back.display();
  if (page < 1)   submit.display();

  method("page" + page);

}

void mousePressed() {
  if      (page > 0   && back.hasClicked())   --page;
  else if (page < 1 && submit.hasClicked())   ++page;

  redraw();
}

void page0() {
  image(img, 375, 50);
  text("stop worrying about the future", 500, cy);
}
void page1() {
  fill(0);
  String word1 = firstWords[int(random(firstWords.length))];
  String word2 = secondWords[int(random(secondWords.length))];
  String word3 = thirdWords[int(random(thirdWords.length))];
  String word4 = fourthWords[int(random(fourthWords.length))];
  String word5 = fifthWords[int(random(fifthWords.length))];

  text(word1,100,0, 300, 300);
  text(word2,100,50, 300, 300);
  text(word3,100,150, 300, 300);
  text(word4,100,250, 300, 300);
  text(word5,100,300, 300, 300);


  String output = firstWords[int(random(firstWords.length))] + " " + secondWords[int(random(secondWords.length))];


  println (output);
}

void pageSelector() {
  switch(page) {
  case 0:
    page0();
    break;

  case 1:
    page1();
    break;

  }
}

class Button {
  final static int W = 60, H = 40;
  final static color BTNC = 225, TXTC = 0;

  final String label;
  final short x, y, xW, yH;

  Button(String txt, int xx, int yy) {
    label = txt;

    x = (short) xx;
    y = (short) yy;

    xW = (short) (xx + W);
    yH = (short) (yy + H);
  }

  void display() {
    fill(255);
    rect(x, y, W, H);

    fill(0);
    text(label, x + W/2, y + H/2);
  }

  boolean hasClicked() {
    return mouseX > x & mouseX < xW & mouseY > y & mouseY < yH;
  }
}

How to record and playback without saving to file.

$
0
0

Hi, everyone!

Beginners' question!

In Minim, is there an example on how to record microphone input to memory, (turn it into an AudioSample maybe?) then patch it later, (and repeatedly, in a loop) to output without saving to disk (i.e. without doing what the RecordAndPlayBack example does?

Many many many thanks! :-)

G4P Expands Drop List Automatically

$
0
0

@quark Quick question, anyway to permanently expand the drop list so it behaves more like a selection list?

Example:

Emotion API and POST and HTTP requests library

$
0
0

Hi all.

I have tried to resolve this to no avail. I just don't know what I'm doing wrong. I really hope someone out there can point me in the right direction. Apologies if my use of terminology is occasionally bogus below - network stuff is not my usual bag.

Basically, I'm trying to use the Microsoft Emotion API in Processing: https://dev.projectoxford.ai/docs/services/5639d931ca73072154c1ce89/operations/563b31ea778daf121cc3a5fa It requires API key authentication and HTTP headers as a POST request. I found the HTTP requests library (by Shiffman et al) which apparently takes the pain away (heh) and built a test example below:

import http.requests.*;
PostRequest post;

void setup() {
  size(400, 400);
  makeRequest();
  //println("Reponse Content: " + post.getContent());
  //println("Reponse Content-Length Header: " + post.getHeader("Content-Length"));
  JSONObject response = parseJSONObject(post.getContent());
  println(response);
}

void makeRequest() {
  post = new PostRequest("https://" + "westus.api.cognitive.microsoft.com/emotion/v1.0/recognize");
  post.addHeader("Content-Type", "application/json");
  post.addHeader("Ocp-Apim-Subscription-Key", MyAPIkeyGoesHere);
  post.addData("url", "http://" + "www.boro.gr/contentfiles_2016/psyxologia/thymos/axaaamm.jpg");
  post.send();
}

What I should get back is a JSON file that looks like this:

  {
    "faceRectangle": {
      "height": 216,
      "left": 225,
      "top": 90,
      "width": 216
    },
    "scores": {
      "anger": 9.38430444E-11,
      "contempt": 3.36862873E-12,
      "disgust": 4.649468E-11,
      "fear": 1.913897E-11,
      "happiness": 1.0,
      "neutral": 7.306441E-11,
      "sadness": 1.65613755E-11,
      "surprise": 2.97461256E-09
    }
  }

... but what I get is this:

{"error": {
  "code": "BadBody",
  "message": "JSON parsing error."
}}

Anybody know what's going on? Also, if I was wanting to upload an image locally, how would I do that? Apologies for lameness, but am very grateful for any help. Thanks.

Kind regards, Paul.

What range does getAvg() return in Minim?

$
0
0

I am trying to create a music visualizer using the FFT in Minim. For my calculations, I need getAvg() to return a number between 0 and 1, which I can then convert to dBA. However, it seems to give me numbers between 0 and some other number like 27 when I play a file with full amplitude noise created in Audacity. So what is getAvg() actually returning and how can I get it to be between 0 and 1?

I have this in my setup function:

fft = new FFT(song.bufferSize(), song.sampleRate());
fft.logAverages(22, bandsPerOctave);

and this in my draw function:

fft.forward(song.mix);
for(int i = 0; i < fft.avgSize(); i++)
{
  float amplitude = fft.getAvg(i);
  println(amplitude);
}

controlP5 Toggle button

$
0
0

Hi, I have 10 buttons in a UI and it all works great, the issue I have is that I want the active button to remain highlighted

I added the .setSwitch(true) to each button which acts like a toggle but the issues that when I click another button, the first button still stay highlighted.

How can I have a selected state?

Any idea?

Thanks.

Phil

Triggering multiple videos / stuttering / poor performance

$
0
0

Bonjour lovely knowledgeable people,

I have a little problem with playing back videos in processing. The aim is to trigger the videos via an serial port input which works fine. The problem is that the videos are played back very laggy. I assume its because they are somehow all played back in the background. The videos are very short 2-5 seconds, but are in HD (1920x1080) and .H264 coded. They are supposed to be played back as long as the input signal is there, and fade to black when its gone. Can you please help me figure out how to avoid this problem and achieve fluid playback of the videos? That would be superb! I Have been hammering over this code for a while and I cant figure it out. Annnd, do you have any idea how to implement fading in and fading out of the videos? Tried it with tint, but can not manage it to do it fast enough. You would be a life saver! Merci, merci bien — any help is appreciated!

Love ❤️ jules

import processing.video.*;
import processing.serial.*;

Movie[]  movie = new Movie[10];
float[] myArray = new float[10];
short videoSpeed= 0 ;
PImage bg;
PImage logo;
short videoID = 9;

String[] video ={ "modellblinker1.mp4",
          "modellblinker2.mp4",
          "modellhood.mp4",
          "modellside2.mp4",
          "modellside1.mp4",
          "modellwindshieldsback.mp4",
          "modellTrunk.mp4",
          "modellwindshieldsback.mp4",
          "modellroof.mp4"};



void setup() {
  fullScreen();
  iniMovies();
  imageMode(CENTER);
  frameRate(25);
  bg = loadImage("1.jpg");
  logo = loadImage("m.png");
  println(Serial.list()[0]);
  myPort = new Serial(this, Serial.list()[0], 19200);
  myPort.bufferUntil('\n');


}
void draw() {
  background(0);
  iniMovies();
  mngMovie();

 if( videoID ==9 ){


    image(logo,-57,-57);//, displayWidth/2, displayHeight/2);

  }else{
    image(movie[videoID], displayWidth / 2, displayHeight / 2);
    if (videoID != 9)
       movie[videoID].loop();
  }
}
void movieEvent(Movie m) {
  m.read();
}
void iniMovies(){
   for (int i = 0 ; i< 9;i++){
       movie[i] =  new Movie(this,video[i]);
   }
}
void mngMovie(){
 // print(myArray);

 if(  myArray[0] >2000.0 ) {  /// blinker link
   if ( videoID != 0  && videoID!=9 )
     movie[videoID].stop();
    movie[0].play();
    videoID = 0;
 }
 else if(  myArray[1]>-4000.0 ) {  // blinker recht
   if ( videoID != 1 && videoID!=9 )
     movie[videoID].stop();
    movie[1].play();
    videoID = 1;
 }

 else if(  myArray[2] <-25000.0  || myArray[2] >17000.0  ) {  //  motor
   if ( videoID != 2  && videoID!=9)
     movie[videoID].stop();
    movie[2].play();
    videoID = 2;
 }

 else if(  myArray[3] >5000.0 ) {  // Tür recht
   if ( videoID != 3 && videoID!=9)
     movie[videoID].stop();
    movie[3].play();
    videoID = 3;
 }

 else if(  myArray[4] >20000.0 ) {  // Tür links
   if ( videoID != 4 && videoID!=9 )
     movie[videoID].stop();
    movie[4].play();
    videoID = 4;
 }

 else if(  myArray[5]>20000.0 || myArray[5]<-25000.0) {   // Windschutz
   if ( videoID != 5 && videoID!=9 )
     movie[videoID].stop();
    movie[5].play();
    videoID = 5;
 }

 else if(  myArray[6] >3000.0 ) { // coffer
   if ( videoID != 6  && videoID!=9)
     movie[videoID].stop();
    movie[6].play();
    videoID = 6;
 }
 else if(  myArray[7] >22000.0|| myArray[7]<-22000.0 ) {  // Fenester hinten
   if ( videoID != 7 && videoID!=9)
     movie[videoID].stop();
    movie[7].play();
    videoID = 7;
 }
 else if(  myArray[8]<-22000.0 ) {  // Dach
   if ( videoID != 8 && videoID!=9  )
     movie[videoID].stop();
    movie[8].play();
    videoID = 8;
 }

 else {
   if( videoID != 9)
       movie[videoID].stop();
  videoID=9;
 }
}
void serialEvent(Serial myPort) {
 // get the ASCII string:
 String inString = myPort.readStringUntil('\n');
 if (inString != null) {
 // trim off any whitespace:
 inString = trim(inString);
 // split the string on the commas and convert the
 // resulting substrings into an integer array:
 try{
  myArray =  float(split(inString, ";"));
  mngMovie();
   for (int i = 0 ; i< 9 ; i++){
     print(myArray[i]);
     print(";");
   }
  println(videoID);
 }
 catch(Exception e){
       // println("Error parsing:");
     //      for (int i = 0 ; i< 9 ; i++){
  //   print(myArray[i]);
  //  print(";");
  // }
   println();
  //println(videoID);
   //     e.printStackTrace();
    }
 }
}

How to set volume to 0% (amp=0) when the project begins or if no UI input is detected?

$
0
0

I'm working on a sound related project using a leap to control the sound. I have successfully managed to have the sound fade out when the leap input leaves the edges of the project window, e.g.:

if( hp.x < -400 ) //if hand position(x) is less than or equal to -400...
  {
    amp = 0; //... then volume is 0%
  }
 else if( hp.x < 0 ) //if hand position(x) is less than 0...
  {
    amp = map( hp.x, 0, -400, 1, 0.01 ); //... then posx between 0 & -400 changes volume between 100 - 0%
  }

This snippet of example code fades the volume down to 0 as the leap motion leaves the sketch to the left of the sketch. However, this doesn't help when there is no leap motion location detected (for example when the sketch begins), or if the leap motions location leaves the project window so fast that the last known location was inside of it.

I'm very new to processing, and this seems like a really simple one, but how on earth do I set the project volume (amp) to be at 0 when the project first starts, and ideally also if no leap motion position is detected

Many thanks,

D.

How to take input from and give output to a ps4 controler

$
0
0

I know there are other programs like DS4 but I want to do things like change the light bar on the controller using code. Is there an library I can use?

question about what i did wrong

$
0
0

my Code:

import processing.video.*;

Capture video;



void setup() {
  size(640, 480);
  pixelDensity(1);
  frameRate(60);
  String[] cameras = Capture.list();
  printArray(cameras);
  video = new Capture(this, cameras[1]);
  video.start();
}

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



void draw() {

  video.loadPixels();
  image(video, 0, 0);
  grid();
}

void grid() {
  int square = 0;
  int nr = 20;
  int[] avg = new int[width * height];
  background(255, 0, 0);
  loadPixels();
  if (width % nr == 0 & height % nr == 0) {
    for (int s1 = 0; s1 < height; s1 += height/nr) {
      for (int s2 = 0; s2 < width; s2 += width/nr) {

        for (int x = 0; x < width/nr; x++) {
          for (int y = 0; y < height/nr; y++) {
            square = (x + y * width) + s1 * width + s2;
            avg[square] = int(brightness(get(x + s2, y + s1 * width)));
            pixels[square] = color(avg[square]);
          }
        }

      }
    }
    updatePixels();
  }
}

END

when i run this code it only shows me a black screen. I already tried the same code with just slightly changed for() loops

void grid() {
  int[] avg = new int[width*height];
  loadPixels();
  for (int x = 0; x < width; x++) {
    for (int y = 0; y < height; y++) {
      avg[x+y*width] = int(brightness(get(x,y)));
      pixels[x+y*width] = color(avg[x+y*width]);
    }
  }
  updatePixels();
}

and it worked 100% correct, so I assume the problem must be in the for() loops or how i used the variables s1 and s2, but I just can not find the mistake. Thanks in advance.

~sLucas

Unfolding Map

$
0
0

Is there anyone who can help me with unfolding map. i want to create markers on map and want to save them too in .csv file so that if i want my device to follow that path . it will follow that without any error.

import de.fhpotsdam.unfolding.providers.Microsoft;
import de.fhpotsdam.unfolding.*;
import de.fhpotsdam.unfolding.utils.*;
import de.fhpotsdam.unfolding.marker.*;
import de.fhpotsdam.unfolding.geo.*;


UnfoldingMap map ;
SimpleLinesMarker connectionMarker;

UnfoldingMap currentMap;

void setup() {
  size(800, 600);
  map = new UnfoldingMap(this, new Microsoft.AerialProvider());
  MapUtils.createDefaultEventDispatcher(this, map);
  currentMap = map;

  map = new UnfoldingMap(this);
  Location startLocation = new Location(32.2, 76.3);
  Location endLocation = new Location(53.35, -6.26);
  SimpleLinesMarker connectionMarker = new SimpleLinesMarker(startLocation, endLocation);
  MapUtils.createDefaultEventDispatcher(this, map);

}

void draw() {
  currentMap.draw();
}

void keyPressed() {
    if (key == '1') {
        currentMap = map;
    }
}

How to hide sphere overlap point

$
0
0

Hey everyone! I'm working on making a sphere out of individual points and calculating the radius of each point by the volume of the music. If you load my code you can see my problem. There is a big mark that indicates where the sphere starts and stops. Is there a way to make these two connected so it doesnt look as ugly? Any help is appreciated!!

import peasy.*;
import peasy.org.apache.commons.math.*;
import peasy.org.apache.commons.math.geometry.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
import ddf.minim.signals.*;
import ddf.minim.spi.*;
import ddf.minim.ugens.*;

PeasyCam cam;
Minim minim;
AudioPlayer player;
AudioMetaData meta;
BeatDetect beat;
FFT fft;

PVector[][] globe;
color[][] colormap;
float[][] r;
int total = 100;
float rad = 25;
float nI=0;
float nJ=0;
float hu;
float minRad = 30;
float maxRad = 100;
boolean calculated = false;
boolean up=true;
void setup() {
  cam = new PeasyCam(this, 50);
  minim = new Minim(this);
  //player = minim.loadFile("D:/programeer gedoe/Programs/Music visualiser/PROCESSING VISUALIZER/Audio/SAIL - AWOLNATION.mp3");
  //player = minim.loadFile("D:/programeer gedoe/Programs/Music visualiser/PROCESSING VISUALIZER/Audio/Ganja White Night - Mr Nice.mp3");
  player = minim.loadFile("D:/programeer gedoe/Programs/Music visualiser/PROCESSING VISUALIZER/Audio/Imagine Dragons, Radioactive HD.mp3");
  size(1000, 1000, P3D);
  r = new float[total+1][total+1];
  colormap = new color[total+1][total+1];
  globe = new PVector[total+1][total+1];
  colorMode(HSB);
  smooth();
  frameRate(30);
  meta = player.getMetaData();
  beat = new BeatDetect();
  fft = new FFT(player.bufferSize(), player.sampleRate());
  player.play(35000);
}

void draw() {
  background(0);
  lights();
  noStroke();
  // if (!calculated) {
  //float nJ=0;
  println("nI: " + nI);
  println("nJ: " + nJ);
  for (int i = 0; i < total+1; i++) {
    float lat = map(i, 0, total, 0, PI);
    for (int j = 0; j < total+1; j++) {
      r[i][j] = map(player.left.get(i)*player.left.get(j), -1, 1, minRad, maxRad);
      //r[i+1][j] = map(player.left.get(i)*player.left.get(j), 0, 1, minRad, maxRad);
      //if (j == total && i == total) {
      //  r[i][j] = map(player.left.get(0)*player.left.get(0), 0, 3.5, minRad, maxRad);
      //}
      if (nI > 15 && up) {
        up = false;
      }
      if (nI >= 15) {
        up = false;
      } else if (nI <= 0) {
        up = true;
      }
      if (up) {
        nI+=0.0000002;
        nJ+=0.0000002;
      } else {
        nI-=0.0000005;
        nJ-=0.0000005;
      }
      hu = map(r[i][j], minRad, maxRad, 0, 255);
      colormap[i][j] = color(hu, 255, 255);
      //fill(hu, 255, 255);
      float lon = map(j, 0, total, 0, TWO_PI);
      //float x = rad*cos(lon)*sin(lat);
      //float y = rad*sin(lat)*sin(lon);
      //float z = rad*cos(lat);
      float x = r[i][j]*cos(lon)*sin(lat);
      float y = r[i][j]*sin(lat)*sin(lon);
      float z = r[i][j]*cos(lat);
      globe[i][j] = new PVector(x, y, z);
    }
  }
  calculated = true;
  //}

  for (int i =0; i < total; i++) {
    beginShape(TRIANGLE_STRIP);
    for (int j = 0; j < total + 1; j++) {
      fill(colormap[i][j]);
      PVector v = globe[i][j];
      PVector v2 = globe[i+1][j];
      vertex(v.x, v.y, v.z);
      fill(colormap[i+1][j]);
      vertex(v2.x, v2.y, v2.z);
    }
    endShape();
  }
}
Viewing all 2896 articles
Browse latest View live