-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpaint.java
More file actions
87 lines (85 loc) · 2.34 KB
/
Copy pathpaint.java
File metadata and controls
87 lines (85 loc) · 2.34 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
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
public class paint extends JPanel{
static int width = 400;
static int height = 400;
private static final long serialVersionUID = 1L;
float[] origX;
float[] origY;
float[] x;
float[] y;
int[] ans;
int[] gs;
float[] w;
paint(Point2D.Float[] pointsArray,int[] calculatedAnswers, int[] guessArray, float[] weights){
w=new float[weights.length];
w=weights.clone();
x=new float[pointsArray.length];
y=new float[pointsArray.length];
origX=new float[pointsArray.length];
origY=new float[pointsArray.length];
ans=new int[pointsArray.length];
gs=new int[pointsArray.length];
for(int i=0; i<pointsArray.length;i++){
origX[i]=pointsArray[i].x;
x[i]=toPixelPlane(pointsArray[i]).x;
origY[i]=pointsArray[i].y;
y[i]=toPixelPlane(pointsArray[i]).y;
ans[i]=calculatedAnswers[i];
gs[i]=guessArray[i];
}
}
public void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
Ellipse2D.Float outerCircle = new Ellipse2D.Float();
Ellipse2D.Float innerCircle = new Ellipse2D.Float();
Point2D.Float pt1 = new Point2D.Float(width, f(width));
Point2D.Float pt2 = new Point2D.Float(-width, f(-width));
Line2D.Float line = new Line2D.Float(toPixelPlane(pt1), toPixelPlane(pt2));
g2d.draw(line);
Point2D.Float pt3 = new Point2D.Float(width, wf(width));
Point2D.Float pt4 = new Point2D.Float(-width, wf(-width));
Line2D.Float lineAbstract = new Line2D.Float(toPixelPlane(pt3), toPixelPlane(pt4));
g2d.draw(lineAbstract);
for(int i=0;i<x.length;i++){
g2d.setPaint(Color.black);
outerCircle.setFrame(x[i]-12, y[i]-12, 24f, 24f);
if(f(origX[i])>=origY[i]){
g2d.draw(outerCircle);
}
else{
g2d.fill(outerCircle);
}
innerCircle.setFrame(x[i]-4, y[i]-4, 8f, 8f);
if(ans[i]==gs[i]){
g2d.setPaint(Color.green);
}
else{
g2d.setPaint(Color.red);
}
g2d.fill(innerCircle);
}
}
//
// interface FunctionCaller{
// public float fxn(float z);
// }
// private float operate(float z, FunctionCaller f){
// return f.fxn(z);
// }
//
public Point2D.Float toPixelPlane(Point2D.Float p){
return new Point2D.Float(p.x+width,mod(p.y-height));
}
public float mod(float n){
return n<0?-n:n;
}
public static float f(float x){
return 0.2f*x+0.364f;
}
public float wf(float x){
return (-w[0]*x-w[2])/w[1];
}
}