Processing -> Java -- Can I ouput/view native java files.

edited May 2016 in Android Mode

Hi, I would like to see java files for a Processing program. I am assuming since Processing runs on java there is a way to have processing generate code in Java. Thanks for your help. Tim

Answers

  • operating system?

  • preference for Mac.

  • The processing run command wraps your code into a little bit of Java and does a few other changes like converting color to int. The output of this stage is saved somewhere on the file system before being compiled as Java. On Linux it's in the /tmp directory, named after the sketch but with a big random suffix. I don't know about macs but have a look there first.

    There's not a lot of difference between the pde and the Java tbh - most of the work is done by libraries. Depends what you're after.

  • for instance, a simple sketch:

    void setup() {
      size(100, 100);
      noStroke();
    }
    
    void draw() {
      color c = #123456;
      ellipse(width / 2, height / 2, width / 2, width / 2);
    }
    

    becomes /tmp/sketch_jul21a8978331535202291499temp/sketch_jul21a.java

    import processing.core.*; 
    import processing.xml.*; 
    
    import java.applet.*; 
    import java.awt.Dimension; 
    import java.awt.Frame; 
    import java.awt.event.MouseEvent; 
    import java.awt.event.KeyEvent; 
    import java.awt.event.FocusEvent; 
    import java.awt.Image; 
    import java.io.*; 
    import java.net.*; 
    import java.text.*; 
    import java.util.*; 
    import java.util.zip.*; 
    import java.util.regex.*; 
    
    public class sketch_jul21a extends PApplet {
    
    public void setup() {
      size(100, 100);
      noStroke();
    }
    
    public void draw() {
      int c = 0xff123456;
      ellipse(width / 2, height / 2, width / 2, width / 2);
    }
      static public void main(String args[]) {
        PApplet.main(new String[] { "--bgcolor=#DFDFDF", "sketch_jul21a" });
      }
    }
    
  • (^ processing 1.5.1)

  • When you export a sketch, the PDE exports the .java files as well.

Sign In or Register to comment.