Advertisement
Guest User

Untitled

a guest
Jan 17th, 2013
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.19 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Graphics;
  3. import java.awt.event.MouseEvent;
  4. import java.awt.event.MouseListener;
  5. import java.awt.image.BufferedImage;
  6. import javax.swing.JFrame;
  7.  
  8. public class Screen extends JFrame implements Runnable, MouseListener {
  9.     BufferedImage Show;
  10.     Pnt[] pnt;
  11.     int p; //myers-briggs
  12.     int i, t, u, sizx, sizy;
  13.     public static void main(String[] args) {
  14.         Screen bob = new Screen();
  15.         bob.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  16.         bob.setTitle("Pretty Colors");
  17.         bob.setResizable(false);
  18.         bob.setVisible(true);
  19.         bob.init();
  20.         bob.start();
  21.     }
  22.     public void init() {
  23.         sizx = 1200;
  24.         sizy = 800;
  25.         Show = new BufferedImage(sizx, sizy, BufferedImage.TYPE_INT_ARGB);
  26.         setSize(sizx, sizy);
  27.         setLocation(80, 0);
  28.         SetItUpYo();
  29.         addMouseListener(this);
  30.     }
  31.     public void start() {
  32.         Thread Electricity = new Thread(this);
  33.         Electricity.start();
  34.     }  
  35.     public void run() {
  36.         //System.out.println("run");
  37.         try {
  38.             while(true) {
  39.                 repaint();
  40.                 Thread.sleep(23);
  41.             }
  42.         }
  43.         catch(Exception e) { }
  44.     }
  45.     public void paint(Graphics g) {
  46.         Drawitbaby();
  47.         g.drawImage(Show, 0, 0, this);
  48.     }
  49.     public void Drawitbaby() {
  50.         Graphics g = Show.getGraphics();
  51.         g.setColor(Color.black);
  52.         g.fillRect(0, 0, sizx, sizy);
  53.         for(i = 0; i < p; i++) {
  54.             pnt[i].update();
  55.             for(t = 99; t > 0; t--) {  
  56.                 g.setColor(pnt[i].getColor(100 - t));
  57.                 g.fillOval(pnt[i].pastx[t], pnt[i].pasty[t], (int)((100 - t) * .1), (int)((100 - t) * .1));
  58.                 pnt[i].pastx[t] = pnt[i].pastx[t - 1];
  59.                 pnt[i].pasty[t] = pnt[i].pasty[t - 1];
  60.             }  
  61.             for(u = 0; u < p; u++){
  62.                 if(pnt[i].changedir && i!=u && pnt[i].Checkit(pnt[u].px, pnt[u].py, pnt[u].angle))
  63.                     pnt[i].resetvars(pnt[u].angle);
  64.             }
  65.             if(pnt[i].changedir)
  66.                 pnt[i].resetvars(.23);
  67.             //g.setColor(Color.white);
  68.             //g.drawLine(pnt[i].x, pnt[i].y, pnt[i].px, pnt[i].py);
  69.         }
  70.     }
  71.     public void SetItUpYo() {
  72.         p = 64;
  73.         pnt = new Pnt[p];
  74.         int q = (p / 4);
  75.         int d, a, b, f, g;
  76.         int red, green, blue;
  77.         new java.util.Random();
  78.         for(d = 0; d < 4; d++) {
  79.             a = (int) (Math.random() * sizx);
  80.             b = (int) (Math.random() * sizy);
  81.             red = (int) (50 + (Math.random() * 200));
  82.             green = (int) (50 + (Math.random() * 200));
  83.             blue = (int) (50 + (Math.random() * 200));
  84.             for(i = 0; i < q; i++) {
  85.                 f = (int) (25 - (Math.random() * 50));
  86.                 g = (int) (25 - (Math.random() * 50));
  87.                 pnt[(d * q) + i] = new Pnt(360 * ((double)i / (double)q), a - f, b - g, red - f, green - g, blue - g + f);
  88.             }
  89.         }
  90.     }
  91.     public void mouseClicked(MouseEvent e) {
  92.         SetItUpYo();
  93.     }
  94.     public void mouseEntered(MouseEvent e) {}
  95.     public void mouseExited(MouseEvent e) {}
  96.     public void mousePressed(MouseEvent e) {}
  97.     public void mouseReleased(MouseEvent e) {}
  98. }
  99. import java.awt.Color;
  100.  
  101. public class Pnt {
  102.     int x, y, px, py;
  103.     int[] pastx, pasty;
  104.     int r, g, b;
  105.     int magnitude, shift, cycle, spd;
  106.     double angle, a;
  107.     double vx, vy, d;
  108.     boolean changedir, L;
  109.     public Pnt(double ang, int ex, int wy, int rr, int gg, int bb) {
  110.         x = px = ex;
  111.         y = py = wy;
  112.         r = Math.abs(Math.min(rr, 250));
  113.         g = Math.abs(Math.min(gg, 250));
  114.         b = Math.abs(Math.min(bb, 250));
  115.         spd = 6;
  116.         if(Math.random()>.5)
  117.             L = true;
  118.         else
  119.             L = false;
  120.         changedir = false;
  121.         cycle = Math.max(magnitude / 5, 10);
  122.         pastx = new int[100];
  123.         pasty = new int[100];
  124.         for(int a = 0; a < 100; a++){
  125.             pastx[a] = x;
  126.             pasty[a] = y;
  127.         }
  128.         resetvars(ang);
  129.     }
  130.     public void resetvars(double ang){
  131.         changedir = false;
  132.         magnitude = (int) (50 + (Math.random() * 200));
  133.         x = px;
  134.         y = py;
  135.         shift = 0;
  136.         if(ang!=.23)
  137.             angle = ang;
  138.         else if(x < 0)
  139.             angle = 315 + (Math.random() * 90);
  140.         else if(y < 0)
  141.             angle = 225 + (Math.random() * 90);
  142.         else if(x > 1200)
  143.             angle = 135 + (Math.random() * 90);
  144.         else if(y > 800)
  145.             angle = 45 + (Math.random() * 90);
  146.         else
  147.             angle += (45 - Math.random() * 90);
  148.         if(angle > 360)
  149.             angle -= 360;
  150.         else if(angle < 0)
  151.             angle += 360;
  152.         if(L)
  153.             L = false;
  154.         else
  155.             L = true;
  156.         setVel();
  157.     }
  158.     public void setVel() {
  159.         vx = spd * Math.cos(Math.toRadians(angle)) * .1;
  160.         vy = -1 * spd * Math.sin(Math.toRadians(angle)) * .1;
  161.         d = Math.sqrt(Math.pow((vx * magnitude), 2) + Math.pow((vy * magnitude), 2)) / 2;
  162.     }
  163.     public void update() {
  164.         if(shift > magnitude / 2)
  165.             cycle++;
  166.         else if(cycle > 10)
  167.             cycle--;
  168.         shift += cycle * .1;
  169.         if(shift >= magnitude) {
  170.             shift = magnitude;
  171.             changedir = true;
  172.         }
  173.         px = x + (int)(vx * shift);
  174.         py = y + (int)(vy * shift);
  175.         if(L)
  176.             a = angle - 90 + (((double)shift / (double)magnitude) * 180);
  177.         else
  178.             a = angle - 90 - (((double)shift / (double)magnitude) * 180);
  179.         pastx[0] = (int)((x + (vx * magnitude) / 2) + d * Math.sin(Math.toRadians(a)));
  180.         pasty[0] = (int)((y + (vy * magnitude) / 2) + d * Math.cos(Math.toRadians(a)));
  181.     }
  182.     public Color getColor(int t) {
  183.         return new Color((int) (r * t * .01), (int) (g * t * .01), (int) (b * t * .01));
  184.     }
  185.     public boolean Checkit(int cx, int cy, double ca){
  186.         if(x < 0 || x > 1200 || y < 0 || y > 800)
  187.             return false;
  188.         if(Math.abs(px - cx) < 150 && Math.abs(py - cy) < 150) {
  189.             if(Math.abs(angle - ca) < 90 || Math.abs(angle - ca) > 315)
  190.                 return true;
  191.         }
  192.         return false;
  193.     }
  194. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement