Exporting code/copying code/ code management

Exporting was mentioned already…

There are occasions where my Processing application crashes and I did not do a recent save.

I look into the %temp% folder and can find the last *.java file that Processing generated which is the same as an export (for working code). If I had a lot of tabs it is “a chore to restore”. :slight_smile:

These *.java and other files are also generated for every sketch and in the %temp% folder.

For example:

import processing.core.*; 
import processing.data.*; 
import processing.event.*; 
import processing.opengl.*; 

import java.util.HashMap; 
import java.util.ArrayList; 
import java.io.File; 
import java.io.BufferedReader; 
import java.io.PrintWriter; 
import java.io.InputStream; 
import java.io.OutputStream; 
import java.io.IOException; 

public class XY_Perlin_00 extends PApplet {

//Perlin noise used to generate a line
//Gives a nice "warbling" effect

float xoff1, xoff2, xoff3;

public void setup()
  {
  
  }

public void draw()
  {
  background(220);
  stroke(102, 0, 230);  
  strokeWeight(10);
  
  translate(-40, 0);
  rotate(-TAU/128);
  scale(.8f, 1);
  float p = .019f;

// I see patterns here and could replace with a for loop:
  circle(300, height - 300 +20, .019f);
  circle(500, height - 500 +20, .020f);
  circle(700, height - 700 +20, .021f); 

  lineX(100, 100, 800);
  lineY(100, 100, 800);  
  lineXY(100, 100, 800); 
  }

public void circle(int x, int y, float rand)
  {
  for (float th = -TAU/20 +TAU/2; th < 3*TAU/2 + TAU/20; th += TAU/500)
    {
    xoff1 = xoff1 + rand;
    random(10);
    float r = 40 + 10*noise(xoff1);
//    println(noise(xoff1));
    point( r*cos(th)+x, r*sin(th)+y);
    }
  }  
  
// These could be consolidated into one method and called from draw();  

public void lineX(int x1, int y1, int l)
  {
  for (float i = 0; i<l; i+=1)
    {
    xoff2 = xoff2 + .02f;
    point(i + x1, height - y1 + 10*noise(xoff2));
    }
  }  

public void lineY(int x1, int y1, int l)
  {
  for (float i = 0; i<l; i+=1)
    {
    xoff2 = xoff2 + .02f;
    point(x1 + 10*noise(xoff2), i + y1 + 10*noise(xoff2));
    }
  } 

public void lineXY(int x1, int y1, int l)
  {
  for (float i = 0; i<l; i+=1)
    {
    xoff3 = xoff3 + .02f;
    point(i + x1 + 10*noise(xoff3), height -i - y1 + 10*noise(xoff3));
    }
} 
  
  public void settings() {  size(800, 1000, P2D); }
  static public void main(String[] passedArgs) {
    String[] appletArgs = new String[] { "XY_Perlin_00" };
    if (passedArgs != null) {
      PApplet.main(concat(appletArgs, passedArgs));
    } else {
      PApplet.main(appletArgs);
    }
  }
}

If comment the “extras” that were added it will run as Processing sketch:

//import processing.core.*; 
//import processing.data.*; 
//import processing.event.*; 
//import processing.opengl.*; 

//import java.util.HashMap; 
//import java.util.ArrayList; 
//import java.io.File; 
//import java.io.BufferedReader; 
//import java.io.PrintWriter; 
//import java.io.InputStream; 
//import java.io.OutputStream; 
//import java.io.IOException; 

//public class XY_Perlin_00 extends PApplet {

//Perlin noise used to generate a line
//Gives a nice "warbling" effect

float xoff1, xoff2, xoff3;

public void setup()
  {
  
  }

public void draw()
  {
  background(220);
  stroke(102, 0, 230);  
  strokeWeight(10);
  
  translate(-40, 0);
  rotate(-TAU/128);
  scale(.8f, 1);
  float p = .019f;

// I see patterns here and could replace with a for loop:
  circle(300, height - 300 +20, .019f);
  circle(500, height - 500 +20, .020f);
  circle(700, height - 700 +20, .021f); 

  lineX(100, 100, 800);
  lineY(100, 100, 800);  
  lineXY(100, 100, 800); 
  }

public void circle(int x, int y, float rand)
  {
  for (float th = -TAU/20 +TAU/2; th < 3*TAU/2 + TAU/20; th += TAU/500)
    {
    xoff1 = xoff1 + rand;
    random(10);
    float r = 40 + 10*noise(xoff1);
//    println(noise(xoff1));
    point( r*cos(th)+x, r*sin(th)+y);
    }
  }  
  
// These could be consolidated into one method and called from draw();  

public void lineX(int x1, int y1, int l)
  {
  for (float i = 0; i<l; i+=1)
    {
    xoff2 = xoff2 + .02f;
    point(i + x1, height - y1 + 10*noise(xoff2));
    }
  }  

public void lineY(int x1, int y1, int l)
  {
  for (float i = 0; i<l; i+=1)
    {
    xoff2 = xoff2 + .02f;
    point(x1 + 10*noise(xoff2), i + y1 + 10*noise(xoff2));
    }
  } 

public void lineXY(int x1, int y1, int l)
  {
  for (float i = 0; i<l; i+=1)
    {
    xoff3 = xoff3 + .02f;
    point(i + x1 + 10*noise(xoff3), height -i - y1 + 10*noise(xoff3));
    }
} 
  
  public void settings() {  size(800, 1000, P2D); }
//  static public void main(String[] passedArgs) {
//    String[] appletArgs = new String[] { "XY_Perlin_00" };
//    if (passedArgs != null) {
//      PApplet.main(concat(appletArgs, passedArgs));
//    } else {
//      PApplet.main(appletArgs);
//    }
//  }
//}