So I have a bit of a special situation here. I have an algorithm that my coworker gave me in Javascript for determining if a point is within a shape. It works fine but he got it from somewhere else and we both are not really sure HOW it works per se, just that it works really well. I converted it into a small Polygon class I wrote for this project I'm working on and was wondering if someone could take a look and and maybe help my mind understand this algorithm? I'll be using it a lot and am uneasy about having something so core to my app be out of my understanding.
class Polygon{
ArrayList<PVector> points;
PVector[] ptArray = new PVector[1];
Polygon(ArrayList<PVector> _points){
points = _points;
ptArray = new PVector[points.size()];
points.toArray(ptArray);
}
void addPoint(PVector pt){
points.add(pt);
ptArray = new PVector[points.size()];
points.toArray(ptArray);
}
PVector[] getPoints(){
return ptArray;
}
void render (){
beginShape();
for(int i = 0; i< ptArray.length; i++){
vertex(ptArray[i].x, ptArray[i].y);
}
endShape(LINES);
}
// convenience function to see if a point is within this polygon
Having an issue with a control Event with control P5. I'm using a radio button and am trying to capture the event specific to that but it seems like I can only capture the event class but access any methods. Heres some of my code :
I'm trying to export an application I built with GSVideo, OpenCV and ControlP5. The App runs just fine in the Processing IDE but when I go to kick out an application, it crashes. Upon checking out the console I realize theres an Unsatisfied Link Error and It cant download the GStreamer Library. The Error looks like this :
10/12/12 7:50:45.920 PM [0x0-0x408408].LaserTestCV_nocapture: starting camera
10/12/12 7:50:46.034 PM [0x0-0x408408].LaserTestCV_nocapture: Exception in thread "Animation Thread" java.lang.UnsatisfiedLinkError: Unable to load library 'gstreamer-0.10': dlopen(libgstreamer-0.10.dylib, 9): image not found
10/12/12 7:50:46.034 PM [0x0-0x408408].LaserTestCV_nocapture:
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:163)
10/12/12 7:50:46.034 PM [0x0-0x408408].LaserTestCV_nocapture:
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:236)
10/12/12 7:50:46.034 PM [0x0-0x408408].LaserTestCV_nocapture:
at com.sun.jna.Library$Handler.<init>(Library.java:140)
10/12/12 7:50:46.034 PM [0x0-0x408408].LaserTestCV_nocapture:
at com.sun.jna.Native.loadLibrary(Native.java:379)
10/12/12 7:50:46.034 PM [0x0-0x408408].LaserTestCV_nocapture:
at org.gstreamer.lowlevel.GNative.loadNativeLibrary(GNative.java:48)
10/12/12 7:50:46.034 PM [0x0-0x408408].LaserTestCV_nocapture:
at org.gstreamer.lowlevel.GNative.loadLibrary(GNative.java:45)
10/12/12 7:50:46.034 PM [0x0-0x408408].LaserTestCV_nocapture:
at org.gstreamer.lowlevel.GstNative.load(GstNative.java:42)
10/12/12 7:50:46.034 PM [0x0-0x408408].LaserTestCV_nocapture:
at org.gstreamer.lowlevel.GstNative.load(GstNative.java:39)
10/12/12 7:50:46.035 PM [0x0-0x408408].LaserTestCV_nocapture:
at org.gstreamer.Gst.<clinit>(Gst.java:97)
10/12/12 7:50:46.035 PM [0x0-0x408408].LaserTestCV_nocapture:
at codeanticode.gsvideo.GSVideo.initImpl(Unknown Source)
10/12/12 7:50:46.035 PM [0x0-0x408408].LaserTestCV_nocapture:
at codeanticode.gsvideo.GSVideo.init(Unknown Source)
10/12/12 7:50:46.035 PM [0x0-0x408408].LaserTestCV_nocapture:
at codeanticode.gsvideo.GSCapture.initGStreamer(Unknown Source)
10/12/12 7:50:46.035 PM [0x0-0x408408].LaserTestCV_nocapture:
at codeanticode.gsvideo.GSCapture.<init>(Unknown Source)
10/12/12 7:50:46.035 PM [0x0-0x408408].LaserTestCV_nocapture:
at LaserTestCV_nocapture.setup(LaserTestCV_nocapture.java:94)
10/12/12 7:50:46.035 PM [0x0-0x408408].LaserTestCV_nocapture:
at processing.core.PApplet.handleDraw(PApplet.java:1608)
10/12/12 7:50:46.035 PM [0x0-0x408408].LaserTestCV_nocapture:
at processing.core.PApplet.run(PApplet.java:1530)
10/12/12 7:50:46.035 PM [0x0-0x408408].LaserTestCV_nocapture:
at java.lang.Thread.run(Thread.java:680)
Now my question is, how is it that the IDE can run this? I see the Library in the processing libraries section but what file system must I have in my app to make the image be found? Any help would be awesome!
Thanks
K
EDIT :
I found the solution I ended up just having to copy the GStreamer library files into the Contents/Resources/Java directory in the package contents. Works for me.
I recently asked a question trying to figure out how to get fullscreen using proclipsing in eclipse. The solution I got totally works, except when I try to use the PApplet.OPENGL as a renderer.
Anyone know how to set up a full screen app in Eclipse and the Proclipsing plugin? whenever I export with
size(screenWidth, screenHeight);
i get an error in the export process that says that the size function requires numerical values and not variables.
Not sure if this a plugin problem or if the processing IDE just does some background magic for you that I'm not aware of. any help on this would be awesome!
Hey all
I'm working on a project that will be hooked up to an arduino. The problem is the arduino part of the installation is supposed be at the location all day collecting data, and in the evening we'd come in and hook up the processing projection with the data that has been collected to date.
The problem is whenever I connect the arduino to processing, or turn on the serial monitor from the arduino, the whole program resets itself and whatever data that has been collected is lost. Any Ideas on how to get by this? I'm using an arduino uno thats pretty bare. No shields or libraries just the code for counting.
Hey all I'm having a weird issue with a project I built in Eclipse with the Proclipsing plugin. In eclipse, everything works fine, it runs as an applet or as an application no problems but whenever i go to export the application it seems like, for mac osx at least, it doesnt export the data folder along with. So my application crashes when it tries to load anything I'm not sure if i have the file paths wrong somehow even though they work in the Eclipse IDE.
File Structure in Eclipse:
Project Folder
.git
.idea
.settings
bin
lib
src
bicyclecounter
data
out
text
visuals
.classpath
.DS_Store
.project
BicicleCounter.iml
preferences.txt
README
but when i export this is what i get
Application.macosx
Bicyclecounter.app
contents
info.plist
macOS
pkgInfo
resources
java
BicycleCounter.jar
source
bicyclecounter
out
text
visuals
It seems like the data folder itself is missing from the export. Idk if it gets all merged in with the jar file but my program keeps crashing when its trying to load a font which is the first time i access that data folder.
In the eclipse IDE i just use the filename of the file i want without the any path to it for example loadFont("Vag-Rounded-Black.vlw"); That works fine in the IDE but i dont know if the file structure changes and requires me to do something different in Eclipse.
Hey All
I'm working on a project and the one I'm working with has asked me to make an image move along a drawn path. Both the image and the path are made in illustrator so I can use them as png images or as svg shapes in processing. The path is a series of curves that arent really in an sort of pattern. I'm wondering if there is a way of moving the image along this path that would be simpler than breaking the path down to the specific curves and treating each curve with its own math equation for animating the stitching all that back together. Is there away to get the points out of the svg path and move to those?
Or is there an entirely different path i should look into for this?
Hey all,
I'm using toxic libs, after a brief introduction and then a hiatus from the library, to set up a really simple verlet physics system. right now I just want particles that fall down and bounce around if the hit each other or if they. I will be adding more later. I'm working in eclipse and am pretty sure I got all the libraries in as there are no errors with those.
The problem I am having though is that nothing moves. I have a class that extends VerletParticle2D, which is a super class to 3 other subclasses that will all essentially draw different shapes/images at their x and y positions. Whenever I instantiate an instance of my super class it draws the proper shape at the initial position but doesnt move. the physics.particles collection shows it as stagnant almost as if nothing is affecting it. I'm not sure whats going on here any help would be appreciated. Heres some sample code of what i have so far:
package bicyclecounter;
import java.io.File;
import java.util.ArrayList;
import processing.core.*;
import toxi.geom.*;
import toxi.physics2d.*;
import toxi.physics2d.behaviors.*;
import visuals.*;
import text.*;
import out.*;
public class BicycleCounter extends PApplet {
public static final long serialVersionUID = 294872387429L;
public static final int[] screenRes = {800, 600};
ArrayList<DataObject> dataObjs = new ArrayList<DataObject>();
VerletPhysics2D physics;
public void setup() {
size(screenRes[0], screenRes[1]);
background(0);
frameRate(30);
smooth();
//create a new physics object to govern our world of motion
setUpPhysicsWorld();
}
public void setUpPhysicsWorld(){
physics = new VerletPhysics2D();
physics.setDrag(.05f);
physics.setWorldBounds(new Rect(0,0, screenRes[0], screenRes[1]));//pass in a toxic libs geom rectangle for the world bounds
Hey all I'm trying to get set up with processing in android mode. I have processing 2.0 alpha 5. the code I have is pretty simple
void setup(){
size(screenWidth, screenHeight, P2D);
background(0);
frameRate(15);
}
void draw(){
println(mouseX);
}
But when I run it...
Exception in thread "Thread-35" java.lang.NullPointerException
at processing.mode.android.AndroidBuild.writeLocalProps(AndroidBuild.java:547)
at processing.mode.android.AndroidBuild.createProject(AndroidBuild.java:135)
at processing.mode.android.AndroidBuild.build(AndroidBuild.java:71)
at processing.mode.android.AndroidMode.handleRunEmulator(AndroidMode.java:147)
at processing.mode.android.AndroidEditor$13.run(AndroidEditor.java:344)
I cant imagine my code is breaking it or causing a nullpointer so I'm wondering if i'm missing a component in the libraries or if they are in the wrong spot.
I'm pretty sure I got all the parts of the sdk that the processing wiki said. Is there something I'm missing
Is there a limit to println calls that can be done to the console? Or will processing just keep going forever until you run out of ram?
I'm trying to debug a problem without being really able to see the code or the error and the only thing i can think of that could be a problem is that the sketch was println every minute or so and its been going for about 12 hrs now.
Hey all,
I'm building a small app that mixes the colors of the pixels of 2 pictures to create a new image. The idea is simple, a read pixel overlayed on a blue pixel should return a purple pixel. I have it running and blending using the PImage.blend() method but it doesnt seem to mix the colors that way. I've tried all the blend mode options. Is there a trick I'm missing or should i be looking into a more complex color mixing algorithm for this project? The Images are taken from the camera. on interaction a current frame is taken and blended with a previous saved image.
Heres what i have running so far:
import processing.video.*;
Capture cam;
boolean interaction = false; // has there been interaction
Hey I'm building an app in processing that is currently utilizing the minim library to play some sounds. There's a list of sounds and they loop 1 after the other. the looping and playing work just fine what I have a question about is finding a good method of knowing the song is done. currently I have it setup to check the length() of the AudioPlayer - the position() of the AudioPlayer, thinking if length - position == 0, we are done.
Well that doesnt quite work, it seems the songs have a varying amount of time on the ends that are not played. IE length() - position will decrease until it hits like 265 and not go down anymore as the song is done. This number varies from 265 all in to the 500s as I have seen.
Does Minim allow or have an event somewhere that is fired when a song is done playing?
Hey all, I'm working on some basic sketches with processing communication with arduino for a workshop class and I'm running into a weird issue. The serial library connection is VERY VERY SLOOOOOOOOOOWWW. I'm not sure whats going on but there is a huge lag between processing and the arduino over the serial library. I thought it was my code so i took everything out except for reading and writing (println commands, conditionals, etc) and it was still running very slow.
I tried using the SimpleWrite example that comes with the processing libraries and that was super slow as well. I'm not sure whats going on.
I switched the Arduino library which uses the same serial library and everything seems to be running fine again.
I used the serial library with arduino and processing for my senior project from college 3 months ago in december and it worked fine. The only difference in my setups is that I am running Mac OSX 10.7 (lion) now as opposed to snow leopard 10.6 back then. Can anyone shed any light on why this is being so slow? If you need a code sample to test with, just use the processing example 'SimpleWrite' because thats what I was using.
Hey all I'm trying to create an xml file of mouse points on keypressed. I've got the xml writing and printing out the root element properly in processing but it's not properly writing to a file it only writes the first point in the file. What am I missing. Any ideas on what might be missing? I havent dealt with writing xml files in processing in a while so it may be something simple and stupid i'm missing.
heres the code I was working with. I'm working in Eclipse btw:
package writetofile;
import processing.core.*;
import processing.xml.*;
import java.io.PrintWriter;
publicclassWriteToFileextendsPApplet {
staticfinallongserialVersionUID=289273923L;
PrintWriterpw;
XMLElementroot=newXMLElement("points");
publicvoidsetup() {
pw=createWriter("data/text.xml");
}
publicvoiddraw() {
if(keyPressed){
//writeLine(new PVector(mouseX, mouseY));
}
}
publicvoidwriteLine(PVectorpt){
XMLElement xml =newXMLElement("pt");
xml.setFloat("x",pt.x);
xml.setFloat("y",pt.y);
root.addChild(xml);
root.write(pw);//where the problem is. Its only writing the first child element of pt in to the file.
pw.flush();
pw.close();
println(root);;// this prints out the whole root element with all the children that have been added thus far
Hey
So, working in eclipse, I created a video player within a class that is a little ways down in terms of classes from the main class. The class structure for it is as follows : Main class > contentplayer class > to mediaPlayer superclass > video player and sound player classes that both extend the mediaPlayer super class.
The problem I'm having is that when I load in a new video file, I can't seem to access the available() method. It always comes through as false even when the sound is playing. Taking that out allows me to play the video and the sound but they are out of sync. Can anyone think of away I can get the available method to turn out true? I cant use the movieEvent method of the Movie Class in the Processing video library because the main class as it is now doesn't have access to the Movie Object in the video player. here's some sample code to try to explain what I mean
// user uploads a file here all that works and it hits this method with the file name string in video player
public void loadMedia(String fileName){ currentFileName = fileName; ScreenManager.setScreenType(2); mainMovie = new Movie(p, currentFileName); mainMovie.pause(); if(mainMovie.width > 1){ PApplet.println("ready to play");// this doesnt print out so i dont even know if this is doing anything mainMovie.play(); } }
//this method is called from the draw() of the main through the content player to this video player class
Hey all
I'm working on a simple media player that takes in a directory or a file and plays it (obviously!). I'm having some issues with the selectInput and selectFolder methods. They seem to crash the whole app. What happens is that it runs once and when I closeout of it by selecting a file or canceling it causes a block of the app. is there a bug here or a better way of doing this that I don't know about? Or should i just go down the regular java path and dip out of processing for this?
Heres some code (its not all of it but this generally what happens):
String loadFile;
void setup(){
}
void draw(){
}
void mousePressed(){
loadFile = selectInput();
handleSelected();
}
void handleSelected(){
if(loadFile == null){
println("no file selected");
}
else{
println(loadFile);
}
}
is there anything else I should be adding here? Thanks in advance
Hello all I'm trying to create a "wall of text" in processing and I have come to a bit of a problem. I'm not sure what the best method is for knowing exactly how many I can have in my string that will basically take up exactly one half of the screen. The idea is to populate this string with that many characters and continue to replace characters in that string. I'm wondering if the text() functions width parameter automatically adds in \n characters or if there is a better way of addressing this problem.
Any help/advice is appreciated.
Thanks!
EDIT:
I have found a method of doing this after banging my head against a few walls. I created my own version of the width parameter in the text() method. I created a variable to only monitor the text of a single line instead of the whole string. This is the keyPressed code with the magic happening.
void keyPressed() {
if (keyCode >=32 && keyCode <=126) {
s.append(key);
stringLength += textWidth(key);// stringLength will append textwidths of the keys pressed per line of text
if (stringLength >= (width/2)) {
// if the length of this variable is longer than the desired witdh(in my case half the screen width)
s.append("\n");//append a new line
stringLength -= width/2;// subtract the desired with from the var (ie resetting it to the new line)
if(stringLength <0)stringLength = 0;// if you are in a situation where you need a buffer/padding (ex the //if statement is like if(stringLength >=(width/2) -5) for 5 px padding on the right side, this will just restart u //at the 0 marker instead of at a negativ number