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

Processing3 video libray and P3D mode

$
0
0

In Processing 3, the video stream freezes at the first frame while the sketch continues to play on top of the frozen video background. For example with the Video/Capture/BrightnessTracking example, if I change size(640, 480); to size(640, 480,P3D);

It is working with Processing 2, now I am using Processing 3.1.1 on Windows10 Am I alone with this problem or is this a known bug?


Automatically zoom out using mouseWheel and PeasyCam?

$
0
0

Hello,

I have a P3D (3 dimensional) sketch that I've written and need help in automating or possibly dynamically changing the zoom out speed/rate. I have imported the PeasyCam library mrfeinberg.com/peasycam/ , which for the life of me I can not understand the reference.

Processing also inherently has the mouseWheel function.

My code is below, thanks for any suggestions and help in advance.

`import peasy.*; PeasyCam cam;

Line[] lines; Line[] lines2; Line[] lines3; Line[] lines4;

PVector start_pos, start_pos2, start_pos3, start_pos4; PVector end_pos, end_pos2, end_pos3, end_pos4;

void setup(){ size(displayWidth,displayHeight,P3D); cam = new PeasyCam(this, 0,0,0,100); cam.lookAt(0,0,0); //cam.setRollRotationMode(); cam.setSuppressRollRotationMode(); cam.setWheelScale(.1);

                                  //camera(0,0,0, 0,0,0,  0, 1, 0);

start_pos = new PVector(0, 0, 0); end_pos = new PVector(0, 0, 0);

start_pos2 = new PVector(0, 0, 0); end_pos2 = new PVector(0, 0, 0);

start_pos3 = new PVector(0, 0, 0); end_pos3 = new PVector(0, 0, 0);

start_pos4 = new PVector(0, 0, 0); end_pos4 = new PVector(0, 0, 0);

lines = new Line[1000]; lines2 = new Line[1000]; lines3= new Line[1000]; lines4= new Line[1000];

for(int i = 0; i < lines.length; i++){ lines[i] = new Line(start_pos, end_pos, color(random(0, 255), random(0, 255), random(0, 255)) ); start_pos = end_pos.copy(); end_pos.x = random(-100, 100); end_pos.y = random(-100, 100); end_pos.z += 100; }

for(int i = 0; i < lines2.length; i++){ lines2[i] = new Line(start_pos2, end_pos2, color(random(0, 255), random(0, 255), random(0, 255)) ); start_pos2 = end_pos2.copy(); end_pos2.x = random(-100, 100); end_pos2.y = random(-100, 100); end_pos2.z += 100; }

for(int i = 0; i < lines3.length; i++){ lines3[i] = new Line(start_pos3, end_pos3, color(random(0, 255), random(0, 255), random(0, 255)) ); start_pos3 = end_pos3.copy(); end_pos3.x = random(-100, 100); end_pos3.y = random(-100, 100); end_pos3.z += 100; }

for(int i = 0; i < lines4.length; i++){ lines4[i] = new Line(start_pos4, end_pos4, color(random(0, 255), random(0, 255), random(0, 255)) ); start_pos4 = end_pos4.copy(); end_pos4.x = random(-100, 100); end_pos4.y = random(-100, 100); end_pos4.z += random(50,250); } }
void draw(){ //rotateY(-1000); //rotateX(-1000); background(0, 127);

for(int i = 0; i < lines.length; i++){ lines[i].display(); }

for(int i = 0; i < lines2.length; i++){ lines2[i].display(); }

for(int i = 0; i < lines3.length; i++){ lines3[i].display(); }

}

class Line{ color col; PVector pos1; PVector pos2;

Line(PVector p1, PVector p2, color c){ pos1 = p1.copy(); pos2 = p2.copy(); col = c; }

void display(){ stroke(col); strokeWeight(3); line(pos1.x, pos1.y, pos1.z, pos2.x, pos2.y, pos2.z); } }`

rotation function with 4 arguments..??

$
0
0

Hi Everyone !

I am working on a project (I would love to share with u all) that involves visualizing data received from gyro sensor using arduino. I got the basic code which uses toxiclibs library to convert the quaternion values (recieved through calculation in arduino) of the rotation to 4 values- Rotation angle in radians and rotation axis x,y,z (as described in the toxiclibs documentation).

And then uses rotate function with the 4 values as argument to rotate. which works!! Here is the part of code I am talking about -
float[] axis = quat.toAxisAngle(); rotate(axis[0], -axis[1], axis[3], axis[2]);

My question is how does this kind of rotation function exactly works?? There is no description about this kind of rotate function even in Processing refernce. Also more importantly I need to track the new coordinates of rotated object after rotation.

I am stuck here.. tried a couple of ideas. Didn't worked out. Need some inspiration from you guys.

Thanks !

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.

Visualize WAV data

$
0
0

I basically need to be able to load the entirety of a wav file into an array in memory. Maybe I'm missing it, but is there any libs that could help with this? Or do i need to dig into wav file structure and do it the old fashion way?

Get id while hovering in scrollable list

$
0
0

Is there a way of getting the individual id of scrollable list in controlP5 while hovering? In the sketch below you get the id by clicking. Possible to get it by hovering?

import controlP5.*;
import java.util.*;

//String info;

ControlP5 cp5;

void setup() {
  size(400, 400);
  cp5 = new ControlP5(this);
  List l = Arrays.asList("a", "b", "c", "d", "e", "f", "g", "h");
  cp5.addScrollableList("dropdown")
    .setPosition(100, 100)
    .setSize(200, 100)
    .setBarHeight(20)
    .setItemHeight(20)
    .addItems(l)
    .setType(ScrollableList.LIST) // currently supported DROPDOWN and LIST
    .onMove(new CallbackListener() {
    public void controlEvent(CallbackEvent theEvent) {
      float value = theEvent.getController().getValue();
      println("the value is " + value);
    }
  }
  );
}

void draw() {
  background(240);
  // HOVER
  boolean over = cp5.get(ScrollableList.class, "dropdown").isMouseOver();
  // println("OVER " + over);
}

void dropdown(int n) {
  println("id:" + n);
}

It's possible to reproduce just one time a GIF in Processing?

$
0
0

I want to know if there is a possibility to reproduce a gif for only one time when you run your code. :-/

Save textArea with ControlP5

$
0
0

Hello guys,

How could I save the contents of a textArea in a text file?

It worked to open normal as the example in the link below, but still managed to save not ... tried this code, but it gives error, the syntax is wrong ...

https://forum.processing.org/one/topic/textarea-using-controlp5.html

stretch code:

//String[] lines = loadStrings(textArea.getText());
//printArray(lines);

String lines = textArea.getText()
println(lines);

for (int i = 0; i <= lines.length-1; i++){
   lineSave[i] = lines[i];
}

saveStrings(split(lineSave, "\n"));

Thanks in advance for your attention.


Issues with web-camera and size

$
0
0

Hi, mates. I am kinda really new in Processing, but some things I already know and try to use it. Recently found an example of changing brightness of camera's pixels (it's like a flashlight). The code works, all fine and nice. But when I try to change the size of window(not camera), it ruins evething (photo). And don't know what to do. And one more thing what i saw. First we load all pixels, then cam.pixels. And in (loop in loop) we work with camera's pixels, but when we update Pixels, we update all pixels, not only from camera. And when i try to write cam.pixels[loc] = c; or cam.updatePixels(); it doesn't work, just gray screen. Could you help me or if know( i didn't found) links with similar problems. Thanks in advance.

    import processing.video.*;

    // Step 2. Declare a Capture object
    Capture video;

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

    video = new Capture(this, 320, 240,30);
      video.start();
    }

    // An event for when a new frame is available
    void captureEvent(Capture video) {
      // Step 4. Read the image from the camera.
      video.read();
    }
    void draw() {

      loadPixels();
      video.loadPixels();

      for (int x = 0; x < video.width; x++) {
        for (int y = 0; y < video.height; y++) {

          // Calculate the 1D location from a 2D grid
          int loc = x + y*video.width;

          // Get the R,G,B values from image
          float r, g, b;
          r = red  (video.pixels[loc]);
          g = green(video.pixels[loc]);
          b = blue (video.pixels[loc]);

          // Calculate an amount to change brightness based on proximity to the mouse
          float d = dist(x, y, mouseX, mouseY);
          float adjustbrightness = map(d, 0, 100, 4, 0);
          r *= adjustbrightness;
          g *= adjustbrightness;
          b *= adjustbrightness;

          // Constrain RGB to make sure they are within 0-255 color range
          r = constrain(r, 0, 255);
          g = constrain(g, 0, 255);
          b = constrain(b, 0, 255);

          // Make a new color and set pixel in the window
          color c = color(r, g, b);
        pixels[loc] = c;
        }
      } updatePixels();
       }

G4P: GTextField slow input

$
0
0

Hello! I'm having some performance issues with GTextField while using larger font size. While entering text in GTextField that goes past the edge of the field, the input dramatically slows down.

I'm experiencing this on Windows 7 64, Processing 3.1.1 and G4P 4.0.4. Do others experience this as well?

If it is general issue, I have few more observations. Curiously the field is fast when deleting characters with backspace. ControlP5 is also fast, but it doesn't have other features like copy/pasting.

Thank you!

import g4p_controls.*;
import java.awt.Font;

GTextField txf1;
int fontSize = 80;

void setup() {
  size(800, 600);

  txf1 = new GTextField(this, 100, 250, 600, 100);
  txf1.setFont(new Font("Arial", Font.PLAIN, fontSize));
}

void draw() {
  background(125);
}

Pixel detection boxes for Roullette Game

$
0
0

Hello everyone, for a school project my teachers had a cool project for me in mind. Making a cheating roullette table with the help of processing. I told them I am not very good at Processing, but they said that it was pretty easy to do. Now I am 6 weeks further and the help of my teachers is gone. I have to do it on my own now and I can't seem to improve on my work anymore. I'm stuck and it is hard as balls for me. So is there anyone here on the forums who can help me out as soon as possible?

The code makes a picture from my webcam and checks the picture for blobs. Then he colors the blobs with a size higher than 200 pixels and puts a rectangle box around it. Right now I need to check the middle of a rectangle box if it is in another box, like is it x > 400 x < 450 y > 60 y < 100 etc. This is to check if the casino tokens are on a number or not. If yes, then exclude a video from playing and if no, put the video in a random playlist. So I want if a token is on 1, i dont want the video wich rolls a 1 to be played. Also if there are tokens on 4 and 17, exclude those from the possibility to play. I don't know how to go further and I'm desperate.

Thank you in advance.

import processing.video.*;

PImage img;
ArrayList<Integer> blackPixels = new ArrayList<Integer>();
Capture cam;

void setup() {
  size(1280,960);
  String[] cameras = Capture.list();
  if (cameras.length == 0) {
    println("There are no cameras available for capture.");
    exit();
  } else {
    println("Available cameras:");
    for (int i = 0; i < cameras.length; i++) {
      println(cameras[i]);
    }

    cam = new Capture(this, cameras[1]);
    cam.start();
  }
}

void draw(){
    if (cam.available() == true) {
    cam.read();
    image(cam, 0, 0);
    println("DrawFunction");
  }
}


void mousePressed(){
  cam.stop();
    saveFrame("check.jpg");
  readPixels();

  //imageCheck();
}

void imageCheck(){
   img = loadImage("check.jpg");
   image(img,0,0);
     println("imageCheck");
   readPixels();
  }


void readPixels()
{
  println("readPixels");
  loadPixels();
  for (int i = 0; i < pixels.length; i++)
  {
    if( blue(pixels[i]) > 150 && red(pixels[i]) > 200 && green(pixels[i]) > 200)
    {
      pixels[i] = color(0,0,0);
      blackPixels.add(1);
    }
    else
    {
      pixels[i] = color(255,255,255);
      blackPixels.add(0);
    }
  }
  updatePixels();
  findFirstPixel();
}


void findFirstPixel()
{
  println("findFirstPixel");
  for (int i = 0; i < blackPixels.size(); i++)
  {
    if(blackPixels.get(i) == 1)
    {
      findPixels( i );
      break;
    }
  }
}

void findPixels( int pixelNumber )
{
  ArrayList<Integer> blob = new ArrayList<Integer>();
  checkSurroundingPixels( pixelNumber , blob );

  println(blob.size());
  if( blob.size() > 200 )
  {
    calculateBoundingBox(blob);
    calculateNumber(blob);
    paintBlob(blob, color(255,0,0) );
  }
  else
  {
    paintBlob(blob, color(255,0,255) );
  }
}

void checkSurroundingPixels( int pixelNumber, ArrayList<Integer> blob )
{
  blob.add( pixelNumber );
  int i = 0;
  while( i < blob.size() )
  {
    pixelNumber = blob.get(i);

    int topleft = pixelNumber - width - 1;
    int topmiddle = pixelNumber - width;
    int topright = pixelNumber - width + 1;
    int left = pixelNumber - 1;
    int right = pixelNumber + 1;
    int bottomleft = pixelNumber + width - 1;
    int bottommiddle = pixelNumber + width;
    int bottomright = pixelNumber + width + 1;

    if( !blob.contains( topleft ) )
    {

      if( topleft >= 0 && blackPixels.get(topleft) == 1)
      {
        blob.add( topleft );
      }
    }

    if( !blob.contains( topmiddle ) )
    {
      if(topmiddle >= 0 && blackPixels.get(topmiddle) == 1)
      {
        blob.add( topmiddle );
      }
    }

    if( !blob.contains( topright ) )
    {
      if( topright >= 0 && blackPixels.get(topright) == 1 )
      {
        blob.add( topright );
      }
    }

    if( !blob.contains( left ) )
    {
      if( left >= 0 && blackPixels.get(left) == 1 )
      {
        blob.add( left );
      }
    }

    if( !blob.contains( right ) )
    {
      if( right <= (width * height) - 1 && blackPixels.get(right) == 1)
      {
        blob.add( right );
      }
    }

    if( !blob.contains( bottomleft ) )
    {
      if( bottomleft <= (width * height) - 1 && blackPixels.get(bottomleft) == 1)
      {
        blob.add( bottomleft );
      }
    }

    if( !blob.contains( bottommiddle ) )
    {
      if( bottommiddle <= (width * height) -1 && blackPixels.get(bottommiddle) == 1)
      {
        blob.add( bottommiddle );
      }
    }

    if( !blob.contains( bottomright ) )
    {
      if(bottomright <= (width * height) - 1 && blackPixels.get(bottomright) == 1)
      {
        blob.add( bottomright );
      }
    }

    i++;
  }
}

void calculateBoundingBox( ArrayList<Integer> blob )
{
  println("blob found");
  int maxX = 0;
  int minX = width;
  int maxY = 0;
  int minY = height;

  for (int i = 0 ; i < blob.size() ; i++){
    int x = blob.get(i) % 1280;
    int y = ceil(blob.get(i) / 1280);
    if( x > maxX )
    {
      maxX = x;
    }

    if( x < minX )
    {
      minX = x;
    }

    if( y > maxY )
    {
      maxY = y;
    }

    if( y < minY )
    {
      minY = y;
    }
    rect(minX, minY, maxX-minX, maxY-minY);
  }


}

void paintBlob( ArrayList<Integer> blob , color col)
{
  loadPixels();
  for (int i = 0 ; i < blob.size() ; i++)
  {
    pixels[blob.get(i)] = col;
  }
  updatePixels();
  removeBlob( blob );
}

void removeBlob( ArrayList<Integer> blob )
{
  for (int i = 0 ; i < blob.size() ; i++)
  {
    blackPixels.set( blob.get(i), 0);
  }
  findFirstPixel();
}

Problem with Movie Maker

$
0
0

Hi everyone, I'm new in this forum. It's about 5 month that I started to use Processing for my project. I'm working with minim library for the creation of music video. I'm using saveFrame (with frameRate (7) ) and Movie Maker. I already done 4 songs, but now, only with one file, this is the message that appare when I try to start movie maker: "Creating the QuickTime movie failed. len must be divisable by sampleCount len = 373 sampleCount = 3" How can I solve this problem? (I tried to create a new file, new frame, different name, etc. but nothing works.)

Please, help me!

Convert MongoDB 'DBobject' to Json

$
0
0

Hi.
I'm using the MongoDB java driver to pull some data out of a MongoDB collection. I'm having problems converting the resultant DBObject into a processing JSON object. My code looks a little bit like this:

    BasicDBObject query = new BasicDBObject("s__UID","123456789");
        cursor = coll.find(query);

        while(cursor.hasNext())
        {
         println(cursor.hasNext());
         json = getJSONObject(cursor.next());
        }
        cursor.close();

The Println of cursor.hasNext works fine, but getJSONObject (or loadJSONObject) complain because I'm not passing in strings.

Can anyone help?

Processing 3 with P3D embedded in JPanel

$
0
0

In my current project, I need to embed a Processing 3 canvas in my Java Swing application. I could find some good examples for P2D renderer, which worked perfectly fine; however, my application is using P3D renderer for displaying 3D models.

After a thorough search on the Internet and reading the source codes, I could get a solution, which does not work properly.

Here is a baby example of what I have so far followed by the screenshots of my issue (the example uses JFrame for simplicity and conciseness).

public class Visualiser3D extends PApplet {

    private PeasyCam camera;

    @Override
    public void settings() {
        size(1000, 800, P3D);
    }

    @Override
    public void setup() {
        camera = new PeasyCam(this, 0, 0, 0, 1500);
    }

    @Override
    public void draw() {
        camera();        // force default coordsys
        camera.feed();   // manually set peasycam
        background(30);
        sphere(200);    // draw a sphere
    }

    public static void main (String[] args) {
        // prepare JFrame
        JFrame frame = new JFrame("Processing in JFrame");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLayout(new BorderLayout());

        // run Processing
        Visualiser3D mp3d = new Visualiser3D();
        PApplet.runSketch(new String[]{"MyPapplet 3D"}, mp3d);
        PSurfaceJOGL pSurfaceJOGL = (PSurfaceJOGL) mp3d.getSurface();
        pSurfaceJOGL.initOffscreen(mp3d);
        // add canvas to JFrame (used as a Component)
        NewtCanvasAWT canvas = (NewtCanvasAWT) pSurfaceJOGL.getComponent();
        frame.add(canvas, BorderLayout.CENTER);
        pSurfaceJOGL.startThread();

        // display
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}

Here are the screenshots of what I get. The actual processing window keeps running, and if I close it programmatically, the entire application gets closed. I would like to have the Processing canvas embedded inside of my Java Swing application without any other open windows.

JFrame with inserted Processing Canvas Processing Window running

I hope that you will be able to help me do it properly. Thank you very much.

Error from video library in Ubuntu 16.04

$
0
0

Hi there

I'm getting an error when trying to use the video library using Capture in Linux Ubuntu 16.04 in a 64 bits machine. Actually I tried in two different machines with fresh installs and got the same results.

I have searched a lot in the internet for a solution and could not find it.

The error says to "'Run Sketches on Display' preference to display 1" but in the preferences I have this like so: run.display=1 which I think is what it is mentioning.

Setting 'Run Sketches on Display' preference to display 1
UnsatisfiedLinkError: Error looking up function 'gst_date_get_type': /usr/lib/x86_64-linux-gnu/libgstreamer-1.0.so.0.800.0: undefined symbol: gst_date_get_type
A library relies on native code that's not available.
Or only works properly when the sketch is run as a 32-bit application.

I'm really out of ideas. Someone out there know what I have to do or have a direction to point me?
It will be much appreciated.

best regards,
Gil


Translate Áudio file

$
0
0

Preciso traduzir um áudio com uma fala (conversa) para uma frase apresentada.

To translate an audio with a speech ( conversation) for a given phrase .

Trails or Motion blur from webcam

$
0
0

How i can create trails or motion blur from a webcam input ? plz help me with some code example !

if/else questions with control.p5 in Unfolding library

$
0
0

hey guys,

i'm kinda new to the processing scene but wanted to do an interactive map by using the unfolding lib by till nagel. so far, i got this stuff seen in the code below. there's a lot of stuff to fix but the most urgent question is: how can i make markers visible by pressing the button created with control.p5? i looked up in the examples of the p5-lib and found a hint with a booelan, implemented it but it's not working when i set th boolean to true. to make the whole whole sketch working, i set the boolean to false for now. when checking the code please consider setting the boolean to true.

is there somebody out there who could have a glance at this? pretty sure it's a little mistake done by a rookie ;)

my code:

// unfolding libraries

import de.fhpotsdam.unfolding.utils.*; import de.fhpotsdam.unfolding.marker.*; import de.fhpotsdam.unfolding.tiles.*; import de.fhpotsdam.unfolding.interactions.*; import de.fhpotsdam.unfolding.ui.*; import de.fhpotsdam.unfolding.*; import de.fhpotsdam.unfolding.data.*; import de.fhpotsdam.unfolding.providers.*; import java.util.List; import de.fhpotsdam.unfolding.geo.Location;

// controlp5 library

import controlP5.*;

ControlP5 cp5; ColorPicker cp;

// initialize map, set start location

UnfoldingMap map; Location mannheimLocation = new Location(49.4721f, 8.5116f);

List citizenservicesMarker, stadtbezirkeMarker; SimplePointMarker wasserturmMarker, schlossMarker, paradeplatzMarker, ntmMarker, fernmeldeturmMarker, moscheeMarker, luisenparkMarker, technoseumMarker; ;

boolean citizen = true;

public void setup() { size(1100, 900); cp5 = new ControlP5(this);

//cp5-controls

cp5.addToggle("citizen") .setColorActive(color(255, 48, 48)) .setColorForeground(color(125)) .setColorBackground(color(80)) .setPosition(30, 30) .setSize(60, 20) .setColorLabel(0) .setLabelVisible(true);
cp5.addToggle("sights") .setColorActive(color(0, 0, 255)) .setColorForeground(color(125)) .setColorBackground(color(80)) .setPosition(30, 80) .setSize(60, 20) .setColorLabel(0) .setLabelVisible(true);

map = new UnfoldingMap(this, "Mannheim", new StamenMapProvider.TonerBackground()); map.zoomToLevel(13); map.panTo(new Location(mannheimLocation)); map.setZoomRange(9, 15); // prevent zooming too far out MapUtils.createDefaultEventDispatcher(this, map);

// create citizen markers via loading geojosn-file and style them with markerfactory

List citizenservices = GeoJSONReader.loadData(this, "buergerservice.geojson");
MarkerFactory citizenFactory = new MarkerFactory(); citizenFactory.setPointClass(LabeledMarker.class); List citizenservicesMarker = citizenFactory.createMarkers(citizenservices);

// create district markers via loading geojosn-file and style them with markerfactory

List stadtbezirke = GeoJSONReader.loadData(this, "stadtbezirke.geojson"); MarkerFactory stadtbezirkeFactory = new MarkerFactory(); stadtbezirkeFactory.setPolygonClass(SimplePolygonMarker.class); List stadtbezirkeMarker = stadtbezirkeFactory.createMarkers(stadtbezirke); //map.addMarkers(stadtbezirkeMarker);

// question for toggling markers: not working at the moment!

if (citizen==true) { map.addMarkers(citizenservicesMarker); }

// initialize locations and define markers for sights

Location wasserturmLocation = new Location(49.484097, 8.475568); wasserturmMarker = new SimplePointMarker(wasserturmLocation);

Location schlossLocation = new Location(49.482986, 8.461783); schlossMarker = new SimplePointMarker(schlossLocation);

Location paradeplatzLocation = new Location(49.487162, 8.466250); paradeplatzMarker = new SimplePointMarker(paradeplatzLocation);

Location ntmLocation = new Location(49.488344, 8.477535); ntmMarker = new SimplePointMarker(ntmLocation);

Location fernmeldeturmLocation = new Location(49.487067, 8.492178); fernmeldeturmMarker = new SimplePointMarker(fernmeldeturmLocation);

Location moscheeLocation = new Location(49.493919, 8.461333); moscheeMarker = new SimplePointMarker(moscheeLocation);

Location luisenparkLocation = new Location(49.479997, 8.495569); luisenparkMarker = new SimplePointMarker(luisenparkLocation);

Location technoseumLocation = new Location(49.476812, 8.496570); technoseumMarker = new SimplePointMarker(technoseumLocation); }

public void draw() { map.draw();
//cp5-styling

fill(255, 240); rect(20, 20, 150, 140);
// draw sight-markers and set visualize labels

ScreenPosition wasserturmLocation = wasserturmMarker.getScreenPosition(map); fill(255, 255, 255); noStroke(); rect(wasserturmLocation.x+6, wasserturmLocation.y-7, 73, 15); fill(0, 0, 255); ellipse(wasserturmLocation.x, wasserturmLocation.y, 10, 10); text("Wasserturm", wasserturmLocation.x + 8, wasserturmLocation.y + 5);

ScreenPosition schlossLocation = schlossMarker.getScreenPosition(map); fill(255, 255, 255); noStroke(); rect(schlossLocation.x+6, schlossLocation.y-7, 47, 15); fill(0, 0, 255); ellipse(schlossLocation.x, schlossLocation.y, 10, 10); text("Schloss", schlossLocation.x + 8, schlossLocation.y + 5);

ScreenPosition paradeplatzLocation = paradeplatzMarker.getScreenPosition(map); fill(255, 255, 255); noStroke(); rect(paradeplatzLocation.x+6, paradeplatzLocation.y-7, 73, 15); fill(0, 0, 255); ellipse(paradeplatzLocation.x, paradeplatzLocation.y, 10, 10); text("Paradeplatz", paradeplatzLocation.x + 8, paradeplatzLocation.y + 5);

ScreenPosition ntmLocation = ntmMarker.getScreenPosition(map); fill(255, 255, 255); noStroke(); rect(ntmLocation.x+6, ntmLocation.y-7, 93, 15); fill(0, 0, 255); ellipse(ntmLocation.x, ntmLocation.y, 10, 10); text("Nationaltheater", ntmLocation.x + 8, ntmLocation.y + 5);

ScreenPosition fernmeldeturmLocation = fernmeldeturmMarker.getScreenPosition(map); fill(255, 255, 255); noStroke(); rect(fernmeldeturmLocation.x+6, fernmeldeturmLocation.y-7, 93, 15); fill(0, 0, 255); ellipse(fernmeldeturmLocation.x, fernmeldeturmLocation.y, 10, 10); text("Fernmeldeturm", fernmeldeturmLocation.x + 8, fernmeldeturmLocation.y + 5);

ScreenPosition moscheeLocation = moscheeMarker.getScreenPosition(map); fill(255, 255, 255); noStroke(); rect(moscheeLocation.x+6, moscheeLocation.y-7, 178, 15); fill(0, 0, 255); ellipse(moscheeLocation.x, moscheeLocation.y, 10, 10); text("Yavuz-Sultan-Selim-Moschee", moscheeLocation.x + 8, moscheeLocation.y + 5);

ScreenPosition luisenparkLocation = luisenparkMarker.getScreenPosition(map); fill(255, 255, 255); noStroke(); rect(luisenparkLocation.x+6, luisenparkLocation.y-7, 68, 15); fill(0, 0, 255); ellipse(luisenparkLocation.x, luisenparkLocation.y, 10, 10); text("Luisenpark", luisenparkLocation.x + 8, luisenparkLocation.y + 5);

ScreenPosition technoseumLocation = technoseumMarker.getScreenPosition(map); fill(255, 255, 255); noStroke(); rect(technoseumLocation.x+6, technoseumLocation.y-7, 70, 15); fill(0, 0, 255); ellipse(technoseumLocation.x, technoseumLocation.y, 10, 10); text("Technoseum", technoseumLocation.x + 8, technoseumLocation.y + 5);

// call the function for highlighting the labels of the citizen-markers

citizen(); }

// function for highlighting the labels of the citizen-markers

void citizen() { // Deselect all marker for (Marker citizenservices : map.getMarkers ()) { citizenservices.setSelected(false); }

// Select hit marker // Note: Use getHitMarkers(x, y) if you want to allow multiple selection. Marker citizenservices = map.getFirstHitMarker(mouseX, mouseY); if (citizenservices != null) { citizenservices.setSelected(true); } }

this piece is used for highlighting the labels of the red markers:

import de.fhpotsdam.unfolding.marker.*; import de.fhpotsdam.unfolding.geo.*; import processing.core.*; import java.util.HashMap;

/** * A point marker which can show a label containing the marker's name. */ public class LabeledMarker extends SimplePointMarker {

protected String name; protected float size = 15; protected int space = 10;

private PFont font; private float fontSize = 12;

public LabeledMarker(Location location, HashMap properties) { this.location = location;

// Use property 'title' as label
Object titleProp = properties.get("title");
if (titleProp != null && titleProp instanceof String) {
  name = (String) titleProp;
}

}

/** * Displays this marker's name in a box. */ public void draw(PGraphics pg, float x, float y) { pg.pushStyle(); pg.pushMatrix(); if (selected) { pg.translate(0, 0); } pg.strokeWeight(strokeWeight); if (selected) { pg.fill(255, 48, 48); pg.stroke(1); } else { pg.fill(255, 48, 48); pg.noStroke(); } pg.ellipse(x, y, size, size);// TODO use radius in km and convert to px

// label
if (selected && name != null) {
  if (font != null) {
    pg.textFont(font);
  }
  pg.fill(255, 255, 255);
  pg.noStroke();
  pg.rect(x + strokeWeight / 2, y - fontSize + strokeWeight / 2 - space, pg.textWidth(name) + space * 1.5f,
  fontSize + space);
  pg.fill(255, 48, 48);
  pg.text(name, Math.round(x + space * 0.75f + strokeWeight / 2),
  Math.round(y + strokeWeight / 2 - space * 0.75f));
}
pg.popMatrix();
pg.popStyle();

}

public String getName() { return name; } }

ControlP5 2dslider limitations

$
0
0

Hi Everyone,

I'm trying to build a custom 2d slider where the sum of the x and y coordinates are less than 20. How can I program this? Here is my current setup for the 2d slider.

cp5 = new ControlP5(this); s = cp5.addSlider2D("wave") .setPosition(30,40) .setSize(100,100) .setMinMax(1,20,20,1) .setValue(1,1) ;

Thank you so much, Jerry

ControlP5 I am misunderstanding something

$
0
0

Hello, I am a rusty programmer.. I was wondering if someone would be kind enough to point out my misunderstanding. I am setting up two windows.. one running a temperature graph and one containing the controls. There are three temp stations. Everything was running along smoothly until I tried using the setOn() or setOff() button functions. I think I am misunderstanding something basic about how the ControlP5 library works.

There is a lot of irrelevant code... I think this should be enough to help me...if you so choose.

        `
        SecondWin sw;

        void settings() {
           size(1100, 850, JAVA2D);
        }

        void setup() {
           sw = new SecondWin(this, 700, 400);  //second Window (Control Panel)
        }
        void draw() {
        }

        public class SecondWin extends PApplet {  // code for window

          int w, h;
          PApplet parent;
          ControlP5 cp5;


            public SecondWin(PApplet _parent, int _w, int _h) {
               super();
               parent = _parent;

               w = _w;
               h = _h;
               PApplet.runSketch(new String[]{this.getClass().getName()}, this);
            }

            public void settings() {
               size(w, h);
            }

            public void setup() {

            cp5 = new ControlP5(this);

              cp5.addButton("VS2")
                            .setImages(icons[0], icons[0], icons[10])
                            .updateSize()
                            .setPosition(10, 10)
                            .setSwitch(true)
                            .setId(50)
                            .plugTo(parent, "VS2");
        }

          public void draw() {
          background(255);
          fill(0);
         }
         public void controlEvent(ControlEvent theEvent) {
              if (theEvent.isController()) {
                  println(((Button)cp5.getController("VS2")).isOn());
       //         ((Button)cp5.getController("VS2")).setOn();       ########## PROBLEM  ######
            }

        }
}
`

As mentioned, I left out a lot of code. I have been fighting this for a few hours...so a lot of this code I have stolen from online sources and Frankenstein'd here.

As is, it runs with no errors and hitting the VS2 button prints out the proper false and true values. When I un-comment the ((Button)cp5.getController("VS2")).setOn(); and then hit the button, I get a stream of multiple 'trues' printed to console and

    java.lang.NoClassDefFoundError: Could not initialize class java.util.logging.LogRecord
at java.util.logging.Logger.log(Logger.java:787)
at java.util.logging.Logger.severe(Logger.java:1463)
at controlP5.ControlBroadcaster.printMethodError(Unknown Source)
at controlP5.ControlBroadcaster.invokeMethod(Unknown Source)
at controlP5.ControlBroadcaster.broadcast(Unknown Source)
at controlP5.Controller.broadcast(Unknown Source)
at controlP5.Button.setValue(Unknown Source)
at controlP5.Button.activate(Unknown Source)
at controlP5.Button.mouseReleased(Unknown Source)
at controlP5.Controller.setMousePressed(Unknown Source)
at controlP5.ControllerGroup.setMousePressed(Unknown Source)
at controlP5.ControlWindow.mouseReleasedEvent(Unknown Source)
at controlP5.ControlWindow.mouseEvent(Unknown Source)
at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at processing.core.PApplet$RegisteredMethods.handle(PApplet.java:1398)
at processing.core.PApplet.handleMethods(PApplet.java:1593)
at processing.core.PApplet.handleMouseEvent(PApplet.java:2680)
at processing.core.PApplet.dequeueEvents(PApplet.java:2603)
at processing.core.PApplet.handleDraw(PApplet.java:2414)
at processing.awt.PSurfaceAWT$12.callDraw(PSurfaceAWT.java:1527)
at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:316)

If it is something really basic I am missing, even throwing me a reference page address would be appreciated.

Thanks!

Viewing all 2896 articles
Browse latest View live