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

How To Put Admob In the Sketch?

$
0
0

Hello, I want to know how to put ADMOB in processing sketch. any help would be nice. Thanks in advance.


Question about QRCode library

$
0
0

Hello everybody,

Today, I found the QRCode library from Daniel Shiffman with the following code:

/*
QRcode reader
 Generate images from a QRcode generator such as
 http://qrcode.kaywa.com/ and put them in this sketch's
 data folder.
 Press spacebar to read from the camera, generate an image,
 and scan for barcodes.  Press f to read from a file and scan.
 Press s for camera settings.
 Created 9 June 2007
 by Tom Igoe / Daniel Shiffman
 */


import processing.video.*;
import qrcodeprocessing.*;

Capture video;                                 // instance of the video capture library
String statusMsg = "Waiting for an image";     // a string to return messages:

// Decoder object from prdecoder library
Decoder decoder;

void setup() {
  size(400, 320);
  video = new Capture(this, 320, 240);
  video.start();

  // Create a decoder object
  decoder = new Decoder(this);
}

// When the decoder object finishes
// this method will be invoked.
void decoderEvent(Decoder decoder) {
  statusMsg = decoder.getDecodedString();
}

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

void draw() {
  background(0);

  // Display video
  image(video, 0, 0);
  // Display status
  text(statusMsg, 10, height-4);

  // If we are currently decoding
  if (decoder.decoding()) {
    // Display the image being decoded
    PImage show = decoder.getImage();
    image(show, 0, 0, show.width/4, show.height/4);
    statusMsg = "Decoding image";
    for (int i = 0; i < (frameCount/2) % 10; i++) statusMsg += ".";
  }
}

void keyReleased() {
  // Depending on which key is hit, do different things:
  switch (key) {
  case ' ':
    // Spacebar takes a picture and tests it:
    // copy it to the PImage savedFrame:
    PImage savedFrame = createImage(video.width, video.height, RGB);
    savedFrame.copy(video, 0, 0, video.width, video.height, 0, 0, video.width, video.height);
    savedFrame.updatePixels();
    // Decode savedFrame
    decoder.decodeImage(savedFrame);
    break;
  case 'f':    // f runs a test on a file
    PImage preservedFrame = loadImage("qrcode.png");
    // Decode file
    decoder.decodeImage(preservedFrame);
    break;
  }
}

But if Ioad it, the 'Capture video' (line 4 here, normally line 17) is underlined red and is says: 'The class 'Capture' does not exist'. Does anybody knows how to fix this? I'm using Processing 3 by the way.

Regards, Daantje

How to fix an older version of code to processing 3.1 !

$
0
0

I just started to work with toxic_library , but I am having an issue. The code suppose to be made with an older version of processing, probably 1.0 ..... I installed toxi library but still I have a bunch of unknown list of commands , likewise: setColorLabel,addToggle,captionLabel,valueLabel,addButton and so on ....

Here below I'll show you the link maybe someone of you could show some interests ....

http://www.openprocessing.org/sketch/65086

THNX.

How can i make a complex shape in pBox2d using only in Rectangles?

$
0
0

I have been reading the pbox2d code for complex shapes.

I need to make a shape like the one shown here shape

I think I need to create a horizontal rectangle and add vertical rectangles to each end of the horiztontal rectangle, but I'm not sure how to create each and attach them.

I was trying to use this code as a reference, that uses a circle and a rectangle, but haven't been able to change it's characteristics into just rectangles or polygons.

Reference Code

class Lollipop {

// We need to keep track of a Body and a width and height Body body; float w; float h; float r;

// Constructor Lollipop(float x, float y) { w = 8; h = 24; r = 8; // Add the box to the box2d world makeBody(new Vec2(x, y)); }

// This function removes the particle from the box2d world void killBody() { box2d.destroyBody(body); }

// Is the particle ready for deletion? boolean done() { // Let's find the screen position of the particle Vec2 pos = box2d.getBodyPixelCoord(body); // Is it off the bottom of the screen? if (pos.y > height+w*h) { killBody(); return true; } return false; }

// Drawing the lollipop void display() { // We look at each body and get its screen position Vec2 pos = box2d.getBodyPixelCoord(body); // Get its angle of rotation float a = body.getAngle();

rectMode(CENTER);
pushMatrix();
translate(pos.x, pos.y);
rotate(-a);
fill(127);
stroke(0);
strokeWeight(2);

rect(0,0,w,h);
ellipse(0, -h/2, r*2, r*2);
popMatrix();

}

// This function adds the rectangle to the box2d world void makeBody(Vec2 center) {

// Define the body and make it from the shape
BodyDef bd = new BodyDef();
bd.type = BodyType.DYNAMIC;
bd.position.set(box2d.coordPixelsToWorld(center));
body = box2d.createBody(bd);

CircleShape circle = new CircleShape();
circle.m_radius = box2d.scalarPixelsToWorld(r);
Vec2 offset = new Vec2(0,-h/2);
offset = box2d.vectorPixelsToWorld(offset);
circle.m_p.set(offset.x,offset.y);

PolygonShape ps = new PolygonShape();
float box2dW = box2d.scalarPixelsToWorld(w/2);
float box2dH = box2d.scalarPixelsToWorld(h/2);
ps.setAsBox(box2dW, box2dH);

body.createFixture(ps,1.0);
body.createFixture(circle, 1.0);

// Give it some initial random velocity
body.setLinearVelocity(new Vec2(random(-5, 5), random(2, 5)));
body.setAngularVelocity(random(-5, 5));

} }

Thank you

G4P: Is GEvent ENTERED available for GTextArea

$
0
0

Hello!

It seems there is GEvent ENTERED for GTextArea, but it doesn't get detected for GTextArea. I'm testing with "G4P_EditTextControls.pde" from the library examples (Windows 7, Processing 2.2.1 & 3.0.1.)

Instead of ENTER going to new paragraph, I want to move focus to next GTextArea. I this possible with GTextArea object or G4P library?

Thanks

Converting FFT Amplitude to dB/Hz

$
0
0

Hello, I'm trying to use the Sound library to create a spectrogram. I looked at the FFTSpectrogram example that comes in the library. My goal is to create a spectrogram that looks similar to the output from MATLAB's spectrogram function (image below):

laurance

The whole spectrogram is generated in one image, it is not dynamic with the current audio. The y-axis is frequency (Hz), the x-axis is time (s), and the color axis is Power/frequency (dB/Hz). The FFT class has a spectrum object, but I'm not sure how to convert that value to dB/Hz.

Change of Basis Matrix example

$
0
0

I am trying to study a little about matrices but I am having a hard time figuring out what is wrong with my code. The purpose of this code is to setup some 3d transformation (position and orientation) objects and than get the position and orientation of a neighbour object from the point of view of the current object. In other words, It is just getting a transform coordinate from different origin, (including orientation).

Current code will run perfectly. Blinking point in space is how A looks at C, if A was fixed at 0,0,0. In the other hand when I set C to look at A, the code will fail at some angles of C... This has to be something about rotation ranges that I am not aware of how to solve...Maybe something not so hard but I don't have enough background to do it by myself.

[I am using peasy cam library just to visualize the results a little better but a any camera will do]

code is commented below

import peasy.*;
PeasyCam pcam;

Transform A, B, C = new Transform();
float c,d; //counters

void setup() {
  size(400, 400, P3D);
  rectMode(CENTER);
  pcam = new PeasyCam(this, 100);
  pcam.setDistance(200);
  pcam.rotateY(degrees(45));
  pcam.rotateX(degrees(-45));

  //initial Transformations tx, ty, tz, rx, ry, rz
  float RZ = 0;//PI; //will fail if PI
  A = new Transform(0, 0, 50, 0, 0, RZ);
  A.label = 'A';
  B = new Transform(0, 0, -50, 0, 0, 0);
  B.label = 'B';
  C = new Transform(0, 30, 0, 0, 0, 0);
  C.label = 'C';

  //testing outputs
  PMatrix3D Am = A.getTMatrix();
  Am.print();
  Transform At = mat2Transform(Am);
  At.print();
}

void draw() {
  background(100);
  c+=.2;
  d+=.01;
  pushMatrix();
  rotateX(HALF_PI);
  noFill();
  stroke(255);
  point(0,0,0);
  rect(0, 0, 100, 100);
  popMatrix();

  //testing some moviments
  A.ty = radians( sin(c)*10 );
  A.ry = radians( sin(d)*45 );
  C.rz = radians( c ); //fails to get reference

  A.draw();
  //B.draw();
  C.draw();
  A.showReference(C);// this is how A sees C if A was fixed at 0,0,0
  //C.showReference(A); //fails
}



Transform mat2Transform(PMatrix3D m) {
  float ax = m.m00;
  float ay = m.m10;
  float az = m.m20;
  float bz = m.m21;
  float cz = m.m22;
  float tx = m.m03;
  float ty = m.m13;
  float tz = m.m23;
  float rx = atan2(bz, cz);
  float ry = atan2(-az, sqrt( pow(bz, 2)+pow(cz, 2) ) );
  float rz = atan2(ay, ax) ;
  Transform t = new Transform(tx, ty, tz, rx, ry, rz);
  return t;
}



class Transform {

  float tx, ty, tz, rx, ry, rz;
  float axisRadius = 30;
  PMatrix3D tm; //transform matrix
  int cor;
  char label;

  Transform() {
    cor = color(random(0,255),random(0,255),random(0,255));
  }
  Transform(float tx, float ty, float tz, float rx, float ry, float rz) {
    this.tx = tx;
    this.ty = ty;
    this.tz = tz;
    this.rx = rx;
    this.ry = ry;
    this.rz = rz;
    cor = color(random(0,255),random(0,255),random(0,255));
  }

  PMatrix3D getTMatrix() {
    float Cx = cos(rx);
    float Cy = cos(ry);
    float Cz = cos(rz);
    float Sx = sin(rx);
    float Sy = sin(ry);
    float Sz = sin(rz);

    /*
    double[][] rxm = {  { 1,   0,   0 },
                        { 0,  Cx,  -Sx},
                        { 0,  Sx,   Cx}};

    double[][] rym = {  {  Cy , 0,  Sy},
                        {  0  , 1,  0 },
                        { -Sy , 0,  Cy}};

    double[][] rzm = {  { Cz, -Sz , 0},
                        { Sz,  Cz , 0},
                        { 0 ,  0  , 1}};
    */
    //http://planning.cs.uiuc.edu/node102.html
    tm = new PMatrix3D(  Cz*Cy  , Sz*Sy*Sx - Sz*Sx , Cz*Sy*Cz + Sz*Sx , tx ,
                          Sz*Cy  , Sz*Sy*Sx + Cz*Cx , Sz*Sy*Cx - Cz*Sx , ty ,
                          -Sy    ,       Cy*Sx      ,       Cy*Cx      , tz ,
                           0     ,          0       ,         0        ,  1);
    return tm;
  }


  void print() {
    println(tx, "  ", ty, "  ", tz, " | ", rx, "  ", ry, "  ", rz);
  }


  void showReference(Transform referenceTransform){

    PMatrix3D refMtx = referenceTransform.getTMatrix();
    refMtx.invert();//
    PMatrix3D thisMtx = this.getTMatrix();
    refMtx.apply(thisMtx);//multiplying reference T matrix with this T matrix
    refMtx.invert();//

    Transform output = new Transform();
    output = mat2Transform(refMtx);
    output.axisRadius = 10;
    output.draw();

  }


  void draw() {
    strokeWeight(6);
    stroke(cor);
    pushMatrix();
    translate(tx, ty, tz);
    point(0, 0, 0);
    rotateX( rx );
    rotateY( ry );
    rotateZ( rz );
    pushMatrix();
    strokeWeight(1);
    stroke(lerpColor(#00ff00,cor,.2)); //X
    line(0, 0, axisRadius, 0);
    stroke(lerpColor(#ff0000,cor,.2)); //Y
    rotateZ(HALF_PI);
    line(0, 0, axisRadius, 0);
    stroke(lerpColor(#0000ff,cor,.2)); //Z
    rotateY(HALF_PI);
    line(0, 0, axisRadius, 0);
    popMatrix();
    popMatrix();
    strokeWeight(1);

    //label
    pushMatrix();
    translate(tx, ty, tz);
    float[] r = pcam.getRotations();
    rotateX( r[0]);
    rotateY( r[1]);
    rotateZ( r[2]);
    textSize(9);
    fill(255);
    text(label, 0,-0);
    popMatrix();

  }
}

Callback functions for audio

$
0
0

Hi, is there any callback functions for audio events?

I am interested of a function type the "MousePressed()" that it is called every time a new array of say 256 samples microphone samples is available for processing.

I looked through the Mimin library and I could not see such one.

Also I would like to know if there is some function to change the sampling frequency of the audio, e.g. 8kHz or 16kHz since for speech that frequency is good enough. Once having 8000Hz, the callback should then be invoked repeatedly every 256/8000 seconds. That is how often I want to process the audio samples.

If possible samples should also be stored in some buffer to accept sporadic delays that makes the callback function execution to be delayed since I do not want to loose samples.

Maybe such functionality already exists hidden in some library. Please let me know!

Thanks /Alberto


G4P: Is possible select text lines in the GTextArea by program?

$
0
0

I need to select one line at a time inside a text contained in a textarea as if it were selected by mouse or keyboard. How can I do?

How to find "nearest" color in array of colors?

$
0
0

I'm trying to write a script that will output something akin to this kind of rubiks cube art from a source image.

I found this HPPixelColorist code snippit using the HYPE framework that is getting me fairly close but I'm having trouble figuring out a way of converting the colors that are pulled from the image into the 6 colors that are on a rubiks cube.

What's the best way of going about this?

Here's my code right now. It's using the HYPE framework (which was too long to include in that snippit) and it requires a source image to run.

How to do 3D Solid Difference Set in processing?

$
0
0

Hi everyone! I'm starting studying IGeo & P3D and I'm trying make an 3D Solid Difference Set.Is there a function to do this? For example: 123

Accessing private variable inside a library class

$
0
0

I am trying to get an array from inside a library class, but the field is set as private :((

I used a java decompiler website to see this source of code:

public class MultiMarker
 extends NyARPsgBaseClass {
 protected PImageSensor _ss;
 protected NyARMarkerSystem _ms;
 public static final double DEFAULT_CF_THRESHOLD = 0.51;
 public static final int DEFAULT_LOST_DELAY = 10;
 public static final int THLESHOLD_AUTO = -1;
 private ArrayList<Integer> _id_map = new ArrayList();  //<<------- I WANT TO ACCESS THIS
 private final PMatrix3D _ps_projection = new PMatrix3D();
 private boolean _is_in_begin_end_session = false;

So this is what I had tried following some examples using Java as reference but still variable is NOT VISIBLE. maybe some casting problem...

import java.lang.reflect.*;
import jp.nyatla.nyar4psg.*;

MultiMarker nya;
void setup() {
  size(640,360);
  nya=new MultiMarker(this, 640, 360, "camera_para.dat", NyAR4PsgConfig.CONFIG_PSG);
  nya.addARMarker("patt.hiro", 80);//id=0
  nya.addARMarker("patt.kanji", 80);//id=1

  try {
      MultiMarker.class.getDeclaredField("_id_map").setAccessible(true);
      //or
      //Field idmap = MultiMarker.class.getDeclaredField("_id_map");
      //idmap.setAccessible(true);
      // ArrayList<Integer> castTest = idmap.get( ArrayList<Integer>() ); //--error
      // ArrayList<Integer> castTest = (ArrayList<Integer>)idmap.get(idmap); //--error

  }
    catch (ReflectiveOperationException e) {
    throw new RuntimeException(e);
  }

  println(nya._id_map.size()); //field is not visible
}

Problem Beads and Control P5

$
0
0

Hi, this is my first post on this forum os i'm sorry if my question isn't at the right place. I'm using Processing 3.1.1 and I have some problems with Beads. I'm using ControlP5 to change the gain of my Audioplayer but look at this code, it gives me a really long error from the void Musique and I don't know why. paste2.org/eAL307Hd

Then the 2nd problem is when I start a long music, sometimes the program takes tool long to launch and it gives me this errorjava.lang.RuntimeException: Waited 5000ms for: <6c8aac95, 624d5f74>[count 2, qsz 0, owner <main-FPSAWTAnimator#00-Timer0>] - <main-FPSAWTAnimator#00-Timer0-FPSAWTAnimator#00-Timer1> at processing.opengl.PSurfaceJOGL$2.run(PSurfaceJOGL.java:449) at java.lang.Thread.run(Thread.java:745)

And finally I'd like to know how to loop a sound because when i use setToLoopStart() and .KillOnEnd() it tells me that those functions doesn't exist.

Thanks for your help :)

using websocket to transmit the video frame

$
0
0

hi every one I've plan to send the frame of big image from processing on my laptop to couple of ESP node through my home wifi-modem , each ESP has couple LED strip attached to it and processing slice the image and add node IP address to each of them and transmit to those which way is the safe and fast ? plain TCP? UDP? server websocket of processing and client websocket on ESP node? client websocket of processing and server websocket on ESP node? if we consider 25 frame per second , each package must deliver under 40ms and concurrent multiple connection should be create and kept live any help is really appreciated

Unfolding Maps: Can't initialize a map and set the size/position

$
0
0

Hi All,

I'm relatively new at this so please be kind, I'm sorry if this is a super dumb question.

I am trying to make a basic map using the unfolding maps library (which I intend to incorporate into another sketch once I can get it working). I have been able to get the map running at full window size, but I need to scale it down. From everything I have read this should be relatively simple- just some position and size parameters added to the initializer. However, when I do this (no matter what parameters I use) the map goes to position: 0,0 and size: 500 x 500px (approx). (see image)

Here is the code I've got:

import de.fhpotsdam.unfolding.*;
import de.fhpotsdam.unfolding.core.*;
import de.fhpotsdam.unfolding.data.*;
import de.fhpotsdam.unfolding.events.*;
import de.fhpotsdam.unfolding.geo.*;
import de.fhpotsdam.unfolding.interactions.*;
import de.fhpotsdam.unfolding.mapdisplay.*;
import de.fhpotsdam.unfolding.mapdisplay.shaders.*;
import de.fhpotsdam.unfolding.marker.*;
import de.fhpotsdam.unfolding.providers.*;
import de.fhpotsdam.unfolding.texture.*;
import de.fhpotsdam.unfolding.tiles.*;
import de.fhpotsdam.unfolding.ui.*;
import de.fhpotsdam.unfolding.utils.*;
import de.fhpotsdam.utils.*;
import de.fhpotsdam.unfolding.providers.Google;

AbstractMapProvider p1 = new Google.GoogleSimplifiedProvider();
UnfoldingMap map;

void settings() {
  size(800, 800, P2D);

  map = new UnfoldingMap(this, 100, 100, 100, 100, p1 ); //this line positions the map at 0,0 and around 500,500 size-see above image
  //map = new UnfoldingMap(this, p1 ); //this works properly but the map is full screen
}

void setup() {

  //map = new UnfoldingMap(this, p1 ); if I try to put this line here I get this error: java.lang.NoSuchFieldError:quailty (unless I removed P2D from size)
  Location melbourneLocation = new Location(-37.815924f, 144.966815f);
  float maxPanningDistance = 0.5; // in km
  map.zoomAndPanTo(15, melbourneLocation);
  map.setPanningRestriction(melbourneLocation, maxPanningDistance);
  map.setZoomRange(14, 18);
  MapUtils.createDefaultEventDispatcher(this, map);
}

void draw() {

  map.draw();
}

Any help would be amazing!


ControlP5 ControlFrame not working P3.1.1

$
0
0

I just upgraded to Processing 3.1.1 and updated the ControlP5 library, and my code that was working earlier on P3 is now throwing an error I can't trace. The error is: The method add(Component) in the type Container is not applicable for the arguements (MyApp.ControlFrame)

Error is thrown on f.add(p); below

    ControlFrame addControlFrame(String theName, int theWidth, int theHeight) {
      PImage icon = loadImage("MY_LOGO.png");
      frame.setIconImage(icon.getImage());    //  ========== SET WINDOW ICON

      Frame f = new Frame(theName);
      ControlFrame p = new ControlFrame(this, theWidth, theHeight);
      f.add(p);
      p.init();
      f.setTitle(theName);
      f.setSize(p.w, p.h);
      f.setLocation(displayWidth - 250, 30);
      f.setResizable(true);
      f.setVisible(true);
      f.setAlwaysOnTop( true );
      f.setIconImage(icon.getImage());    //  ========== SET WINDOW ICON
      return p;
    }

Has something changed in the latest release of Processing to cause this, or am I missing something else? Any suggestions and/or insights are very much welcome.

How to process more than one audio inputs?

$
0
0

Hi all. First time here send message :) I'm very interested in《Messa di voce》( image ),but I don't know how to process more than one audio inputs with Minim just like what the video shows(two kinds of sound inputs control the motion trail in different places separately). The programming below is from the example of Minim. How to change it so I can create two kinds of inputs? Or there are maybe some other ways? //////////////////////////////////////////////////////////////////////// import ddf.minim.*;

Minim minim; AudioInput in;

void setup() { size(512, 200, P3D);

minim = new Minim(this);

// use the getLineIn method of the Minim object to get an AudioInput in = minim.getLineIn(); } \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ Poor expression maybe. Thank you :)

trouble draging items

$
0
0

Hi All I am trying to write a sketch to draw the track plan of my model railroad on my screen using Process I have the data in a table which i load and run, ok but to edit the location of a {turnout/point/switch) depending on which country you come from I have to edit the table in notepad each time. what i would like to do is be able to drag the {turnout/point/switch) to a new location and have the table up dated automatically. by dragging it with the mouse. i have tried doing something like what is in the mouse function demo sketch, but with no luck

can any one help me.

//import controlP5.*;
import processing.serial.*;
int tableRows=20;
Serial myPort;
Table myTrack;  //used to draw track point/turnouts on screen
String FileName2="track.csv";
int id, ls, le ;
String na, lrs, rt, vis;
PFont f1;
PFont f2;
PFont f3;
Turnout turnout;  // class
float bx;
float by;
int boxSize = 10;
boolean overBox = false;
boolean locked = false;
float xOffset = 0.0;
float yOffset = 0.0;

void setup() {
  size(1400, 900);
  bx = width/2.0;
  by = height/2.0;
  turnout = new Turnout() ; //new class
  printArray(Serial.list());
  // myPort = new Serial(this, Serial.list()[0], 9600);
  f1 = createFont("Arial", 16, true);
  f2 = createFont("Arial Black", 18, true);
  f3 = createFont("Arial", 14, true);
  strokeWeight(1);
  stroke(0);
  textFont(f1);
  // uncomment the next  line to creat new tables
  //track();
 // then  edit table in notpad
  //---- load tables ---------------
  myTrack = loadTable(FileName2, "header");
  println(myTrack.getRowCount() + " total rows in myTrack");
}

void draw() {
  background(0, 250, 250);
  strokeWeight(0);
  stroke(200);
  fill(0);
  text((Serial.list()[0]), 10, 100);
  for (int i = 0; i <= tableRows-1; i++)
  {
    list_turnouts(i);  // get info from table
    String letter= vis.toUpperCase();
    switch(letter) {
    case "Y"  :   // is it visable ?
      turnout.setit( id, na, ls, le, lrs, rt, vis);
      turnout.display();
      break;
    }
  }
  stroke(0);
  fill(255);
  saveTable(myTrack, FileName2);
}

// now read table and set all lower case to uper case
void list_turnouts(int temp_i) {
  int i=temp_i;
  id=  myTrack.getInt(i, "T_Id");
  na=  myTrack.getString(i, "Name");
  String na1= na.toUpperCase();
  myTrack.setString(i,"Name", na1);
   ls = myTrack.getInt(i, "Loc_S");
  le = myTrack.getInt(i, "Loc_E");
    lrs =myTrack.getString(i, "L_R_S");
  String lrs1= lrs.toUpperCase();
  myTrack.setString(i,"L_R_S", lrs1);
   rt = myTrack.getString(i, "Rotate");
   String rt1= rt.toUpperCase();
  myTrack.setString(i,"Rotate", rt1);
    vis = myTrack.getString(i, "Visable");
   String vis1= vis.toUpperCase();
  myTrack.setString(i,"Visable", vis1);

}

void mousePressed() {
  if (overBox) {
    locked = true;
    fill(0);
  } else {
    locked = false;
  }
  xOffset = mouseX-bx;
  yOffset = mouseY-by;
}

void mouseDragged() {
  if (locked) {
    bx = mouseX-xOffset;
    by = mouseY-yOffset;
  }
}

void mouseReleased() {
  locked = false;
}

class Turnout {
  // verible used inside class Point
  int px;
  int py;
  int pid;
  String pl;
  String pa;
  String pv;
  String pn;
  String temps;

  Turnout() {
  };

  void setit(int id, String na, int x1, int y1, String sl, String sa, String vis) {
    pid=id;
    pn=na;
    px = x1+300;// screen off set
    py = y1+50;  // screen off set
    pl = sl;
    pa = sa;
    pv=vis;
  }

  void display() {
    int ex=0;
    int ey=0;
    textFont(f3);
    strokeWeight(4);
    stroke(0);
    ex=0;
    ey=0;
    String letter1= pl.toUpperCase();
    switch(letter1) {
    case "R":
      ex=px+25;
      text(pn, py-10, px-10);//print name above line
      break;
    case "L":
      ex=px-25;
      text(pn, py-10, px+20);//print name below line
      break;
    case "":
      ex=px;
      break;
    }
    String letter2= pa.toUpperCase();
    switch(letter2) {
    case "W":
      ey=py-25;
      break;
    case "E":
      ey=py+25;
      break;
    case "":
      ey=py   ;
      break;
    }
    //draw switch
    ellipse(py, px, 15, 15);
    line( py, px, ey, ex);
    line( py-25, px, py+25, px);
     strokeWeight(1);
// hylight turnout with red dot
    if (mousePressed == true) {
      if (dist(mouseX, mouseY, py, px) < 15) { //hylight
        fill(255, 0, 0);
        ellipse(py, px, 15, 15);
        textFont(f1);
        //next 3 line for debug
        text(pid, 10, 20);
        text(py-50, 10, 40);
        text(px-300, 10, 60);
      }
       fill(0);
    }
    // now if draged
    // move it ??
  }
}//

content of table looks like this

T_Id,Name,Loc_S,Loc_E,L_R_S,Rotate,Visable
1,00,10,100,R,E,Y
1,N1,40,80,L,W,Y
2,N2,70,60,R,E,Y
3,N3,100,40,L,W,Y
4,N1,0,0,,,
5,N1,0,0,,,
6,N1,0,0,,,
7,N1,0,0,,,
8,N1,0,0,,,
9,N1,0,0,,,
10,N1,0,0,,,
11,N1,0,0,,,
12,N1,0,0,,,
13,N1,0,0,,,
14,N1,0,0,,,
15,N1,0,0,,,
16,N1,0,0,,,
17,N1,0,0,,,
18,N1,0,0,,,
19,N1,0,0,,,
20,N1,0,0,,,

ControlP5 Elements in Classes

$
0
0

Hey, I have a project with multiple classes. A class is used for serial communication. How can I use a Controlp5 element (for example, Textlabel) in this Klassse to get around this output?

if (portId == null) { System.out.println("Could not find COM port."); return; } Regards Willi

create box around line

$
0
0

Hello! I need your help!

i have a perlin noise particle funktion, where every particle connects with their nearest neighbour. the connection, which is currently a line, should be a box, to have it as a volume. it would be awesome if you guys can help me!!!! //line from one vector to his nearest neighbor line(pos.x, pos.y , pos.z, npos.x, npos.y, npos.z);

    import peasy.test.*;
    import peasy.org.apache.commons.math.*;
    import peasy.*;
    import peasy.org.apache.commons.math.geometry.*;


    float depth = 500;
    PVector[] nOffset;
    float nScale = 0.01;
    float stepSize = 3;

    ArrayList<Particle> particles;
    ArrayList<Connection> cn=new ArrayList<Connection>();

     PeasyCam cam;

    void setup(){
      size(1500,1000, P3D);
      frameRate(25);
        cam=new PeasyCam(this, 300);


      nOffset = new PVector[3];
      for(int i = 0; i < 3; i++){
        nOffset[i] = new PVector(random(1), random(10000), random(10000));
      }
      particles = new ArrayList<Particle>();
      for(int i = 0; i <300; i++){
        particles.add(new Particle());
      }

      noFill();
      background(0);
    }

    void draw(){

      background(0);
      stroke(255);
      for(Particle p: particles){p.update();}
      for (Connection c : cn) c.display();
      stroke(255);
      translate(750,700,200);
      box(1500,1500,400);


     if (frameCount%10==0)for (Particle p : particles)p.connect();
    }

     class Particle {

      PVector pos;

      Particle() {
        pos = new PVector(random(1500), random(1500), random(400));
      }

      void update() {
        float x = pos.x + map(noise(nOffset[0].x + pos.x * nScale, nOffset[0].y + pos.y * nScale, nOffset[0].z + pos.z * nScale), 0, 1, -stepSize, stepSize);
        float y = pos.y + map(noise(nOffset[1].x + pos.x * nScale, nOffset[1].y + pos.y * nScale, nOffset[1].z + pos.z * nScale), 0, 1, -stepSize, stepSize);
        float z = pos.z + map(noise(nOffset[2].x + pos.x * nScale, nOffset[2].y + pos.y * nScale, nOffset[2].z + pos.z * nScale), 0, 1, -stepSize, stepSize);
        PVector npos = new PVector(x, y, z);
        pushMatrix();
        //translate(0, 0, 0);
        //line(pos.x, pos.y , pos.z, npos.x, npos.y, npos.z);
        popMatrix();
        if ((0 <= npos.x && npos.x <1500 && 0 <= npos.y && npos.y <1500 && 0 <= npos.z && npos.z < 400) &&
          (random(1) < 0.995)) {
          pos = npos;
        } else {
          pos = new PVector(random(1500), random(1500), random(400));
        }
      }


      void connect() {

        for (Particle p : particles) {


          if (p.pos.dist(pos)<150&&p!=this)cn.add(new Connection(p.pos, this.pos));//check for any particles closer than 200, if there are any add a new Connection by providing two positions
        }
      }
    }

    class Connection {// this class describes the connections between particles, "connect" function inside of the "Particle" class creates new Connection objects

      PVector pos, npos;//a connection needs a beginning and end vector

      Connection(PVector p1, PVector p2) {// in order to create a connection, we need to provide two vectors... check "connect" function inside of the "Particle" class
        pos=p1.get();
        npos=p2.get();
      }

      void display() {
        stroke(255, 100);
        strokeWeight(0.3);

        line(pos.x, pos.y , pos.z, npos.x, npos.y, npos.z);   //line from one vector to his nearest neighbor


      }
    }
Viewing all 2896 articles
Browse latest View live