Advertisement
Guest User

Untitled

a guest
May 3rd, 2015
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.74 KB | None | 0 0
  1. import javax.swing.JApplet;
  2. import java.awt.*;
  3. import java.awt.Graphics;
  4. import java.awt.Graphics2D;
  5. import java.util.*;
  6. import java.awt.geom.GeneralPath;
  7. import java.awt.event.MouseAdapter;
  8. import java.awt.event.MouseEvent;
  9.  
  10.  
  11. public class Umbrella extends JApplet
  12. {
  13.  
  14.     Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  15.  
  16.     //private final int APPLET_WIDTH = (int) screenSize.getWidth();
  17.     //private final int APPLET_HEIGHT = (int) screenSize.getHeight();
  18.  
  19.     private final int APPLET_WIDTH  = (int) Math.floor(710);
  20.     private final int APPLET_HEIGHT = (int) Math.floor(685);
  21.  
  22.     private int [] xUmbrella = {510, 505, 501, 496, 492, 488, 483, 476, 339, 202, 195, 190, 186, 181, 176, 172, 167,  15,  15,  22,  74, 100, 156, 186, 218, 274, 344, 414, 470, 502, 532, 588, 610, 666, 673, 673};
  23.     private int [] yUmbrella = {273, 238, 231, 229, 231, 238, 266, 272, 272, 272, 266, 238, 231, 229, 231, 238, 273, 261, 227, 211, 168, 145, 112, 100,  91,  81,  78,  81,  91, 100, 112, 145, 168, 211, 227, 261};
  24.  
  25.     private int []     xPole = {336, 336, 342, 342};
  26.     private int []     yPole = {272, 655, 655, 272};
  27.  
  28.     private int []     xSand = {  0, 710, 710,   0};
  29.     private int []     ySand = {685, 685, 469, 469};
  30.  
  31.     private int []  xWetSand = {  0, 710, 710,   0};
  32.     private int []  yWetSand = {469, 469, 428, 428};
  33.  
  34.     private int []    xOcean = {  0, 710, 710,   0};
  35.     private int []    yOcean = {428, 428, 344, 344};
  36.  
  37.     private int []      xSky = {  0, 710, 710,   0};
  38.     private int []      ySky = {  0,   0, 685, 685};
  39.  
  40.  
  41.     public void init ()
  42.     {
  43.         addMouseListener(new mouseCheck());
  44.  
  45.         resize(xUmbrella, yUmbrella);
  46.         resize(xPole,     yPole);
  47.         resize(xSand,     ySand);
  48.         resize(xWetSand,  yWetSand);
  49.         resize(xOcean,    yOcean);
  50.         resize(xSky,      ySky);
  51.  
  52.         setSize (APPLET_WIDTH, APPLET_HEIGHT);
  53.     }
  54.  
  55.     public void paint (Graphics page1)
  56.     {
  57.         Graphics2D page = (Graphics2D) page1;
  58.  
  59.         RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  60.         page.setRenderingHints(rh);
  61.  
  62.  
  63.  
  64.         Color darkGreen = new Color (20,  62,  58);
  65.         Color   tanPole = new Color (173, 147, 132);
  66.         Color      sand = new Color (231, 214, 207);
  67.         Color   wetSand = new Color (190, 173, 178);
  68.         Color     ocean = new Color ( 32, 147, 177);
  69.         Color       sky = new Color ( 15, 100, 202);
  70.  
  71.  
  72.  
  73.         drawPolygon(sky,       xSky,      ySky,      page);
  74.         drawPolygon(ocean,     xOcean,    yOcean,    page);
  75.         drawPolygon(wetSand,   xWetSand,  yWetSand,  page);
  76.         drawPolygon(sand,      xSand,     ySand,     page);
  77.         drawPolygon(tanPole,   xPole,     yPole,     page);
  78.         drawPolygon(darkGreen, xUmbrella, yUmbrella, page);
  79.     }
  80.  
  81.     public void resize (int [] x, int [] y)
  82.     {
  83.         for (int i = 0; i < x.length; i++)
  84.         {
  85.             x[i] = (int) (((double) x[i] / 710) * APPLET_WIDTH);
  86.             y[i] = (int) (((double) y[i] / 685) * APPLET_HEIGHT);
  87.         }
  88.     }
  89.  
  90.     public void drawPolygon (Color c, int [] x, int [] y, Graphics2D p)
  91.     {
  92.         GeneralPath polygon = new GeneralPath(GeneralPath.WIND_EVEN_ODD, x.length);
  93.         polygon.moveTo(x[0], y[0]);
  94.  
  95.         for (int i = 1; i < x.length; i++)
  96.         {
  97.             polygon.lineTo(x[i], y[i]);
  98.         }
  99.  
  100.         // if (polygon.contains(x, y)
  101.         if (false) //store code for when i figure out how to check if polygon is clicked
  102.         {
  103.             Random random = new Random();
  104.             float hue = random.nextFloat();
  105.             float saturation = (random.nextInt(2000) + 1000) / 10000f;
  106.             float luminance = 0.9f;
  107.             c = Color.getHSBColor(hue, saturation, luminance);
  108.         }
  109.  
  110.  
  111.         polygon.closePath();
  112.         p.setColor(c);
  113.         p.fill(polygon);
  114.         p.setColor(Color.black);
  115.         p.draw(polygon);
  116.     }
  117.  
  118.     public class mouseCheck extends MouseAdapter
  119.     {
  120.         public Point mouseClicked (MouseEvent e)
  121.         {
  122.             return e.MouseInfo.getPointerInfo().getLocation();
  123.         }
  124.     }
  125.  
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement