Advertisement
Camocc_Studios

ImprovedSnowman

Feb 24th, 2020
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.12 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Graphics;
  3. import java.awt.image.RenderedImage;
  4. import java.io.File;
  5. import java.io.IOException;
  6.  
  7. import javax.imageio.ImageIO;
  8. import javax.swing.JComponent;
  9. import javax.swing.JFrame;
  10.  
  11.  
  12. /*
  13.  * Lauren
  14.  * 2/18/20
  15.  */
  16. public class Snowman2 extends JComponent{
  17.     static JFrame window = new JFrame();
  18.     public static void main(String[] args) throws IOException {
  19.         window.setResizable(true);
  20.         window.setExtendedState(JFrame.MAXIMIZED_BOTH);
  21.         window.setUndecorated(true);
  22.         window.setVisible(true);
  23.         window.setDefaultCloseOperation(3);
  24.         window.add(new Snowman2());
  25.        
  26.         for(int i=0; i<yPositions.length;i++)
  27.             yPositions[i]=(int) (Math.random()*window.getHeight());
  28.     }  
  29.    
  30.     static int[] yPositions = new int[100];
  31.    
  32.     public void paintComponent(Graphics g) {
  33.         int width = window.getWidth();
  34.         int height = window.getHeight();
  35.         g.setColor(new Color(80,120,200));
  36.         g.fillRect(0,0,width,height);
  37.        
  38.         int sm1 = 300;
  39.         int sm2 = 225;
  40.         int sm3 = 150;
  41.         g.setColor(new Color(250,250,250));
  42.         g.fillOval(((int)width/2)-((int)sm1/2), ((int)height/2)-((int)sm1/2)+300, sm1, sm1);
  43.         g.fillOval(((int)width/2)-((int)sm2/2), ((int)height/2)-((int)sm2/2)+80, sm2, sm2);
  44.         g.fillOval(((int)width/2)-((int)sm3/2), ((int)height/2)-((int)sm3/2)-80, sm3, sm3);
  45.        
  46.         int btnR =15;
  47.         g.setColor(new Color(10,10,10));
  48.         g.fillOval(((int)width/2)-((int)btnR/2),550, btnR, btnR);
  49.         g.fillOval(((int)width/2)-((int)btnR/2),600, btnR, btnR);
  50.         g.fillOval(((int)width/2)-((int)btnR/2),650, btnR, btnR);
  51.        
  52.         g.fillOval(((int)width/2)-((int)btnR/2)-25,425, btnR, btnR);
  53.         g.fillOval(((int)width/2)-((int)btnR/2)+25,425, btnR, btnR);
  54.        
  55.         g.setColor(new Color(200,100,0));
  56.         int[] noseX = {((int)width/2)+30,((int)width/2)-10,((int)width/2)-10};
  57.         int[] noseY = {460,470,450};
  58.         g.fillPolygon(noseX,noseY,3);
  59.                
  60.         g.setColor(Color.white);
  61.         for(int i=0;i<yPositions.length;i++) {
  62.             g.fillOval(((int)Math.round((i/100f)*window.getWidth())),yPositions[i],10,10);
  63.             yPositions[i] += Math.random()*5;
  64.             if(yPositions[i]>=window.getHeight())
  65.                 yPositions[i] = 0;
  66.         }
  67.                
  68.         repaint();
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement