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

SuperCollider client problem

$
0
0

Hi all, I'm trying to make the SuperCollider client for Processing work. I have SC 3.7.2 and Processing 3.1.1. I tried to run an example sketch from Daniel John Jones website. The processing part seems to work alright i.e. I get a window displaying a bouncing line but no sound and ...

SuperCollider says :

"FAILURE IN SERVER /n_set Node 2000 not found"

Processing says :

"### [2016/8/13 11:8:5] PROCESS @ OscP5 stopped.

[2016/8/13 11:8:5] PROCESS @ UdpClient.openSocket udp socket initialized.

[2016/8/13 11:8:6] PROCESS @ UdpServer.start() new Unicast DatagramSocket created @ port 57150

[2016/8/13 11:8:6] PROCESS @ UdpServer.run() UdpServer is running @ 57150

[2016/8/13 11:8:6] INFO @ OscP5 is running. you (192.168.1.21) are listening @ port 57150

oscEvent: /b_info oscEvent: /done oscEvent: /done oscEvent: /fail oscEvent: /fail oscEvent: /fail oscEvent: /fail...

... and so on.

Does anyone of you have an idea of what's happening ?

Thanks.

Raphaël

PS : here's the sketch by the way :)

import supercollider.*;
import oscP5.*;

float bx = width / 2,
      by = height / 2,
      vx = 0,
      vy = 0;

Buffer buffer;
Synth synth;

int [] samples;

void setup()
{
  size(1024, 512);
  frameRate(25);
  smooth();

  samples = new int[width];

  buffer = new Buffer(width, 1);
  buffer.alloc(this, "allocated");

  vx = random(-10, 10);
  vy = random(-10, 10);
}

void allocated (Buffer buffer)
{
  buffer.zero();

  synth = new Synth("playbuf_1");
  synth.set("loop", 1);
  synth.set("bufnum", buffer.index);
  synth.create();
}

void exit()
{
  synth.free();
  buffer.free();
  super.exit();
}

void draw()
{
  background(0);
  fill(255);
  noStroke();

  bx += vx;
  by += vy;

  if (bx > width - 1)
  {
    bx = width - 1;
    vx = 0 - vx;
  }
  if (bx < 0)
  {
    bx = 0;
    vx = 0 - vx;
  }
  if (by > height - 1)
  {
    by = height - 1;
    vy = 0 - vy;
  }
  if (by < 0)
  {
    by = 0;
    vy = 0 - vy;
  }

  if (mousePressed)
  {
    vx += (mouseX - bx) * 0.001;
    vy += (mouseY - by) * 0.001;
  }

  buffer.fill((int) bx, (int) abs(vx + 1), (2.0 * by / height) - 1.0);
  for (int i = 0; (i < abs(vx + 1)) && (bx + i < width - 1); i++)
  {
    samples[(int) bx + i] = (int) by;
  }

  for (int i = 0; i < samples.length; i++)
  {
    stroke(150);
    point(i, samples[i]);
  }

  if (synth != null)
  {
    synth.set("pan", (float) bx / width - 0.5);
    synth.set("rate", (float) 0.1 + 0.2 * sqrt(sq(vx) + sq(vy)));
  }
  ellipse(bx, by, 3, 3);
}

G4P use GTextField for number entry only

$
0
0

I'm working on a program that takes a grid of numbers as inputs. I'd like to use GTextField objects to enter each number. As far as I can tell, there's no easy way to limit the possible characters to the digits 0-9 only. I think I know how to make an event handler that's called whenever a text field changes, and simply deletes any wrong characters. The problem I'm running into here is that I'd need to find a way to scale this to work with multiple text fields. I would prefer not to have a separate event handler for each text field, as this would result in many copies of the same code, just with different method names. Any suggestions how I could go about doing this?

Hello. How to draw a button?

$
0
0

Screenshot_2016-08-14-21-16-13

import controlP5.*;
ControlP5 cp5;

Object sun;
Object earth;
Object moon;

PVector camPos;
PVector camEye;
float camRadius, camTheta, camPhi;

void setup()
{
    size(displayWidth, displayHeight, P3D);
    cp5 = new ControlP5(this);
    cp5.setAutoDraw(false);
    cp5.addButton("Button",1,20,20,100,20);

    earth = new Object(1000, 0, 0, 100);
    moon = new Object(1200, 0, 0, 20);

    camPos = new PVector(300, 0, 20);
    camEye = new PVector(0, 0, 0);
    camRadius = 2000;
    camTheta = 160;
    camPhi = -40;
}

void draw()
{
    background(100, 100, 100);
    camera(camPos.x, camPos.y, camPos.z, camEye.x, camEye.y, camEye.z, 0, 0, 1);
    noLights();
    pointLight(255, 255, 255, 150, 0, 0);

    if(mousePressed)
    {
        camTheta += (mouseX - pmouseX);
        camPhi += (pmouseY - mouseY);
    }
    updateCamera();
    earth.draw();
    moon.draw();
}

void updateCamera()
{
    camPos.x = camEye.x + camRadius * cos(camPhi * PI/180) * sin(camTheta * PI/180);
    camPos.y = camEye.y + camRadius * cos(camPhi * PI/180) * cos(camTheta * PI/180);
    camPos.z = camEye.z + camRadius * sin(camPhi * PI/180);
}

using .setSize() with controlP5 imageButtons

$
0
0

Hi there guys, here is the default example for imageButton with ControlP5. (one can find it under Examples)

I was wondering if there was a way to scale up/down say the rolloverImage by a few pixels. So that when you rollover with your mouse the button appears to pop in place.

I tried .setSize(int,int) before .updateSize(); but it does nothing. If you remove the line .updateSize() it freezes.

Any ideas? Tried the java docs but unsure of the syntax/method here.

import controlP5.*;

ControlP5 cp5;

int myColor = color(0);


void setup() {
  size(400, 600);
  cp5 = new ControlP5(this);

  // replace the default controlP5 button with an image.
  // button.setImages(defaultImage, rolloverImage, pressedImage);
  // use button.updateSize() to adjust the size of the button and
  // resize to the dimensions of the defaultImage

  cp5.addButton("buttonA")
    .setPosition(175, 275)
      .setImages(loadImage("Arrow-Left.png"), loadImage("Arrow-Right.png"), loadImage("Refresh.png"))
        .updateSize();
}

void draw() {
  background(myColor);
}

public void controlEvent(ControlEvent theEvent) {
  println(theEvent.getController().getName());
}

// function buttonA will receive changes from
// controller with name buttonA
public void buttonA(int theValue) {
  println("a button event from buttonA: "+theValue);
  myColor = color(128);
}

controlP5 acting up

$
0
0

Here is a simple problem, but I can't seem to figure out why the sliders won't adjust the values of the recursion. Thanks in advance.

//hexagonal fractal
import controlP5.*;
ControlP5 cp5;

int radius = 400;
int num  = 4;

void setup() {
  size(800, 800);
  background(32);
  cp5 = new ControlP5(this);

  smooth();
  noFill();
  noLoop();
  frameRate(2);

  cp5.addSlider("num")
    .setRange(0, 6)
    .setPosition(100, 100)
    .setSize(10, 100)
    .setNumberOfTickMarks(5)
    ;

  cp5.addSlider("radius")
    .setRange(150,450)
    .setPosition(0, 100)
    .setSize(10, 100)
    .setNumberOfTickMarks(5)
    ;
}

void draw() {
  translate(width/2, height/2);
  drawHexagon(radius, num);
}

void drawHexagon(float radius, int num ) {
  stroke(255);
  float x, y = 0;
  beginShape();
  for (int i = 0; i < 6; i++) {
    x = cos(radians(60*i))*radius;
    y = sin(radians(60*i))*radius;
    vertex(x, y);
  }
  endShape(CLOSE);
  //////////////////////////////////////////////////////////////

  if (num-- > 1) {

    pushMatrix();
    translate(radius/2, 0);
    drawHexagon(radius/2, num);
    popMatrix();

    pushMatrix();
    translate(-radius/4, -radius*cos(radians(30))/2);
    drawHexagon(radius/2, num);
    popMatrix();

    pushMatrix();
    translate(-radius/4, radius*cos(radians(30))/2);
    drawHexagon(radius/2, num);
    popMatrix();
  }
}

Is there a default max size for the canvas or video using the IPcapture library?

$
0
0

I've been trying to use this library but I keep getting an error: "Frame resize: from 800x600 to 640x480". I'm trying to load a video and live streaming at the same time using both IPcapture and the video library from processing. Can someone please help me?

toxiclibs - toxiclibsSupport, PGraphics, setGraphics() - trying to use off screen buffer

$
0
0

hello,

I am fairly new to Processing and in the early stages of learning Java.
Thank you for this excellent library - it was crucial to the first major piece of software that I have written (used for an installation a couple of weeks ago).
What I am trying to do is use an instance of PGraphics (called 'frame' in the code below) to draw to the off screen buffer and then save as a .png - for many reasons, but in this case to use transparency (drawing lines and shapes(triangles) on a transparent background).
As soon as I either specify 'frame' in the constructor: "gfx = new ToxiclibsSupport (this, frame);" or use setGraphics(): "gfx.setGraphics(frame);" I get a draft rendering of the drawing - just black lines on a white background, no images, no shapes - for both the off screen buffer and the display.
I have tried everything to the limits of my current knowledge and abilities including using the P2D renderer (specified in size() and in the createGraphics () for 'frame'). As soon as I remove 'frame' from the ToxiclibsSupport constructor or comment out setGraphics(), everything returns to normal, so clearly it is the addition of this PGraphics instance. I have included a very simplified example of my code.

Thank you for any help,

ToxiclibsSupport gfx;
PGraphics frame;


void setup () {

  frame = createGraphics (width, height);
  gfx = new ToxiclibsSupport(this, frame);
  //gfx.setGraphics(frame);

}


void draw () {

  frame.save (imageFileName + nf (frameCount++, 3) + ".png");

}



used in a function:


void drawTriangles () {

  frame.beginDraw();

  for (int i = 0 ; i < triangleList.size () ; i++ ) {
    if (triangleList.get(i).on) {
      noStroke();
      colorSelect(i);
      gfx.polygon2D(triangleList.get(i).triangle);
    } else {
      noFill();
      stroke(white);
      gfx.polygon2D(triangleList.get(i).triangle);
    }
  }

  frame.endDraw();
  image(frame,0,0);
}

Saito OBJLoader Array

$
0
0

Hello,i have this code

import saito.objloader.*;

OBJModel model ;
OBJModel tmpmodel ;


PVector[] PVArray;
float rotX, rotY;
float k = 0.0;

void setup()
{
  size(800, 600, P3D);
  frameRate(30);
  model = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
  model.enableDebug();

  model.scale(100);
  model.translateToCenter();

  tmpmodel = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);

  tmpmodel.enableDebug();

  tmpmodel.scale(100);

  tmpmodel.translateToCenter();


  frameRate(100);
  stroke(255);
  noStroke();
}



void draw()
{
  background(129);
  lights();
  translate(width/2, height/2, 0);
  //rotX+=0.1;
  rotY+=0.01;
  //rotateX(rotX);
  //rotateY(rotY);


  pushMatrix();


  for (int i = 0; i < model.getVertexCount (); i++) {
    PVector orgv = model.getVertex(i);
    PVector tmpv = new PVector();
    PVArray[i] = new PVector();
    //tmpv.x = mouseY;
    //tmpv.y = mouseY;
    println(orgv);
    tmpv.x = orgv.x *(i*mouseX);
    tmpv.y = orgv.y+ (i*0.01) ;
    tmpv.z = orgv.z;
    tmpmodel.setVertex(i, tmpv);
  }
  k+=0.01;



  popMatrix();

  tmpmodel.draw();
}

I have problem with the model.getVertex(i) function,I want to make an array of the PVectors that it gets,so i can manipulate them individualy,with custom functions.and no as a whole object.Do you have any idea?Or u think its better to use PShapeObj?

Thanks in advance


Childrens game

$
0
0

Hi I've made this small game, when a letter is pressed its displayed on screen as an image and a sound plays. When I run the code and press a letter it shows the letter and plays the sound, but when I press the letter again it displays the letter but doesn't play the sound. I've tried using .rewind(); and what happens after that it first time I press a letter it plays the sound and displays the letter, and if I press the same letter again it displays the letter and when i release the key it plays the sound :S.

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 ha;
AudioPlayer sh;
AudioPlayer no;
AudioPlayer ra;
AudioPlayer ba;
AudioPlayer lh;

PImage[] letters = new PImage[6];

void setup() {
  size(400, 400);
  background(0);

  minim = new Minim(this);
  ha = minim.loadFile("0.mp3");
  sh = minim.loadFile("1.mp3");
  no = minim.loadFile("2.mp3");
  ra = minim.loadFile("3.mp3");
  ba = minim.loadFile("4.mp3");
  lh = minim.loadFile("5.mp3");

  imageMode(CENTER);

  for (int i = 0; i<letters.length; i++) {
    letters[i] = loadImage(+i+".jpg");
  }
}
void draw() {
  background(0);
  if ((keyPressed == true)&&(key == 'h')) {
    image(letters[0], width/2, height/2, 200, 200);
    ha.play();
  }
  if ((keyPressed == true)&&(key == 's')) {
    image(letters[1], width/2, height/2, 200, 200);
    sh.play();
  }
  if ((keyPressed == true)&&(key == 'n')) {
    image(letters[2], width/2, height/2, 200, 200);
    no.play();
  }
  if ((keyPressed == true)&&(key == 'r')) {
    image(letters[3], width/2, height/2, 200, 200);
    ra.play();
  }
  if ((keyPressed == true)&&(key == 'b')) {
    image(letters[4], width/2, height/2, 200, 200);
    ba.play();
  }
  if ((keyPressed == true)&&(key == 'l')) {
    image(letters[5], width/2, height/2, 200, 200);
    lh.play();
  }
}

G4P and PeasyCam in OS X

$
0
0

I can not get G4P controls to work with either peasyCam or proScene in OS X. It seems like mouse events are not passed on to G4P. Things work fine in windows 10. Any suggestions why this is?

Try the example in G4P - "G4P_with_PeasyCam".

OS X El Capitan 10.11.2 Processing 3.1.2 G4P 4.0.5 PeasyCam

Best - andreas

Using Mindset Library for accessing Neurosky

$
0
0

Hello, I am trying to run an example sketch to use Neurosky on windows 7 in processing 3.1.1. I am using this library available at www.jorgecardoso.eu/processing/MindSetProcessing. Example sketch name : 'Mindset All Values'.

When I run the sketch : The error comes as "Error opening serial port /dev/cu.MindWaveMobile-DevA: Port busy" and the output window goes to loading state. There is no application running in parallel still it is showing the port busy error..

Once I shut the output window I can see more errors :

blinkEvent() method not defined. rawEvent() method not defined. Could not run the sketch (Target VM failed to initialize). For more information, read revisions.txt and help ? Troubleshooting.

This is my first post in forum but I am using processing since long time. Thanks in advance for the support.

Unfolding Maps: Map Style is not working

$
0
0

Hi There,

I am using Unfolding Maps in Processing 2.2.1 and it's working just fine until I tried to import my own styling.

According to their tutorial page - which is pretty bad documented - I just need to import a mbtiles file

String tilesStr = sketchPath("data/control-room.mbtiles"); map = new UnfoldingMap(this, new MBTilesMapProvider(tilesStr));

I generated a mbtiles file with TileMill from the Control Room example and it seems to be fine but when running the following sketch..

import de.fhpotsdam.unfolding.*; import de.fhpotsdam.unfolding.utils.*;

UnfoldingMap map; import de.fhpotsdam.unfolding.providers.MBTilesMapProvider; void setup() { size(800, 600); String tilesStr = sketchPath("data/control-room.mbtiles"); map = new UnfoldingMap(this, new MBTilesMapProvider(tilesStr)); MapUtils.createDefaultEventDispatcher(this, map); map.setZoomRange(2, 4); } void draw() { map.draw(); }

.. I get a long list of exceptions:

Unfolding Map v0.9.6 No OpenGL renderer. Using Java2DMapDisplay. java.lang.ClassNotFoundException: org.sqlite.JDBC at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:190) at de.fhpotsdam.unfolding.tiles.MBTilesLoaderUtils.getMBTileData(Unknown Source) at de.fhpotsdam.unfolding.tiles.MBTilesLoaderUtils.getMBTile(Unknown Source) at de.fhpotsdam.unfolding.providers.MBTilesMapProvider.getTile(Unknown Source) at de.fhpotsdam.unfolding.tiles.TileLoader.run(Unknown Source) at java.lang.Thread.run(Thread.java:745) java.lang.ClassNotFoundException: org.sqlite.JDBC at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) ...

EDIT: SQlite library was missing

How to connect sliders to attractors with Punktiert + ControlP5?

$
0
0

Hi, I'm working with Punktiert and ControlP5 to create a definition with a bunch of particles and attractors.

The definition below is working fine but I would like to add some sliders to change in real time the behavior of the attractors and their number. At the moment I'm stuck on this two issues:

1// How to connect the slider s01 to change automatically the number of attractors created? Since the attractors are created in the draw() function, I cannot update them again. But if I create the attractors in the draw() function Processing keeps creating new attractors every new frame.

2// How can I change the value of the radius for each attractor with the sliders s02, s03, s04? To change the slider radius I'm using " attr.setRadius(radii.get(i))" in a for loop in the draw() function. How can I relate the sliders to the radius values?

Below the code.

Thank you.

import punktiert.math.Vec;
import punktiert.physics.*;
import controlP5.*;

// World object
VPhysics physics;

int attractorsNum = 3;
int particlesNum = 100;

ArrayList<BAttraction> attractors;
FloatList attractorsX;
FloatList attractorsY;
FloatList radii;

void setup() {
  size(800, 800);
  smooth();
  ControlP5 cp5 = new ControlP5(this);

  // Set up physics
  physics = new VPhysics();
  physics.setfriction(0.4);

  attractors = new ArrayList<BAttraction>();
  attractorsX = new FloatList();
  attractorsY = new FloatList();
  radii = new FloatList();

  //Create radius values for attractors
  for (int i=0; i<attractorsNum; i++) {
    float radius = random(100, 500);
    radii.append(radius);
  }

  //Slider to control attractor numbers and attractors radius
  Slider s01 = cp5.addSlider("attractorsNum", 1, 15, attractorsNum, 10, 10, 100, 10);
  Slider s02 = cp5.addSlider("radius01", 100, 500, radii.get(0), 10, 30, 100, 10);
  Slider s03 = cp5.addSlider("radius02", 100, 500, radii.get(1), 10, 50, 100, 10);
  Slider s04 = cp5.addSlider("radius03", 100, 500, radii.get(2), 10, 70, 100, 10);

  // Create attractor in random positions
  for (int i = 0; i<attractorsNum; i++) {
    float x = random(0, width);
    float y = random(0, height);
    attractorsX.append(x);
    attractorsY.append(y);
    BAttraction attr = new BAttraction(new Vec(x, y), radii.get(i), 0.1);
    attractors.add(attr);
    println(attr);
  }

  // Add attractors to world
  for (int i=0; i<attractors.size (); i++) {
    BAttraction attr = attractors.get(i);
    physics.addBehavior(attr);
  }

  //Create particles
  for (int i = 1; i<particlesNum; i++) {
    // Set particle radius
    float rad = 5;
    // Set position vector
    Vec pos = new Vec(random(0, width), random(0, height));
    // Create particle (position, mass, radius)
    VParticle particle = new VParticle(pos, 1, rad);
    // Add Collision Behavior
    particle.addBehavior(new BCollision());
    // Add particle to world
    physics.addParticle(particle);
  }
}

void draw() {
  background(0);
  // Update physics
  physics.update();

  // Draw particles
  fill(255);
  for (VParticle p : physics.particles) {
    ellipse(p.x, p.y, p.getRadius()*2, p.getRadius()*2);
  }

  // Set attractors
  for (int i=0; i<attractors.size (); i++) {
    BAttraction attr = attractors.get(i);
    float x = attractorsX.get(i);
    float y = attractorsY.get(i);
    attr.setAttractor(new Vec(x, y));

    //Set Radius for each attractor:
    attr.setRadius(radii.get(i));

    // Show influence radius
    noFill();
    stroke(255, 0, 0);
    ellipse(attr.getAttractor().x, attr.getAttractor().y, attr.getRadius(), attr.getRadius());

    // Show attractor
    noStroke();
    fill(255, 0, 0);
    ellipse(attr.getAttractor().x, attr.getAttractor().y, 10, 10);
  }
}

Trying to Visualize Breath as a Line Graph

$
0
0

Hi all, I'm a noob.

I've got some JSON data from a device I wear that measures breathing. The file I reference in the code below is here.

And I've copied and pasted various bits of code from the Processing reference docs and also other sites to get to where I am now, which is code that parses the JSON and plots it on a graph, but right now it's only plotting one point. I know it's because I'm copying and pasting without really realizing the cause and effect, but I do believe I've actually learned a thing or two with that strategy over the last couple of days.

I've got a long way to go... like figuring out how to convert from Unix epoch to regular time, how to animate the line so it looks sorta like this EKG code, and how to only query the data for 24 hours at a time, etc. etc., but right now I'm just trying to figure out why I don't have a whole buncha dots plotted in that tiny space. Help?

// Importing Drawing Library from http://www.gicentre.net/utils/chart
import org.gicentre.utils.stat.*;

JSONObject json;
XYChart lineChart;

void setup() {
  size(500, 200);
  textFont(createFont("Arial", 10), 10);

  json = loadJSONObject("bigdata.json");

  JSONArray data = json.getJSONArray("data");

  for (int i = 0; i < data.size(); i++) {

    JSONObject item = data.getJSONObject(i);

    int timestamp = item.getInt("timestamp");
    float value = item.getFloat("value");
    String event_type = item.getString("event_type");

    //println(timestamp + ", " + value + ", " + event_type);

    // Both x and y data set here.
    lineChart = new XYChart(this);
    lineChart.setData(new float[] {timestamp},
      new float[] {value});

    // Axis formatting and labels.
    lineChart.showXAxis(true);
    lineChart.showYAxis(true);
    lineChart.setMinY(0);

    lineChart.setYFormat("00.00");  // Breath Rate
    lineChart.setXFormat("0000000000"); // EPOCH Timestamp Format

    // Symbol colours
    lineChart.setPointColour(color(180, 50, 50, 100));
    lineChart.setPointSize(5);
    lineChart.setLineWidth(2);
  }
}

void draw()
{
  background(255);
  textSize(9);
  lineChart.draw(15, 15, width-30, height-30);

  // Draw a title over the top of the chart.
  fill(120);
  textSize(20);
  text("Breath-rate", 70, 30);
  textSize(11);
  text(" Since Wearing Spire",
    70, 45);
}

parse a tcp message

$
0
0

hi guys, i need some expert advice on this.

I have successfully created the tcp connection between processing and matlab. I am using oscp5 library for that. I am sending an array containing x and y coordinates from processing and my intent is to draw a sine wave in matlab with these received x & y values.

My question is how i can separate the coordinates after receiving in matlab? Also, i think i need to alter some setting in tcpip object because i am not receiving the same values in matlab, which i am sending.

You can see the code and their values below.

-------------Processing Code-------------
import oscP5.*;
import netP5.*;

OscMessage myMessage;
OscP5 oscP5tcpClient;

int xspacing = 16;   // How far apart should each horizontal location be spaced
int w;              // Width of entire wave
float theta = 0.0;  // Start angle at 0
float amplitude = 75.0;  // Height of wave
float period = 500.0;  // How many pixels before the wave repeats
float dx;  // Value for incrementing X, a function of period and xspacing
float[] yvalues;  // Using an array to store height values for the wave
int x;

void setup() {
  size(640, 360);
  oscP5tcpClient = new OscP5( this, "141.44.219.161", 1234, OscP5.TCP);
  w = width+16;
  dx = (TWO_PI / period) * xspacing;
  yvalues = new float[w/xspacing];
}

void draw() {
  background(0);


  calcWave();
  OscMessage myMessage = new OscMessage("/test");
  myMessage.add(new float[] { x*xspacing, height/2+yvalues[x]});  =====>>> These values are sent to Matlab.
  oscP5tcpClient.send(myMessage);
  print(x*xspacing, height/2+yvalues[x]);
}

void calcWave() {
  // Increment theta (try different values for 'angular velocity' here
  theta += 0.02;

  // For every x value, calculate a y value with sine function
  float x = theta;
  for (int i = 0; i < yvalues.length; i++) {
    yvalues[i] = sin(x)*amplitude;
    x+=dx;
  }
}

void renderWave() {
  noStroke();
  fill(255);
  // A simple way to draw the wave with an ellipse at each location
  for (int x = 0; x < yvalues.length; x++) {
    ellipse(x*xspacing, height/2+yvalues[x], 16, 16);
  }

}

--------------------------MATLAB Code----------------------------
>> tcpipServer = tcpip('141.44.219.161',1234,'NetworkRole','Server');
>> fopen(tcpipServer)
>> data =fread(tcpipServer)

data =

     0
     0
     0
    20
    47
   116
   101
   115
   116
     0
     0         ===>>> these are values i am receving in matlab, which is completely different from what i am sending.
     0
    44
   102
   102
     0
     0
     0
     0
     0
    67
    53
   127
   249

>>
------------------------------------------------------------------

Values which i am sending from processing is look something like below

230.19330 229.068510 227.924120 226.760530 225.578230 224.37770 223.159410 221.923840 220.671510 219.40290 218.118520 216.818880 215.504520 214.175930 212.83370 211.47830 210.110320 208.730290 207.338760 205.936280 204.523440 203.100770 201.668870 200.228290 198.779620 197.323430 195.860320 194.390850 192.915620 191.435230 189.950270 188.461320 186.968980 185.473860 183.976550 182.477630 180.977740 179.477450 177.9773


How can I use translate() to move a shape?

$
0
0

I have used processing for a few months now. I had a question regarding the uses of Translate. I want to make it so that the grid, which I defined using vertices and beginShape(QUAD_STRIP);, lies in the center of the window. I would also like the sphere to be in the center. The code is below. Any answers?

import peasy.*;
int w = 20;
int h = 20;
int scl = 10;
float [][] grid;
PeasyCam camera;

void setup(){
  size(1000, 1000, P3D);
  grid = new float[w][h];
camera = new PeasyCam(this, 0, 0, 0, 100);
}
void draw(){
    lights();
   background (0);
      pushMatrix();
     fill(255);
   sphere(50);
   // noFill();
    noStroke();

popMatrix();

pushMatrix();

//translate(width/2, height/2, 0);
 translate(width/2, height/2 +50);
   rotateX(PI/2.8);                      //setting up perspective

   translate(-w/2, -h/2);
    for(int y = 0; y < h-1; y++) {
noFill();
stroke(255);
     beginShape(TRIANGLE_STRIP);       //preset object in Processing; I can use a net of vertices to make a strip/plane of triangles. The beginShape(); object uses any vertices to create the object specified in the argument ().
     for(int x = 0; x < w; x++){
      vertex(x*scl, y*scl, grid[x][y]);
      vertex(x*scl, (y+1)*scl,grid[x][y+1]);
     }
     endShape();
   }
popMatrix();

}

How to get the point of intersection from curve.

$
0
0

名称未設定

Hello.I'd like to make a some kind of controller like attached file. the curve(white bold line) can be controlled by green button and numbers can map from x coordinate from y coordinate.

I could make curve and button controll. I have been stuck while getting the point of intersection. (added red point by photoshop) I researched and found geomerative library provides intersection method. but i couldn't find how to read bezier curve Rpath object.

Could anyone can tell me how to read bezier curve to geomerative, or any other idea to getting intersection with bezier and lines?

Out of Control y Axis- ROLLING GRAPH

$
0
0

Noobie here, I'm trying to take an input from an arduino over a usb and plot onto a graph. Everything is fine except I cant seem to map where the y begins and ends on my graph. I tried so many things but its stuck between 0 and about 400px. You'll see the box where the graph is suppose to occupy. I can't move/control the y axis. I drew out the issue in red on the attached image, please help!!

You'll see reference to multiple sensors, I am only trying to plot the sensor "moisture" for now.

/This sketch is frankensteined from the SerialCall Response example with arduino and
//this guy's sketch(code in description of video) - http://pastebin.com/kSrU3nVH

import processing.serial.*;

int moisture;  //the only sensor I'm currently trying to plot
float inByte;
int second; //sensors that ar![]()e not yet plotted but printed in the Console
int third;  // " "
int fourth; // " "

Serial myPort;                       // The serial port
int[] serialInArray = new int[4];    // Where we'll put what we receive
int serialCount = 0;                 // A count of how many bytes we receive
PFont  g_font;
boolean firstContact = false;        // Whether we've heard from the microcontroller

int[] yValues;
int w;

//SETUP
void setup() {
  size(1280, 720);  // Stage size

  g_font = loadFont("ArialMT-20.vlw");
  textFont(g_font, 20);

  w = 640; //width of our plot
  strokeWeight(1);
  smooth(); // or noSmooth();
  yValues = new int[w];

  println(Serial.list());
  String portName = Serial.list()[1];
  myPort = new Serial(this, portName, 9600);
}

void draw() {
  String inString = myPort.readStringUntil('\n');

  if (inString != null) {
    inString = trim(inString);
    inByte = float(inString);

    moisture = int(map(inByte, 0, 255, 360, 25));
    //setting the boundry for the graph line, inside box EXCEPT IT DOESNT WORK
  }

  //This should be down here, but works inside the if statement.
  //moisture = int(map(inByte, 0, 255, 360, 25));

  //Background and box for graph
  background(55);
  rect(25, 25, 615, 335);
  fill(255);
  //LEGEND
  strokeWeight(1.5);
  stroke(255, 0, 0);
  line(20, 420, 35, 420);
  stroke(0, 255, 0);
  line(20, 440, 35, 440);
  stroke(0, 0, 255);
  line(20, 460, 35, 460);
  stroke(255, 255, 0);
  line(20, 480, 35, 480);

  fill(0, 0, 0);
  text("Moisture", 40, 430);
  text("Analog A1", 40, 450);
  text("Analog A2", 40, 470);
  text("Analog A3", 40, 490);

  //ACTUAL PLOTTED LINE
  for (int i = 1; i < w; i++) {
    yValues[i-1] = yValues[i];
  }
  yValues[w-1] = moisture;
  //}

  stroke(120, 200, 0);
  line(w, moisture, 0, moisture);
  strokeWeight(3);


  //This controls the horizontal "TICKER LINE"
  for (int i=1; i<w; i++) {
    //stroke (rgb)
    stroke(220, 75, yValues[i]);
    //point folar x, float y
    point(i, yValues[i]);
    rect(0, 25, 50, 335);
    fill(255);
  }
}

void serialEvent(Serial myPort) {
  // read a byte from the serial port:
  int inByte = myPort.read();

  if (firstContact == false) {
    if (inByte == 'A') {
      myPort.clear();          // clear the serial port buffer
      firstContact = true;     // you've had first contact from the microcontroller
      myPort.write('A');       // ask for more
    }
  } else {
    // Add the latest byte from the serial port to array:
    serialInArray[serialCount] = inByte;
    serialCount++;

    // If we have 3 bytes:
    if (serialCount > 3) {
      moisture = serialInArray[0];
      second = serialInArray[1];
      third = serialInArray[2];
      fourth = serialInArray[3];

      // print the values (for debugging purposes only):
      println(moisture + "\t" + second + "\t" + third + "\t" + fourth);

      // Send a capital A to request new sensor readings:
      myPort.write('A');
      // Reset serialCount:
      serialCount = 0;
    }
  }
}

/*ARDUINO UNO CODE
 int firstSensor = 0;    // first analog sensor
 int secondSensor = 0;   // second analog sensor
 int thirdSensor = 0;    // digital sensor
 int fourthSensor = 0; //turning this into a fluxuating value
 int inByte = 0;         // incoming serial byte

 void setup()
 {
 // start serial port at 9600 bps:
 Serial.begin(9600);


 pinMode(2, INPUT);   // digital sensor is on digital pin 2
 establishContact();  // send a byte to establish contact until receiver responds
 }

 void loop()

 {

 // if we get a valid byte, read analog ins:
 if (Serial.available() > 0) {
 // get incoming byte:
 inByte = Serial.read();
 // read first analog input, divide by 4 to make the range 0-255:
 firstSensor = analogRead(A0);
 // delay 10ms to let the ADC recover:
 delay(10);
 // read second analog input, divide by 4 to make the range 0-255:
 secondSensor = analogRead(A1) / 4;
 // read  switch, map it to 0 or 255L
 thirdSensor = map(digitalRead(A2), 0, 1, 0, 255);
 // send sensor values:
 fourthSensor = analogRead(A3) / 4; //new sensor I added
 Serial.write(firstSensor);
 Serial.write(secondSensor);
 Serial.write(thirdSensor);
 Serial.write(fourthSensor);

 }
 }

 void establishContact() {
 while (Serial.available() <= 0) {
 Serial.print('A');   // send a capital A
 delay(300);

 }
 }
 */![Screen Shot 2016-08-18 at 11.45.51 PM](https://forum.processing.org/two/uploads/imageupload/608/2KIEZIROU05C.jpg "Screen Shot 2016-08-18 at 11.45.51 PM")

What is wrong with the Sound Library that it fails to work?

$
0
0

Thanks for any light that you can shed on this problem.

#

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

#

SIGSEGV (0xb) at pc=0x000000012092a04e, pid=3823, tid=0x0000000000011f03

#

JRE version: Java(TM) SE Runtime Environment (8.0_102-b14) (build 1.8.0_102-b14)

Java VM: Java HotSpot(TM) 64-Bit Server VM (25.102-b14 mixed mode bsd-amd64 compressed oops)

Problematic frame:

C [libmethcla.dylib+0x5604e] remove_free_block+0x3e

#

Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again

#

An error report file with more information is saved as:

/Users/rodemer/hs_err_pid3823.log

#

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

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

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

cannot use Processing sound library

$
0
0

If I try to use the Processing sound library I get the error: Java (TM) Platform SE binarxy does not function any more. I tried it wirh P3.1.2 and P3.2. I have this problem only with sektches that contain the sound library?

System: Windows 7 64bit, Audiointerface Behringer FCA1616 (USB)

If anybody has an idea I would appreciate a response.

Viewing all 2896 articles
Browse latest View live