
// JepTurtle.java
// Andrew Davison, ad@coe.psu.ac.th, July 2023

/* Call spirals.py which uses Python's turtle graphics
   (https://docs.python.org/3/library/turtle.html)
   to generate a pleasing spiral pattern which it saves
   to the specified file, and then load the image into
   Java.

  Usage:
     > compile JepTurtle
     > run JepTurtle 
*/

import java.util.*;
import java.awt.image.*;

import jep.*;
import jep.python.*;


public class JepTurtle 
{
  private static final String IM_FNM = "JEPspirals";
     // the name of the file where the spirals
     // image will be saved


  public static void main(String[] args) throws JepException 
  {
    System.out.println("Starting Jep...");
    Interpreter jep = new SharedInterpreter();

    jep.set("fileName", IM_FNM);  // used in the script
    jep.runScript("spirals.py");
    jep.close();

    // load the saved image into Java
    ImageViewer.view("Turtle Spirals", IM_FNM+".png");
    BufferedImage im = PyUtils.loadImage(IM_FNM+".png");
    System.out.println("Image size: " + im.getWidth() + 
                                " x " + im.getHeight());
  } // end of main()

} // end of JepTurtle class
