Loading...
Logo
Processing Forum
niteshade's Profile
10 Posts
54 Responses
0 Followers

Activity Trend

Last 30 days
Show:
Private Message
    Hi there,

    1. PShape map = loadShape("map.svg");
    2. PShape shape = map.getChild("id");

    How can I retrieve the X and Y coordinates of shape at runtime (without a library)?

    I'm sure I could determine the X and Y coordinates with access to the points of the shape.  How might a guy go about pulling these points from a PShape?

    Thanks very much!

    I'm building a fairly complex application in Java, with JBox2D (actually, PBox2D, a wrapper for Processing). One component of this Java application is in Processing (PApplet), containing a JBox2D world. This is so I can use the excellent Processing drawing functions later in the life of the project.

    When the applet gets resized, however, objects in the world do not respect the world boundaries, or the boundaries drift. Please see this video:

    http://www.youtube.com/watch?v=z4p3olwNDPU

    The boxes are where the boundaries should be... they are what is drawn in Processing. However, PBox does not maintain the same locations for its boundaries... for some reason, when the applet window changes sizes, the PBox world shifts to stick to the bottom of the window, while the Processing objects do not. Maddeningly, if I make the window bigger along the X axis, the PBox elements retain their original (correct) locations.

    All of the Processing code seems functional and predictable. I cannot isolate the position changes for PBox... I'm at a loss as to what causes this, and how to fix it. My hunch is that it involves the PBox ground body, but that could be wrong.

    This applet will be embedded in a Swing GUI in the future, and it misbehaves there too.

    Thanks... any help is welcome.

    Hi there,

    I'm having a bit of trouble using Java Swing, Eclipse, and two PApplets in Swing JFrames.  Wondering if anybody can help me out... I've attached some pseudocode below that I think covers all the bases.

    Basically, via its constructor, the second class PApplet Bar receives a copy of the first class PApplet Foo.  The code compiles fine, all imports work OK, the JFrames render correctly, and Eclipse doesn't complain.

    Bar can see Foo; the first println statement in Bar's draw() matches the corresponding println in Foo's draw(); both have the same output.  The getNumber() method works perfectly in Foo.  However, when Bar attempts to access foo.getNumber(), Eclipse throws a null pointer exception.

    All methods are public.  I've tried accessing static variables and loads of other stuff, but nothing seems to get Bar to see inside Foo.

    Thanks, I'd appreciate any help or ideas.  I'm at my wits end, and have tried everything I can think of.

    ---

    1. import javax.swing.*;
    2. import processing.core.*;
    3. ...

    4. public class Application extends JFrame {
    5. ...
    6. public static void main(String[] args) {
    7. EventQueue.invokeLater(new Runnable() {
    8. public void run() {
    9.  Application frame = new Application();
    10.  ...
    11. }
    12. })
    13. }
    14. public Application() {
    15.  ...
    16.    Foo foo = new Foo();
    17.    Bar bar = new Bar(foo);

    18.     JPanel canvas1 = new JPanel();
    19.     foo.init();
    20.     canvas1.add(foo, "");

    21.     JPanel canvas2 = new JPanel();
    22.     bar.init();
    23.     canvas2.add(bar, "");
    24. }
    25. }


    26. // new class file
    27. import processing.core.*;

    28. public class Foo extends PApplet {
    29.   public static int number = 10;
    30.   public int getNumber() {
    31.     return number;
    32.   }
    33.   
    34.   public void setup() {
    35.   }
    36.   public void draw() {
    37.     println(this);
    38.     println(getNumber());
    39.   }
    40. }


    41. // new class file
    42. import processing.core.*;
    43. import Foo;

    44. public class Bar extends PApplet {
    45.   public Bar(PApplet foo_) {
    46.     foo = foo_;
    47.   }
    48.   PApplet foo;
    49.   
    50.   public void setup() {
    51.     ...
    52.   }
    53.   public void draw() {
    54.     println(foo);
    55.     println(foo.getNumber());
    56.   }
    57. }

    I am writing a pretty complex sketch, which has grown to thousands of lines of code.  To keep me from going insane, I have split my code among a number of files.

    Is it possible to group pde files in subdirectories?  Perhaps with import statements of some sort?
    When using the Fisica library, in particular via SVGs from Geomerative, I've been having two problems I have not been able to surmount.

    The first that shapes often stick together when in a world.  The Fisica library (or the JBox2D library under it) provides mechanisms to keep shapes from overlapping, but sometimes it fails, and shapes will not separate.  This is readily apparent when using the Fisica WingedStar example.

    I've tried a lot of kluges, but have not managed to reliably convince the engine to separate shapes once they have joined together.














    The other problem with the Fisica/Geomerative combination is that imported SVGs routinely produce these errors:

    1. Didn't add unusable polygon.  Dumping vertices:

    2. float xv[] = {-0.197412f,-0.156395f,0.072887f,-0.463871f,-0.238113f,};
    3. float yv[] = {-0.122745f,-0.046813f,0.542663f,0.555746f,-0.028875f,};
    4. Found invalid polygon, 
    5. polygon is too thin.
    These errors don't seem to make a difference in the executed sketch, but really clutter the console.

    Any ideas?
    hi there

    Is it possible to get data for a Processing applet from the URI of the page it is running on?

    Basically, I have one Processing sketch that will need to have dozens of versions running concurrently, the only difference being some initial variables.  I want to have a single HTML page linking to the processing sketch, which then passes a user selection to the sketch; it seems the logical way to do this is with a pull-down menu form, which the Processing sketch uses to populate initial variables.

    For example, if my Processing sketch is hosted at:


    and I pass form data with the get method:


    is there any way to use the variable "bar" in my sketch like this:

    1. void setup() {
    2. int bar = intFromFormData;
    3. }

    4. println(bar);

    5. >>>100

    any ideas?
    Installed the ProHTML library in standard sketchbook location.  Restarted Processing as usual.

    When trying to run an example or two, the library objects aren't working.  For example, with the HtmlElement example, Processing craps out saying "The constructor HtmlElement(String, null) is undefined"

    any idea what's wrong? 
    I have begun developing the first of a long series of Processing sketches for use in a high school chemistry curriculum.  The idea is to use simulations of molecular activity to supplement lab and reading activity in learning chemistry concepts.  So far Processing has been a great tool for this project; my supervisor has been pleased with the functionality of Processing visualizations over previous Flash and Netlogo attempts.

    I've run into a particular problem with molecule interactions, however.  My question:
    How can I make two irregular shapes, floating across the Processing canvas, "bounce" off of one another when they overlap?

    Initially, I was rendering molecules in Processing with a series of different sized ellipses; making molecules bounce was a matter of calculating the radii of the atoms in a molecule, returning these radii in an array, and checking the array against the radii array of another molecule; if any radii overlapped, the molecules would bounce.  Pretty straightforward.

    However, the visual sophistication and variation between various molecules, in addition to requests for frequent updates in molecular structure and appearance, has pushed me toward creating the molecules in Adobe Illustrator, and importing Illustrator SVG files into Processing for use in my sketches.  Thus, since the files are SVG imports, I don't think I have access to their boundaries... the only thing I can think of is calculating which pixels the shapes occupy: this seems a horrible kluge, and I'm not sure how to do it.

    Does anyone have any other ideas?  I'm all ears.

    If you would like to see an early version of this project (with molecules drawn via Processing ellipses):