
// DrawPic.java
// Joshua Gulick, Orphan Technologies, Inc., 6/2/2000
// Andrew Davison, ad@coe.psu.ac.th, April 2023

/* Draw various graphics on a blue background.
   Save the image as a PNG file.

   Usage:
     > compile DrawPic.java
     > run DrawPic
*/

import java.awt.*;

import ij.*;
import ij.gui.*;
import ij.process.*;


public class DrawPic
{
  private static final String SAVE_FNM = "orange.png";

  private static final int LEN = 300;
  private static final int RADIUS = 60;


  public static void main(String[] args)
  {
    ImageProcessor imProc = new ColorProcessor(LEN, LEN);
    imProc.setRoi(0, 0, LEN, LEN);
    imProc.setColor(Color.BLUE);
    imProc.fill();

    int xCenter = LEN/2, yCenter = LEN/2;

    // unfilled orange circle in the center
    imProc.setColor(Color.ORANGE);
    imProc.drawOval(xCenter-RADIUS, yCenter-RADIUS, RADIUS*2, RADIUS*2);
/*
    int[] orange = ImageUtils.color2Array(Color.ORANGE);
    double step = 0;
    while (step < 10) {
      double x = Math.sin(step)*RADIUS + xCenter;
      double y = Math.cos(step)*RADIUS + yCenter;
      imProc.putPixel((int)x, (int)y, orange); 
      step = step + 0.001;
    }
*/
    // an orange arrow
    int [] xs = {50,50,90,90,150,90,90};
    int [] ys = {55,85,85,110,70,30,55};
    Polygon p = new Polygon(xs, ys, xs.length);
    imProc.fillPolygon(p);

    // big white text
    imProc.setFont(new Font("TimesRoman", Font.PLAIN, 48)); 
    imProc.setColor(Color.WHITE);
    imProc.drawString("ImageJ", xCenter, yCenter);


    ImagePlus imp = new ImagePlus("Draw Circle", imProc);
    imp.show();

    System.out.println("Saving image to " + SAVE_FNM);
    IJ.saveAs(imp, ImageUtils.getExt(SAVE_FNM), SAVE_FNM);
      /* ".tif", ".jpg", ".gif", ".zip", ".raw", ".avi", 
         ".bmp", ".fits", ".pgm", ".png", ".lut", ".roi", ".txt"
         The image is saved in TIFF format if there is no extension.
      */
  } /* main */


}  // end of DrawPic class


