-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphysicscalc.java
More file actions
80 lines (68 loc) · 1.98 KB
/
physicscalc.java
File metadata and controls
80 lines (68 loc) · 1.98 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
import javax.swing.JFrame;
import java.awt.*;
import java.awt.Color;
import static java.lang.Math.cos;
import static java.lang.Math.sin;
import static java.lang.Math.sqrt;
import static java.lang.Math.pow;
import java.util.Scanner;
class physicscalc extends JFrame
{
private static Graphics gBuf = null;
private static GraphPaperCanvas canvas = null;
private static Image vm = null;
private int x, y;
private int w, h;
public physicscalc( int x, int y )
{
if ( canvas == null )
{
setTitle("Projectile Trajectory Graph");
setSize(625,645);
setLocation(20,50);
canvas = new GraphPaperCanvas(null);
getContentPane().add(canvas);
setVisible(true);
vm = canvas.createImage(2200,1900);
gBuf = vm.getGraphics();
canvas.setVm(vm);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
this.x = x;
this.y = y;
w = 600;
h = 600;
drawBounds();
gBuf.setColor( Color.BLUE );
}
public void drawBounds()
{
Color cur = gBuf.getColor();
gBuf.setColor( Color.LIGHT_GRAY );
for ( int d=0; d<w; d+=w/50 )
gBuf.drawLine( x+d, y+0, x+d, y+h );
for ( int d=0; d<h; d+=h/50 )
gBuf.drawLine( x+0, y+d, x+h, y+d );
gBuf.setColor( Color.BLACK );
gBuf.drawRect( x, y, w+1, h+1 );
gBuf.drawLine( x+w/2, y+0, x+w/2, y+h );
gBuf.drawLine( x+0, y+h/2, x+w, y+h/2 );
gBuf.setColor( cur );
canvas.repaint();
}
public void setColor( Color c )
{
gBuf.setColor(c);
}
public void drawPoint( double px, double py )
{
if ( px > 50 || px < -50 || py > 50 || py < -50 )
return;
px *= w/50;
py *= h/50;
px += w/2 + 1;
py = h/2 - py + 1;
gBuf.drawLine( x+(int)px, y+(int)py, x+(int)px, y+(int)py );
canvas.repaint();
}
}