- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComponents2.java
More file actions
Latest commit
87 lines (82 loc) · 3.45 KB
/
Copy pathComponents2.java
File metadata and controls
87 lines (82 loc) · 3.45 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
importjavax.swing.*;
importjava.awt.*;
importjava.awt.geom.*;
importjava.awt.image.*;
importjava.awt.event.*;
importjava.io.*;
importjava.util.*;
publicclassComponents2extendsJPanel {
privateint[][] m;
privateArrayList<SquareGUI> s;
privateArrayList<FieldPartition> pf;
privateParticlepart;
publicComponents2(int[][] map, boolean[][] mp, ArrayList<FieldPartition> pf) {
this.m = map;
this.s = newArrayList<SquareGUI>();
for(int[] i:m) {
s.add(newSquareGUI(i[0], i[1], mp[i[0]][i[1]]));
}
this.pf = pf;
double[] v = newdouble[2];
doubled = pf.get(0).deriv(pf.get(0).xDom()[1]);
v[0] = -1.0/Math.sqrt(1.0+d*d);
v[1] = -d/Math.sqrt(1.0+d*d);
if(Math.signum(v[0]) != 1) {
d = pf.get(0).deriv(pf.get(0).xDom()[0]);
v[0] = 1.0/Math.sqrt(1.0+d*d);
v[1] = d/Math.sqrt(1.0+d*d);
}
part = newParticle(pf.get(0).xDom()[1], pf.get(0).point(pf.get(0).xDom()[1]), v, pf);
}
publicvoidstep() {
part.step();
this.repaint();
}
privatevoidpaintFieldLines(Graphicsg) {
g.setColor(newColor(200, 50, 50));
for(int[] i:m) {
for(FieldPartitionfp:pf) {
double[] point = newdouble[2];
point[0] = i[0]+0.5;
point[1] = i[1]+0.5;
if(fp.inDomain(point)) {
//g.drawLine((int)(point[0]*Viewer2.size+Viewer2.ox),(int)(point[1]*Viewer2.size+Viewer2.oy), (int)(point[0]*Viewer2.size+Viewer2.ox+10*fp.getAccel(point)[0]), (int)(point[1]*Viewer2.size+Viewer2.oy+10*fp.getAccel(point)[1]));
}
}
}
}
publicvoidpaintComponent(Graphicsg) {
super.paintComponent(g);
for(SquareGUIi:s) {
i.draw(g);
}
for(FieldPartitionpt:pf) {
try {
//pt = (Link)pt;
g.setColor(newColor(0, 125, 255));
/*for(double x = 0.5; x < p[p.length-1][0]+0.5; x += 1.0/Viewer2.size) {
g.fillRect((int)(x*Viewer2.size+Viewer2.ox), (int)(pt.point(x)*Viewer2.size+Viewer2.oy), 1, 3);
}*/
//pt = (PathField)pt;
for(doublex = pt.xDom()[0]; x<pt.xDom()[1]; x+=1.0/Viewer2.size) {
g.fillRect((int)(x*Viewer2.size+Viewer2.ox), (int)(pt.point(x)*Viewer2.size+Viewer2.oy), 1, 3);
}
} catch(Exceptione) {
/*g.setColor(new Color(255, 125, 255));
/*for(double x = 0.5; x < p[p.length-1][0]+0.5; x += 1.0/Viewer2.size) {
g.fillRect((int)(x*Viewer2.size+Viewer2.ox), (int)(pt.point(x)*Viewer2.size+Viewer2.oy), 1, 3);
}*//*
for(double x = pt.xDom()[0]; x<pt.xDom()[1]; x+=1.0/Viewer2.size) {
g.fillRect((int)(x*Viewer2.size+Viewer2.ox), (int)(pt.point(x)*Viewer2.size+Viewer2.oy), 1, 3);
}*/
}
try {
pt = (LinkC)pt;
((LinkC)pt).draw(g);
} catch(Exceptione) {}
}
// this.paintFieldLines(g);
part.draw(g);
// g.drawLine((int)(part.getX()*Viewer2.size+Viewer2.ox),(int)(part.getY()*Viewer2.size+Viewer2.oy), (int)(part.getX()*Viewer2.size+Viewer2.ox+50*pf.get(1).getAccel(part.getPos())[0]), (int)(part.getY()*Viewer2.size+Viewer2.oy+50*pf.get(1).getAccel(part.getPos())[1]));
}
}