Hey Guys.. making a convex hull here with 100 random squares..or asterisks... but i wanted to first graph all of the radom points and start figuring out grahams scan algorithm by measuring the angles.
Any help?
import java.awt.*; import java.util.ArrayList; import java.util.Random; import javax.swing.*; public class Convex extends JFrame { public static int WIDTH = 500; public static int HEIGHT = 500; public static int POINTS = 100; public static void main (String [] args) { Random r = new Random(); ArrayList <Point> points = new ArrayList <Point>(); for ( int i = 0; i<POINTS; i++){ points.add(new Point(r.nextInt(WIDTH), r.nextInt(HEIGHT))); } // make the window JFrame frame = new JFrame("Convex"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Graph g = new Graph(WIDTH, HEIGHT, POINTS); frame.getContentPane().add(g); frame.pack(); frame.setVisible(true); } }
import java.awt.Color; import java.awt.Graphics; import java.awt.Point; import javax.swing.JPanel; import java.awt.*; import java.util.ArrayList; import javax.swing.*; public class Graph extends JPanel { public int WIDTH, HEIGHT, POINTS; public Color BACKGROUND = Color.WHITE; public Color POINTCOLOR = Color.blue; public Graph(int i, int j, int p) { WIDTH = i; HEIGHT = j; POINTS = p; setPreferredSize(new Dimension(i,j)); } public void paintComponent(Graphics g) { super.paintComponent(g); g.setColor(BACKGROUND); g.fillRect(0, 0, WIDTH, HEIGHT); } }