-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisuals.java
More file actions
131 lines (112 loc) · 4.01 KB
/
visuals.java
File metadata and controls
131 lines (112 loc) · 4.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package funStuff;
import java.awt.*;
import java.awt.event.*;
import java.util.List;
import java.util.ArrayList;
public class visuals extends Frame {
public static List<Particle> particles = new ArrayList<>();
static double forceConstant = .5;
public static void main(String[] args) {
//double randomValue = ;
double greenOnGreen = randomValue();
System.out.println(greenOnGreen);
double yellowOnGreen = randomValue();
System.out.println(yellowOnGreen);
double blueOnGreen = randomValue();
System.out.println(blueOnGreen);
double redOnGreen = randomValue();
System.out.println(redOnGreen);
double greenOnYellow = randomValue();
System.out.println(greenOnYellow);
double yellowOnYellow = randomValue();
System.out.println(yellowOnYellow);
double blueOnYellow = randomValue();
System.out.println(blueOnYellow);
double redOnYellow = randomValue();
System.out.println(redOnYellow);
double greenOnBlue = randomValue();
System.out.println(greenOnBlue);
double yellowOnBlue = randomValue();
System.out.println(yellowOnBlue);
double blueOnBlue = randomValue();
System.out.println(blueOnBlue);
double redOnBlue = randomValue();
System.out.println(redOnBlue);
double greenOnRed = randomValue();
System.out.println(greenOnRed);
double yellowOnRed = randomValue();
System.out.println(yellowOnRed);
double blueOnRed = randomValue();
System.out.println(greenOnRed);
double redOnRed = randomValue();
System.out.println(redOnRed);
//400 is the max you can get without inducing too much lag
for (int i = 0; i < 600; i++) {
particles.add(Particle.createRandomParticle(greenOnGreen, yellowOnGreen, blueOnGreen, redOnGreen, 'g'));
particles.add(Particle.createRandomParticle(greenOnYellow, yellowOnYellow, blueOnYellow, redOnYellow, 'y'));
particles.add(Particle.createRandomParticle(greenOnBlue, yellowOnBlue, blueOnBlue, redOnBlue, 'b'));
particles.add(Particle.createRandomParticle(greenOnRed, yellowOnRed, blueOnRed, redOnRed, 'r'));
}
new visuals();
while(true) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public static double randomValue() {
//return 2*(forceConstant * (Math.random()-.5));
return -0.2011023416280407;
}
public void addParticle(Particle particle) {
particles.add(particle);
}
public visuals() {
setSize(1500, 800);
setVisible(true);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.exit(0);
}
});
Thread loop = new Thread(new Runnable() {
public void run() {
while (true) {
repaint();
try {
Thread.sleep(30);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
});
loop.start();
}
private Image buffer;
@Override
public void update(Graphics g) {
if (buffer == null) {
buffer = createImage(getWidth(), getHeight());
}
Graphics bufferGraphics = buffer.getGraphics();
// Clear and draw everything on the buffer
bufferGraphics.clearRect(0, 0, getWidth(), getHeight());
paint(bufferGraphics);
// Draw the buffer onto the screen
g.drawImage(buffer, 0, 0, this);
}
public void paint(Graphics g) {
g.clearRect(0, 0, getWidth(), getHeight());
g.drawRect(50,50,1353,703);
for(Particle particle : particles) {
particle.moveX(particles);
particle.moveY(particles);
particle.draw(g);
}
}
}