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

I am wondering how to change the audio amp and the bars to be inside of the musical note image ?

$
0
0

Hello, I was wondering how to change the audio amp and the bars to be inside of the musical note image I added in the code. I am a beginner just need a little help for the solution. Also, I added a clear feature, but when I click "c" to clear it doesn't clear it and you have to take multiple button pressing c to see what I mean.

PImage img;
import processing.sound.*;
Amplitude amp;
AudioIn in;
float volume = 0;
int x = 0;

void setup() {
  amp = new Amplitude(this);
  in = new AudioIn(this, 0);
  in.start();
  amp.input(in);
  frameRate(50);
  background(0, 255, 255);
  size(600, 800);
  img= loadImage("Musical Note.png");
  PFont font;
  font = loadFont("UrbanClass-10.vlw");
  textFont(font, 12);
  text("Use microphone to change color of note and click to draw.", 10, 20);
}

void draw() {
  image(img, 25, 80);
  //Draw normal
  if (mousePressed && (mouseButton == LEFT)) {
    ellipse(mouseX, mouseY, 40, 40);
    fill(random(255), random(255), random(255));
    noStroke();
    //draw coin like pattern
  } else if (mousePressed && (mouseButton == RIGHT)) {
    ellipse(mouseX, mouseY, 40, 40);
    fill(0, 255, 255);
    noStroke();
  }
  volume = amp.analyze();  // get volume level
  println(volume);
  float graph = map(volume, 0, 1, height, 0);  //Scale 0-1 volume to height of canvas
  fill(random(255), random(255), random(255));
  rect(x, graph, 5, height);
  x += 5;   // increase x to draw rectangles of graph next to each other
  if (x > width) {
    x = 0;
    if (keyPressed == true) {
      if (key == 'c')
        background(0, 255, 255);
      text("Use microphone to change color of note and click to draw.", 10, 20);
    }
  }
}

exe not able to launch from command prompt

$
0
0

Hello,

I have a simple script to send osc commands and I want it to be called from another app. My processing script runs fine from processing itself, it also runs fine when I make it an executable file and double click on it. The problem is it won't run from the Command Prompt or from a bat file if I call that executable.

Any idea why? I tried with processing 2.x and 3.x and I'm on Windows 7 pro Thanks

Combine use of oscP5 and Fisica

$
0
0

Hello,

to make this fast: i'm a noob at processing and programming in general (started a couple of weeks ago), but I LOVE IT! Very fun so far.

My problem with this game I'm trying to create is, well I want to be able to control the "FBox player" (a rectangle that serves as the player) using oscP5. When I move the "//Player" part into draw I'm able to do it but it generates LOTS of boxes and trying to use background() to clean doesn't work. Can anyone help me out with this issue?

To sum up: let me control the box without the program generating hundreds of boxes:)

Many thanks in advance!

OscP5 oscP5;

FWorld world;

float x, y, inputX, inputY;

void setup() {

size(500, 500);

Fisica.init(this);
world = new FWorld();
world.setEdges();
world.setEdgesRestitution(0.5);

oscP5 = new OscP5(this, 12000);

 // Player
FBox player = new FBox(80, 20);
player.setPosition(x, 450);
world.add(player);

 // Ball
FCircle ball = new FCircle(25);
ball.setPosition(250, 250);
world.add(ball);
}

void draw() {
background(0, 150, 150);

world.step();
world.draw();

x = lerp(x, inputX, 0.08f);
 // y = lerp(y, inputY, 0.08f);

}

void oscEvent(OscMessage msg) {
if (msg.checkAddrPattern("/multi/1")) {
inputX = msg.get(0).floatValue() * width;
 // inputY = msg.get(1).floatValue() * height;

println(x + " " + y);

} }

The most simple and modular way to export a gif

$
0
0

Hi folks!

I've created two gif-export-functions in a seperate file to simplify the process of exporting gifs. Now all i have to do is calling the gifsetup-function in the setup and the gifdraw-function in draw.

This is an example for a sketch

int a = 0;

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

// Call the gifsetup-function
  gifsetup();
}

void draw() {
ellipse(width/2,height/2,a,a);
a++;
// Call the gifdraw-function
// Specify, how many frames shall be recorded
  gifdraw(40);
}

The functions are stored in a separate file (gifexport.pde)

import gifAnimation.*;

GifMaker gifExport;

void gifsetup() {
  println("gifAnimation " + Gif.version());
  gifExport = new GifMaker(this, "export.gif");
  gifExport.setRepeat(0);
  gifExport.setDelay(50);
}

void gifdraw(int frames) {

  gifExport.addFrame();
  if (frameCount == frames) {
    gifExport.finish();
    println("gif saved");
    exit();
  }
}

As you can see, all i have to do to export a gif is calling two functions: gifsetup(); in the setup and gifdraw(); in the draw-section.

Now my question is: Is it possible to simplify the gif-export a bit more? It would be perfect, to just have one lie of code instead of two. Maybe like this

gif(40);

Thanks and enjoy your weekend!

Tim

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

$
0
0

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

Here is code I have so far:

// libraries
import processing.sound.*;

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

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

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

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

    // YOUR FILTER CODE GOES HERE

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

MadMeshMaker using sound input

$
0
0

Hello everybody! I want to create a sort of mesh generator similar to the madmeshmaker http://www.madlab.cc/madmeshmaker/ The parameters i want to feed into the program should be based on sound! Has somebody experience with it or even some similar codes i can look on? i am totally new to processing so any help is appreciated!! best, Raffi

Sending a HTTP Get Request

$
0
0

Hi There. I have a few students who are attempting to send a get request from processing to retrieve their SCRATCH cloud data. I have instructed them to use the following: GET https://scratch.mit.edu/varserver/105015849

The Processing.org sketch looks like this:

import http.requests.*;

GetRequest get = new GetRequest("https://scratch.mit.edu/varserver/105015849“);
get.send();
get.addHeader(”Accept“, ”application/json“);
println(”Response Content: " +get.getContent());

However, no response is provided. Any suggestions?

Running PHP script via processing

$
0
0

Hi!

I have this wordpress plugin that creates and verifies new software licenses. It does this by sending an array of data to the server. I'm trying to write a piece of processing code that creates a license key. I can successfully send variables to my PHP script and I know they are received; I check this using an if statement in my PHP code that checks if the variable 'send' is received and sends the array of data I mentioned before:

Processing code:

import processing.net.*;

Client c;

String secret_key = "56fc633286bc72.62466890";
String action = "slm_create_new";
String f = "James";
String l = "Doe";
String email = "jdoe@yahoo.com";

void setup() {
size(200, 200);
background(50);
fill(200);
c = new Client(this, "www.roham.comxa.com", 21);

loadStrings("http://"+"roham.comxa.com/test.php/?key="+secret_key);
loadStrings("http://"+"roham.comxa.com/test.php/?action="+action);
loadStrings("http://"+"roham.comxa.com/test.php/?first="+f);
loadStrings("http://"+"roham.comxa.com/test.php/?last="+l);
loadStrings("http://"+"roham.comxa.com/test.php/?email="+email);
String[] b = loadStrings("http://"+"roham.comxa.com/test.php/?send=GO");
println(b);
}

void draw() {
   if (c.available() > 0) {
    String dataIn = c.readString();
    println(dataIn);
  }
}

PHP script:

<?

$postURL = "roham.comxa.com";

$data=array();
$data['secret_key']=isset($_GET['key'])?$_GET['key']:"";
$data['slm_action']=isset($_GET['action'])?$_GET['action']:"";
$data['first_name']=isset($_GET['first'])?$_GET['first']:"";
$data['last_name']=isset($_GET['last'])?$_GET['last']:"";
$data['email']=isset($_GET['email'])?$_GET['email']:"";


$PHPSubmit = isset($_GET['send'])?$_GET['send']:"";

if($PHPSubmit == "GO")
{
        echo "Sending Command ";
    $ch = curl_init ($postURL);
    curl_setopt ($ch, CURLOPT_POST, true);
    curl_setopt ($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
    $returnValue = curl_exec ($ch);
    var_dump($returnValue);
    echo $returnValue;
}
?>

So by logic, if the script enters the if statement, I should be able to successfully create a new license, but I only get "Sending Command" and "string(25631)" which means there was no reply and no license is created when I check the database. I understand that this may be a PHP issue but want to make sure that the processing code is correct. Please help if you know anything about this!

Thanks!


Dynamic Chart (or other control) Manipulation

$
0
0

I'm using the controlP5 library to visualize some UDP byte stream data, but ran into an issue with accessing Charts dynamically by their defined names.

The code is working when explicitly referencing Charts by their chart name (commented out at bottom), but I would like to do it all within the for loop down in "receiveUDP()". Below is my code. Is this possible?

class DataPoint {
  int Position;
  float Value;

  public DataPoint(int Position, float Value) {
    this.Position = Position;
    this.Value = Value;
  }
}

public class UDP_DooDad_3000 extends PApplet {
  ControlP5 cp5;

  Map<String, DataPoint> telemetryData = new HashMap<String, DataPoint>();

  Chart speedChart;
  Chart engineSpeedChart;
}

public void setup() {
  telemetryData.put("speed", new DataPoint(28, 0.0f));
  telemetryData.put("engineSpeed", new DataPoint(148, 0.0f));

  cp5 = new ControlP5(this);

  speedChart = cp5.addChart("speedChart", 0, 200, 200, 100)
    .addDataSet("speedDataSet");

  engineSpeedChart = cp5.addChart("engineSpeedChart", 210, 200, 200, 100)
    .addDataSet("engineSpeedDataSet");

  //...


}

public void receiveUDP(byte[] data) {
  for (Map.Entry<String, DataPoint> entry : telemetryData.entrySet()) {
    DataPoint iDataPoint = null;
    iDataPoint = entry.getValue();
    iDataPoint.Value = ripFloatData(data, iDataPoint.Position); //ripFloatData does some bitmashing in another function

    //Possible to reference the name of a chart dynamically?
    //  Chart[entry.getKey() + "Chart"].addData(entry.getKey() + "DataSet", iDataPoint.Value);
    //or
    //  cp5.getChart(entry.getKey() +  "Chart").addData(entry.getKey() + "DataSet", iDataPoint.Value);
  }

  // I want to avoid the below code. I was hoping to do it dynamically in the loop above instead of explicitly adding data points each chart's dataSet
  //DataPoint speedDataPoint;
  //speedDataPoint = telemetryData.get("speed");
  //speedChart.addData("speedDataSet", speedDataPoint.Value);

  //DataPoint engineSpeedDataPoint;
  //engineSpeedDataPoint = telemetryData.get("engineSpeed");
  //engineSpeedChart.addData("engineSpeedDataSet", engineSpeedDataPoint.Value);
}

How to make a sound clip play on an event/trigger?

$
0
0

Hey guys,

I'm building a game using Processing. How would I have a sound clip play during a custom event/trigger? For example, when a new level loads...or when my character gets hit. How do I have a sound clip occur during one of these events?

Using a (non P5) library that doesn't have a .jar file ?

$
0
0

I've been using Eclipse for a bit, but the ease of use and new features in the P3 IDE have made me come back to it.

I'm having some trouble installing an external library though. This is the one: https://github.com/google/gson

I looked around and found out that others got ext libraries to work, by adding the .jar file to the sketch.

This file was nowhere to be found in the zip however, so I tried making it myself. Went into eclipse, made a new java project and did import > archive file. Added gson-master.zip. Then did export > java > jar file.

After adding the file to my sketch, I put import com.google.gson.Gson; at the top. But it gives me "The package "com.google" does not exist. You might be missing a library." error.

Tried adding it to my library folder, made a folder "gson" with a folder "library" inside and put the .jar in there. It shows up in the Sketch > Import library menu now, but when I click it it doesn't add a line. I clearly should read up on how libraries function within processing...

Any idea on how I could get this to work?

controlp5 tab positioning (deprecated?)

$
0
0

Is it still possible to reposition tabs in cp5? form this reference it says to use ControlWindow.setPositionOfTabs(int, int) but ControlWindow is deprecated. http://www.sojamo.de/libraries/controlP5/reference/controlP5/Tab.html ControllerGroup.setPosition(int, int) doesn't work, at least just playing with the example, like this: cp5.getTab("extra").activateEvent(true).setId(2).setPosition(30, 40);

How to make a sound clip play on an event/trigger?

$
0
0

Hey guys,

Trying to have a sound clip play when something happens (e.g. an event occurs).

I'm building a game using Processing. How would I have a sound clip play during a custom event/trigger? For example, when a new level loads...or when my character gets hit. How do I have a sound clip occur during one of these events?

Landscape generator with the help of sound

$
0
0

Hello,

I am working on a landscape generator. i had the idea of a Perlin Noise surface wich interacts with sound. I wonder how i can feed it with even more parameters to get it more visible that the sound has an influence on the surface? has anybody an idea or even a similar example i can look on?

This is my code:

import ddf.minim.*;
import ddf.minim.analysis.*;
Minim minim;
AudioPlayer player;
AudioMetaData meta;
BeatDetect beat;

FFT fftLin;
FFT fftLog;



boolean record;


int datascale = 250;
int dsh = datascale / 2;
float[][] data = new float [datascale][datascale];
float incrementation = 0.01;
int dataheight = 190;
int g;
int p;
float fram;
float z = 0.9;
float zoff = 3;
boolean stop;
boolean lnon;
float framspeed = 0.01;
boolean mouseleftpressed;


import peasy.*;
PeasyCam cam;

void setup() {
  background(0);
  stroke(255);
  strokeWeight(1);
  size(1920, 1080,P3D);
    minim = new Minim(this);
  player = minim.loadFile("groove.mp3");
  meta = player.getMetaData();
  beat = new BeatDetect();
  player.loop();
//  player.play();



}
void draw() {


   beat.detect(player.mix);


    lights();
     if(stop==false) {
    fram += framspeed;
  }

 translate(width/2, height/2);
  rotateY(map(mouseX,0,width*0.1,-PI/2,PI/2));
  rotateX(map(mouseY,0,height*0.1,-PI/2,PI/2));


int bsize = player.bufferSize();

  for(int i = 0; i < datascale; i++) {                                                                                                     //funktion  incrementation
      for(int j = 0; j < datascale; j++) {
       data[i][j] = 2 * noise((i+bsize)*incrementation/4+52, (j+p)*incrementation/4+35, fram/4) + (noise((i+g)*incrementation,
        (j+p)*bsize + pow(noise((i+bsize)*incrementation, (j+p)*incrementation, fram)*2, 2), fram+zoff)) * dataheight;
     }
   }                                                                                                                                           //funktion

  background(0);        //hier wird geupdated


  scale(2);

  for(int i = 1; i < datascale-1; i++) {                                                                                             //konstruktion
    for(int j = 1; j < datascale-1; j++) {


      if(lnon == true) {
        line((i-dsh)*2, (j-dsh)*2, data[i][j], (i-1-dsh)*2, (j-1-dsh)*2, data[i-1][j-1]);
        line((i-dsh)*2, (j-dsh)*2, data[i][j], (i-1-dsh)*2, (j+1-dsh)*2, data[i-1][j+1]);
      }else{
        noStroke();
        beginShape(TRIANGLE_STRIP);
          vertex((i-dsh)*2, (j-dsh)*2, data[i][j]);
          vertex((i-dsh)*2, (j+1-dsh)*2, data[i][j+1]);
          vertex((i+1-dsh)*2, (j-dsh)*2, data[i+1][j]);
          vertex((i+1-dsh)*2, (j+1-dsh)*2, data[i+1][j+1]);
        endShape(CLOSE);
      }
    }
  }


 }                                                                                                                                  //konstruktion

How to Merge 2 Sketches with different setups

$
0
0

Hello everyone! I am trying to merge two sketches into one and switch between them with p5control. I have already put them into classes and this kinda works well but I still have a problem. One of the two sketches uses PeasyCam, the other doesn't. I would like to being able to limit the activity of Peasy cam only to one of the sketches, equivalently being able to embed each sketch into a main one, having each sketch working separately with their own setup and draw functions. Would you think it is possible? By looking around I saw that it could be possible by the main class PApplet, i.e. by statements of the type: public class Collision extends PApplet {}, but I haven't been able to find anything precise for implementing it. Here is an example of code until now:

import peasy.*;
import processing.opengl.*;

Withpeasy Mypeasy;
Nopeasy MyNopeasy;


void setup() {

  size(600, 600, OPENGL);
  smooth();
  Mypeasy = new Withpeasy(this);
  MyNopeasy= new Nopeasy();

}

void draw(){
 background(0);
 Mypeasy.display();
 MyNopeasy.display();
 }

public class Withpeasy {
  PeasyCam cam;
//--------First sketch: I want to control it with peasycam
  Withpeasy(processing.core.PApplet parent) {

    cam = new PeasyCam(parent, 1000);

  }
  void display() {
    stroke(235);
    noFill();
    strokeWeight(0.5);
    box(600);

  }
}
//--------Second sketch: I want it static, that doesn't react to peasycam
public class Nopeasy {
  Nopeasy() {}
  void display() {
    stroke(235);
    noFill();
    strokeWeight(0.5);
    ellipse(0,0,200,200);
  }
}

Thank you all!


How do I get sound out of Processing 3

$
0
0

Hi,

I'm new to Processing, I just got back into programming after 15 years. I'm currently making a simple game, in which i'd like to have some sounds. However, I can't get the "sound"-library to work. Every example-scetch I've tried gives this error:

A fatal error has been detected by the Java Runtime Environment:

#

Internal Error (0x20474343), pid=2972, tid=5820

#

JRE version: Java(TM) SE Runtime Environment (8.0_74-b02) (build 1.8.0_74-b02)

Java VM: Java HotSpot(TM) 64-Bit Server VM (25.74-b02 mixed mode windows-amd64 compressed oops)

Problematic frame:

C [KERNELBASE.dll+0x71f28]

#

Failed to write core dump. Minidumps are not enabled by default on client versions of Windows

#

An error report file with more information is saved as:

G:\Software\Overige\Processing 2\processing-3.0.2\hs_err_pid2972.log

#

If you would like to submit a bug report, please visit:

http://bugreport.java.com/bugreport/crash.jsp

The crash happened outside the Java Virtual Machine in native code.

See problematic frame for where to report the bug.

# Could not run the sketch (Target VM failed to initialize). For more information, read revisions.txt and Help ? Troubleshooting.

Tetris-fan

How to write binary STL

$
0
0

I'm trying to write binary stl's from Processing, I've done ASCII stl's before but they get way to big. I'm using the wikipedia article on binary stl to write them, but I can't get it to work.

Here's my code:

try {
    for (int i=0; i!=80; ++i) {
      binfile.write(b[i]);      //useless header, as long as it doesn't begin with "solid"
    }

    binfile.write(0);
    binfile.write(0);
    binfile.write(0);
    binfile.write(4); //needs to be a 32 bit number, so yeah...
    for (int i=0; i<s.getVertexCount(); i+=3) {
      binfile.write(0);
      binfile.write(0);
      binfile.write(0);
      binfile.write(0);
      binfile.write(0);
      binfile.write(0);
      binfile.write(0);
      binfile.write(0);
      binfile.write(0);
      binfile.write(0);
      binfile.write(0);
      binfile.write(0);//normal vector, doesn't matter
      for (int j=0; j!=3; ++j) {
        float x = s.getVertex(i+j).x;
        float y = s.getVertex(i+j).y;
        float z = s.getVertex(i+j).z;

        int convertX = Float.floatToIntBits(x);
        int convertY = Float.floatToIntBits(y);
        int convertZ = Float.floatToIntBits(z);

        binfile.write(convertX >> 24);
        binfile.write(convertX >> 16);
        binfile.write(convertX >> 8);
        binfile.write(convertX);
        binfile.write(convertY >> 24);
        binfile.write(convertY >> 16);
        binfile.write(convertY >> 8);
        binfile.write(convertY);
        binfile.write(convertZ >> 24);
        binfile.write(convertZ >> 16);
        binfile.write(convertZ >> 8);
        binfile.write(convertZ);
      }
      binfile.write(0);
      binfile.write(0);  //attribute byte count (16 bit), never used
    }
    binfile.flush();
    binfile.close();
  }
  catch(IOException e) {
    println("Oh no! ");
  }

I have all the verteces in a PShape s, so I use those to write to the stl. Since the x,y,z coordinates have to be in a 32 bit floating point number, I convert them using Float.floatToIntBits. I then bitshift them because .write only writes the 8 least significant bits (see here). The four that I write after the header is the number of triangles. The program makes an stl file, but the file doesn't work, any idea where my mistake is?

How to resize sketch to the monitor

$
0
0

Hi, I have a sketch that is going to be presented on a large screen monitor. Is there a way to get my sketch to resize and center itself onto the monitor when it is run?

Here is my code: `` /* * Base Example * * Sketch that features the basic building blocks of a Spacebrew client app. * */

import spacebrew.*;

String server="192.168.1.57"; String name="Maria's Comp"; String description ="This is an blank example client that publishes .... and also listens to ...";

Spacebrew sb; String message ="Hello!"; PFont f; float r= 100;

int i = 0;

int color1 = i; int color2 = i; int color3 = i;

int color1e = i; int color2e = i; int color3e = i;

int[] color1a = new int[10]; int[] color2a = new int[10]; int[] color3a = new int[10];

int i1 =0; int i2 =0; int i3 =0;

//colorMode RGB;

PImage ring; PImage may; PImage new1; int np = 500 * 375;

void setup() { fullScreen(); imageMode(CENTER); //fill(255);

//size(375,500);

ring = loadImage("ring.jpg"); may= loadImage("maygs.jpg"); new1=loadImage("may.jpg");

for(int i =0; i < 10; i++){ color1a[i]=0; color2a[i]=0; color3a[i]=0; }

// instantiate the sb variable sb = new Spacebrew( this );

// add each thing you publish to // sb.addPublish( "buttonPress", "boolean", false );

// add each thing you subscribe to sb.addSubscribe( "color1", "range" );

sb.addSubscribe( "color2", "range" );

sb.addSubscribe( "color3", "range" );

// connect to spacebrew sb.connect(server, name, description ); }

//void draw() { void draw() {

// Update some picels ring.loadPixels(); may.loadPixels(); new1.loadPixels(); for (int i = 0; i < np; i++) { // Select random pixel

int ring_argb = ring.pixels[i];
//Fast way to get argb values in range 0-255
// for a pixel. The alpha is shown but not altered
// in this example
int ring_alpha = ring_argb >>> 24;
int ring_red = (ring_argb >> 16) & 0xFF;
int ring_green = (ring_argb >> 8) & 0xFF;
int ring_blue = ring_argb & 0xFF;


int may_argb = may.pixels[i];
//Fast way to get argb values in range 0-255
// for a pixel. The alpha is shown but not altered
// in this example
int may_alpha = may_argb >>> 24;
int may_red = (may_argb >> 16) & 0xFF;
int may_green = (may_argb >> 8) & 0xFF;
int may_blue = may_argb & 0xFF;

int new1_argb = new1.pixels[i];
//Fast way to get argb values in range 0-255
// for a pixel. The alpha is shown but not altered
// in this example
int new1_alpha = new1_argb >>> 24;
int new1_red = (new1_argb >> 16) & 0xFF;
int new1_green = (new1_argb >> 8) & 0xFF;
int new1_blue = new1_argb & 0xFF;

//playground- this one looks awesome write an artist statment about the convergence of the two pics.

new1_red =  (ring_red+may_red *color1e) % 255;
new1_green =(ring_blue + may_green * color2e) % 255;
new1_blue =  (ring_green + may_red * color3e)% 255;

//heavy metal version /* new1_red = (ring_red+may_red *color1e) % (color2+1); new1_green =(ring_blue + may_green * color2e) % (color3+1); new1_blue = (ring_green + may_red * color3e)% (color1+1); */

//good static image, but not as good as the first two

/* new1_red = (ring_red - may_red / (color1e+1)) % (color2+1); new1_green =(ring_blue - may_green / (color2e+1)) % (color3+1); new1_blue = (ring_green - may_red / (color3e+1))% (color1+1); */

new1_argb = (new1_alpha << 24) | (new1_red << 16) | (new1_green << 8) | new1_blue;
// update the pixel
new1.pixels[i] = new1_argb;

} // Stote the changes made to the image before displaying it new1.updatePixels(); // Now display updated image //new1.resize(0,displayHeight); image(new1, displayWidth/2, displayHeight/2); }

void onRangeMessage( String name, int value ) { println("got range message )" + name + ") : " + value); if (name.equals("color1")==true) { color1 = value;

if (color1 > 255) {
  color1 = 255;
}

if (color1<0) {
  color1=0;
}
int oldVal=color1a[i];
color1a[i] = color1;

color1e = abs(color1-oldVal);

i1=(i1+1) % 10;

} println("betsy)"+name+"):"+value); if (name.equals("color2")==true) { color2 = value;

if (color2 > 255) {
  color2 = 255;
}

if (color2<0) {
  color2=0;
}

int oldVal=color2a[i2];
color2a[i2] = color2;

color2e = abs(color2-oldVal);

i2=(i2+1) % 10;

}

//println("Hithere"+name); if (name.equals("color3")==true) { color3 = value; //println("setting"); if (color3 > 255) { color3 = 255; }

if (color3<0) {
  //println("<0");
  color3=0;
}

int oldVal=color3a[i3];
color3a[i3] = color3;

color3e = abs(color3-oldVal);

i3=(i3+1) % 10;

} //else //{ //println(name+"not color3"); //} }

void onBooleanMessage( String name, boolean value ) { println("got boolean message " + name + " : " + value); }

void onStringMessage( String name, String value ) { println("got string message " + name + " : " + value);
//if(name == "color1") { //color1 = value; }

//if(name == "color2") {

//color2 = value;

//if(name == "color3") { //color3 = value;

void onSbClose(){ println("sb closed, trying to reopen"); // instantiate the sb variable sb = new Spacebrew( this );

// add each thing you publish to // sb.addPublish( "buttonPress", "boolean", false );

// add each thing you subscribe to sb.addSubscribe( "color1", "range" );

sb.addSubscribe( "color2", "range" );

sb.addSubscribe( "color3", "range" );

// connect to spacebrew sb.connect(server, name, description );

}

void onCustomMessage( String name, String type, String value ) { println("got " + type + " message " + name + " : " + value); }

how can i have it say it once and thats it but once evertime the function is run?

$
0
0

i found a sketch that has the pc say whatever i want but the issue is that it will keep saying over and over, also i notice that it is very slow at processing and while the pc says anything the video output becomes slow or freezes for like 500ms which is crazy

import guru.ttslib.*;

TTS Server;

void setup() {
  size(100, 100);
  Server = new TTS();
}

void draw() {
}

void mousePressed() {
  Server.speak("Good day?");
}

now if i was to use a function inside draw and every time that functions condition is met the pc will say what ever is on that function right? but the issue is that while that function is being used the pc will keep saying the same thing over and over so HOW can i get it to say what ever JUST ONCE ?

Getting a NullPointerException Error in Processing Code

$
0
0

Below is the code for servo motor control using joystick but every time I run the program I get the NullPointerException error for the line no. 70 and 71: stickPosX = stick.getX() and stickPosY = stick.getY()

import procontroll.*;
import java.io.*;

ControllIO controll;
ControllDevice device;
ControllStick stick;
ControllStick stick1;

ControllButton button1;
ControllButton button2;
ControllButton button3;
ControllButton button4;
ControllButton button5;

import processing.serial.*;

Serial myPort;

int xIdent = 200;
int yIdent = 201;

float stickPosX = 360;
float stickPosY = 360;

void setup()
{
  size(720, 720);
  smooth();
  noStroke();

  controll = ControllIO.getInstance(this);

  controll.printDevices();

  device = controll.getDevice("USB Vibration Joystick");

  device.printSticks();

  device.printSliders();

  ControllSlider sliderX = device.getSlider("X-akse");
  ControllSlider sliderY = device.getSlider("Y-akse");
  ControllSlider glidebryterX = device.getSlider("Glidebryter");
  ControllSlider Z_rotasjon = device.getSlider("Z-rotasjon");

  stick = new ControllStick(sliderX, sliderY);
  stick1 = new ControllStick(glidebryterX, Z_rotasjon);

  device.setTolerance(0.005f);

  device.printButtons();

  button1 = device.getButton("Knapp 1");
  button2 = device.getButton("Knapp 0");
  button3 = device.getButton("Knapp 2");
  button4 = device.getButton("Knapp 3");
  button5 = device.getButton("Knapp 4");

  println(Serial.list());

  String portName = Serial.list()[0];

  myPort = new Serial(this, portName, 9600);
}

void draw() {

  background( 50 );

      stickPosX = stick.getX();
      stickPosY = stick.getY();

  stickPosX = map(stickPosX, -1, 1, 0, 720);
  stickPosY = map(stickPosY, -1, 1, 0, 720);

  constrain(stickPosX, 0, 720);
  constrain(stickPosY, 0, 720);

  myPort.write(xIdent);

  myPort.write(int(map(stickPosX, 0, 720, 120, 80)));

  myPort.write(yIdent);

  myPort.write(int(map(stickPosY, 0, 720, 90, 30)));

  fill(255, 0, 0);
  ellipse(stickPosX, stickPosY, 33, 33);
}
Viewing all 2896 articles
Browse latest View live