Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JApplet;
- import java.awt.*;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.util.*;
- import java.awt.geom.GeneralPath;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- public class Umbrella extends JApplet
- {
- Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
- //private final int APPLET_WIDTH = (int) screenSize.getWidth();
- //private final int APPLET_HEIGHT = (int) screenSize.getHeight();
- private final int APPLET_WIDTH = (int) Math.floor(710);
- private final int APPLET_HEIGHT = (int) Math.floor(685);
- 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};
- 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};
- private int [] xPole = {336, 336, 342, 342};
- private int [] yPole = {272, 655, 655, 272};
- private int [] xSand = { 0, 710, 710, 0};
- private int [] ySand = {685, 685, 469, 469};
- private int [] xWetSand = { 0, 710, 710, 0};
- private int [] yWetSand = {469, 469, 428, 428};
- private int [] xOcean = { 0, 710, 710, 0};
- private int [] yOcean = {428, 428, 344, 344};
- private int [] xSky = { 0, 710, 710, 0};
- private int [] ySky = { 0, 0, 685, 685};
- public void init ()
- {
- addMouseListener(new mouseCheck());
- resize(xUmbrella, yUmbrella);
- resize(xPole, yPole);
- resize(xSand, ySand);
- resize(xWetSand, yWetSand);
- resize(xOcean, yOcean);
- resize(xSky, ySky);
- setSize (APPLET_WIDTH, APPLET_HEIGHT);
- }
- public void paint (Graphics page1)
- {
- Graphics2D page = (Graphics2D) page1;
- RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- page.setRenderingHints(rh);
- Color darkGreen = new Color (20, 62, 58);
- Color tanPole = new Color (173, 147, 132);
- Color sand = new Color (231, 214, 207);
- Color wetSand = new Color (190, 173, 178);
- Color ocean = new Color ( 32, 147, 177);
- Color sky = new Color ( 15, 100, 202);
- drawPolygon(sky, xSky, ySky, page);
- drawPolygon(ocean, xOcean, yOcean, page);
- drawPolygon(wetSand, xWetSand, yWetSand, page);
- drawPolygon(sand, xSand, ySand, page);
- drawPolygon(tanPole, xPole, yPole, page);
- drawPolygon(darkGreen, xUmbrella, yUmbrella, page);
- }
- public void resize (int [] x, int [] y)
- {
- for (int i = 0; i < x.length; i++)
- {
- x[i] = (int) (((double) x[i] / 710) * APPLET_WIDTH);
- y[i] = (int) (((double) y[i] / 685) * APPLET_HEIGHT);
- }
- }
- public void drawPolygon (Color c, int [] x, int [] y, Graphics2D p)
- {
- GeneralPath polygon = new GeneralPath(GeneralPath.WIND_EVEN_ODD, x.length);
- polygon.moveTo(x[0], y[0]);
- for (int i = 1; i < x.length; i++)
- {
- polygon.lineTo(x[i], y[i]);
- }
- // if (polygon.contains(x, y)
- if (false) //store code for when i figure out how to check if polygon is clicked
- {
- Random random = new Random();
- float hue = random.nextFloat();
- float saturation = (random.nextInt(2000) + 1000) / 10000f;
- float luminance = 0.9f;
- c = Color.getHSBColor(hue, saturation, luminance);
- }
- polygon.closePath();
- p.setColor(c);
- p.fill(polygon);
- p.setColor(Color.black);
- p.draw(polygon);
- }
- public class mouseCheck extends MouseAdapter
- {
- public Point mouseClicked (MouseEvent e)
- {
- return e.MouseInfo.getPointerInfo().getLocation();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement