Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.Graphics;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
- import java.awt.image.BufferedImage;
- import javax.swing.JFrame;
- public class Screen extends JFrame implements Runnable, MouseListener {
- BufferedImage Show;
- Pnt[] pnt;
- int p; //myers-briggs
- int i, t, u, sizx, sizy;
- public static void main(String[] args) {
- Screen bob = new Screen();
- bob.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
- bob.setTitle("Pretty Colors");
- bob.setResizable(false);
- bob.setVisible(true);
- bob.init();
- bob.start();
- }
- public void init() {
- sizx = 1200;
- sizy = 800;
- Show = new BufferedImage(sizx, sizy, BufferedImage.TYPE_INT_ARGB);
- setSize(sizx, sizy);
- setLocation(80, 0);
- SetItUpYo();
- addMouseListener(this);
- }
- public void start() {
- Thread Electricity = new Thread(this);
- Electricity.start();
- }
- public void run() {
- //System.out.println("run");
- try {
- while(true) {
- repaint();
- Thread.sleep(23);
- }
- }
- catch(Exception e) { }
- }
- public void paint(Graphics g) {
- Drawitbaby();
- g.drawImage(Show, 0, 0, this);
- }
- public void Drawitbaby() {
- Graphics g = Show.getGraphics();
- g.setColor(Color.black);
- g.fillRect(0, 0, sizx, sizy);
- for(i = 0; i < p; i++) {
- pnt[i].update();
- for(t = 99; t > 0; t--) {
- g.setColor(pnt[i].getColor(100 - t));
- g.fillOval(pnt[i].pastx[t], pnt[i].pasty[t], (int)((100 - t) * .1), (int)((100 - t) * .1));
- pnt[i].pastx[t] = pnt[i].pastx[t - 1];
- pnt[i].pasty[t] = pnt[i].pasty[t - 1];
- }
- for(u = 0; u < p; u++){
- if(pnt[i].changedir && i!=u && pnt[i].Checkit(pnt[u].px, pnt[u].py, pnt[u].angle))
- pnt[i].resetvars(pnt[u].angle);
- }
- if(pnt[i].changedir)
- pnt[i].resetvars(.23);
- //g.setColor(Color.white);
- //g.drawLine(pnt[i].x, pnt[i].y, pnt[i].px, pnt[i].py);
- }
- }
- public void SetItUpYo() {
- p = 64;
- pnt = new Pnt[p];
- int q = (p / 4);
- int d, a, b, f, g;
- int red, green, blue;
- new java.util.Random();
- for(d = 0; d < 4; d++) {
- a = (int) (Math.random() * sizx);
- b = (int) (Math.random() * sizy);
- red = (int) (50 + (Math.random() * 200));
- green = (int) (50 + (Math.random() * 200));
- blue = (int) (50 + (Math.random() * 200));
- for(i = 0; i < q; i++) {
- f = (int) (25 - (Math.random() * 50));
- g = (int) (25 - (Math.random() * 50));
- pnt[(d * q) + i] = new Pnt(360 * ((double)i / (double)q), a - f, b - g, red - f, green - g, blue - g + f);
- }
- }
- }
- public void mouseClicked(MouseEvent e) {
- SetItUpYo();
- }
- public void mouseEntered(MouseEvent e) {}
- public void mouseExited(MouseEvent e) {}
- public void mousePressed(MouseEvent e) {}
- public void mouseReleased(MouseEvent e) {}
- }
- import java.awt.Color;
- public class Pnt {
- int x, y, px, py;
- int[] pastx, pasty;
- int r, g, b;
- int magnitude, shift, cycle, spd;
- double angle, a;
- double vx, vy, d;
- boolean changedir, L;
- public Pnt(double ang, int ex, int wy, int rr, int gg, int bb) {
- x = px = ex;
- y = py = wy;
- r = Math.abs(Math.min(rr, 250));
- g = Math.abs(Math.min(gg, 250));
- b = Math.abs(Math.min(bb, 250));
- spd = 6;
- if(Math.random()>.5)
- L = true;
- else
- L = false;
- changedir = false;
- cycle = Math.max(magnitude / 5, 10);
- pastx = new int[100];
- pasty = new int[100];
- for(int a = 0; a < 100; a++){
- pastx[a] = x;
- pasty[a] = y;
- }
- resetvars(ang);
- }
- public void resetvars(double ang){
- changedir = false;
- magnitude = (int) (50 + (Math.random() * 200));
- x = px;
- y = py;
- shift = 0;
- if(ang!=.23)
- angle = ang;
- else if(x < 0)
- angle = 315 + (Math.random() * 90);
- else if(y < 0)
- angle = 225 + (Math.random() * 90);
- else if(x > 1200)
- angle = 135 + (Math.random() * 90);
- else if(y > 800)
- angle = 45 + (Math.random() * 90);
- else
- angle += (45 - Math.random() * 90);
- if(angle > 360)
- angle -= 360;
- else if(angle < 0)
- angle += 360;
- if(L)
- L = false;
- else
- L = true;
- setVel();
- }
- public void setVel() {
- vx = spd * Math.cos(Math.toRadians(angle)) * .1;
- vy = -1 * spd * Math.sin(Math.toRadians(angle)) * .1;
- d = Math.sqrt(Math.pow((vx * magnitude), 2) + Math.pow((vy * magnitude), 2)) / 2;
- }
- public void update() {
- if(shift > magnitude / 2)
- cycle++;
- else if(cycle > 10)
- cycle--;
- shift += cycle * .1;
- if(shift >= magnitude) {
- shift = magnitude;
- changedir = true;
- }
- px = x + (int)(vx * shift);
- py = y + (int)(vy * shift);
- if(L)
- a = angle - 90 + (((double)shift / (double)magnitude) * 180);
- else
- a = angle - 90 - (((double)shift / (double)magnitude) * 180);
- pastx[0] = (int)((x + (vx * magnitude) / 2) + d * Math.sin(Math.toRadians(a)));
- pasty[0] = (int)((y + (vy * magnitude) / 2) + d * Math.cos(Math.toRadians(a)));
- }
- public Color getColor(int t) {
- return new Color((int) (r * t * .01), (int) (g * t * .01), (int) (b * t * .01));
- }
- public boolean Checkit(int cx, int cy, double ca){
- if(x < 0 || x > 1200 || y < 0 || y > 800)
- return false;
- if(Math.abs(px - cx) < 150 && Math.abs(py - cy) < 150) {
- if(Math.abs(angle - ca) < 90 || Math.abs(angle - ca) > 315)
- return true;
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement