// CIS 757 / 790         L.A.T.T.C            PROF. AUCIELLO
//
/*  TOPICS
        Mondarian (output as art)       - colors (red, green, blue)
        canvas size                     - hor, ver coordinates
        KB INPUT to an applet           - textfields
        init() time                     - random number generation
        String to Int conversion        - while loop
        Trace Statements                - initializing Prompts
        Batch file used to compile

Assignment:

	Run this use your name, and vary # iterations (careful not
        to have too many -- 500 iterations takes about 30 seconds).
        While the art is interesting, it serves to set the table
        for the programming concepts involved such as
        color as  having red-green-blue components.
        Comment every line of code.
        Modify program to print  output like  212-123-65
                                              red-gre-blu
        in random locations.                  (see demo)
        Objectives:  Gain a sense of how colors are formed.
        Learn how to input variables to an Applet.

*/


// mondarian

import java.awt.Graphics;
import java.awt.Font;
import java.awt.Color;
import java.lang.Math;
import java.util.Date;
import java.util.Random;
import java.util.*;
import java.awt.*;
import corejava.*;

public class auci4 extends java.applet.Applet
{ public TextField inputField1, inputField2, inputField3;;

  int n;

  public void init()
      { inputField1 = new TextField(20);
        add (inputField1);
        inputField1.setText("Overwrite with your Name");

        inputField2 = new TextField(4);
        add (inputField2);
        inputField2.setText("10");

        inputField3= new TextField(28);
        add (inputField3);
        inputField3.setText("Type Iterations. Click 'Reload' to Start.");
      }

 public void paint(Graphics g)
      { int n  = 5, rval, gval, bval, x=0, ver=0, hor=0;
        Font f    = new Font("TimesRoman", Font.ITALIC, 24);
        Random r  = new Random();
        String s  =  inputField1.getText();
        String ns =  inputField2.getText();
                n =  Integer.parseInt(ns);

        while (x < n)
         {hor  = Math.abs(r.nextInt()%520+1);
          ver  = Math.abs(r.nextInt()%230+1);
          rval = Math.abs(r.nextInt()%224+1);
          System.out.println("rval = "+ rval+s+" = input string paint()");
          gval = Math.abs(r.nextInt()%224+1);
          bval = Math.abs(r.nextInt()%224+1);
          g.setFont(f);
          g.setColor(new Color(rval,gval,bval)); // get random color.

          g.drawString(s,hor,ver+70);
          x++;
         }  // end while group
      }  // end paint class
}  // end class 

// ==================================================
// auci4

/*