package myClass;
import java.awt.*;
public class myGraphics {
double PI;
public void drawLine(Graphics g, int x0, int y0, int x, int y, String str, Color color,
Font font) {
Color oldcolor = g.getColor();
Font oldfont = g.getFont();
g.drawLine(x0, y0, x, y);
g.setColor(color);
g.setFont(font);
if(x > x0)
g.drawString(str, (x0 + x + 20) / 2, (y0 + y) / 2);
else
g.drawString(str, ((x0 + x) - 20) / 2, (y0 + y) / 2);
g.setColor(oldcolor);
g.setFont(oldfont);
}
public void drawAngleline(Graphics g, int x0, int y0, int len, double angle) {
int x = x0 + (int)((double)len * Math.cos(angle));
int y = y0 + (int)((double)len * Math.sin(angle));
g.drawLine(x0, y0, x, y);
}
public void drawArrow(Graphics g, int x0, int y0, int x, int y) {
Font font1 = new Font("Dialog", 1, 15);
drawArrow(g, x0, y0, x, y, " ", Color.black, font1);
}
public void drawArrow(Graphics g, int x0, int y0, int x, int y, String str, Color color,
Font font) {
int s = 8;
double a = PI / 12D;
Color oldcolor = g.getColor();
Font oldfont = g.getFont();
double angle = angleOfline(x0, y0, x, y);
g.drawLine(x0, y0, x, y);
if(angle <= PI / 2D) {
drawAngleline(g, x, y, s, (PI / 2D + angle) - a);
drawAngleline(g, x, y, s, PI / 2D + angle + a);
} else {
drawAngleline(g, x, y, s, angle - PI / 2D - a);
drawAngleline(g, x, y, s, (angle - PI / 2D) + a);
}
g.setColor(color);
g.setFont(font);
if(x > x0)
g.drawString(str, (x0 + x + 20) / 2, (y0 + y) / 2);
else
g.drawString(str, ((x0 + x) - 20) / 2, (y0 + y) / 2);
g.setColor(oldcolor);
g.setFont(oldfont);
}
public void drawArrow(Graphics g, int x0, int y0, int len, double angle) {
Font font1 = new Font("Dialog", 1, 15);
drawArrow(g, x0, y0, len, angle, " ", Color.black, font1);
}
public void drawArrow(Graphics g, int x0, int y0, int len, double angle, String str,
Color color, Font font) {
int s = 8;
double a = PI / 12D;
Color oldcolor = g.getColor();
Font oldfont = g.getFont();
drawAngleline(g, x0, y0, len, angle);
int x = x0 + (int)((double)len * Math.cos(angle));
int y = y0 + (int)((double)len * Math.sin(angle));
if(angle <= PI / 2D) {
drawAngleline(g, x, y, s, (PI / 2D + angle) - a);
drawAngleline(g, x, y, s, PI / 2D + angle + a);
g.setColor(color);
g.setFont(font);
g.drawString(str, x, y + 15);
} else {
drawAngleline(g, x, y, s, angle - PI / 2D - a);
drawAngleline(g, x, y, s, (angle - PI / 2D) + a);
g.setColor(color);
g.setFont(font);
g.drawString(str, x, y - 10);
}
g.setColor(oldcolor);
g.setFont(oldfont);
}
public void drawCircle(Graphics g, int x, int y, int r, int startAngle, int arcAngle) {
g.drawArc(x - r, y - r, 2 * r, 2 * r, startAngle, arcAngle);
}
public void drawMarrow(Graphics g, int x0, int y0, int len, double angle, String str,
Color color, Font font) {
int s = 8;
double a = PI / 12D;
Color oldcolor = g.getColor();
Font oldfont = g.getFont();
drawAnglemline(g, x0, y0, len, angle);
int x = x0 + (int)((double)len * Math.cos(angle));
int y = y0 + (int)((double)len * Math.sin(angle));
if(angle <= PI / 2D) {
drawAngleline(g, x, y, s, (PI / 2D + angle) - a);
drawAngleline(g, x, y, s, PI / 2D + angle + a);
g.setColor(color);
g.setFont(font);
g.drawString(str, x, y + 15);
} else {
drawAngleline(g, x, y, s, angle - PI / 2D - a);
drawAngleline(g, x, y, s, (angle - PI / 2D) + a);
g.setColor(color);
g.setFont(font);
g.drawString(str, x, y - 10);
}
g.setColor(oldcolor);
g.setFont(oldfont);
}
public void drawFillarrow(Graphics g, int x0, int y0, double angle) {
int s = 10;
int x[] = new int[3];
int y[] = new int[3];
double a = PI / 12D;
Color oldcolor = g.getColor();
g.setColor(Color.red);
x[0] = x0;
y[0] = y0;
if(angle <= PI / 2D) {
x[1] = x[0] + (int)((double)s * Math.cos((PI / 2D + angle) - a));
y[1] = y[0] + (int)((double)s * Math.sin((PI / 2D + angle) - a));
x[2] = x[0] + (int)((double)s * Math.cos(PI / 2D + angle + a));
y[2] = y[0] + (int)((double)s * Math.sin(PI / 2D + angle + a));
} else {
x[1] = x[0] + (int)((double)s * Math.cos(angle - PI / 2D - a));
y[1] = y[0] + (int)((double)s * Math.sin(angle - PI / 2D - a));
x[2] = x[0] + (int)((double)s * Math.cos((angle - PI / 2D) + a));
y[2] = y[0] + (int)((double)s * Math.sin((angle - PI / 2D) + a));
}
g.fillPolygon(x, y, 3);
g.setColor(oldcolor);
}
public void drawMline(Graphics g, int x0, int y0, int x, int y,double step) {
double m1 = Math.sqrt((x - x0) * (x - x0) + (y - y0) * (y - y0));
int num = (int)(m1 / step);
int x1 = x0;
int y1 = y0;
for(int i = 0; i < num; i++) {
int x2 = x0 + (int)Math.round((double)(step * (i + 1) * (x - x0)) / m1);
int y2 = y0 + (int)Math.round((double)(step * (i + 1) * (y - y0)) / m1);
if(i % 2 == 0)
g.drawLine(x1, y1, x2, y2);
x1 = x2;
y1 = y2;
}
}
public void drawAnglemline(Graphics g, int x0, int y0, int len, double angle) {
int x = x0 + (int)((double)len * Math.cos(angle));
int y = y0 + (int)((double)len * Math.sin(angle));
// drawMline(g, x0, y0, x, y);
}
public double angleOfline(int x0, int y0, int x, int y) {
double s = Math.sqrt((x - x0) * (x - x0) + (y - y0) * (y - y0));
double angle = Math.acos((double)(x - x0) / s);
if(y >= y0)
return angle;
else
return PI - angle;
}
public double angleOfoval(int x, int y, int x0, int y0, int a, int b) {
double s = Math.sqrt(Math.pow(b, 4D) * (double)(x - x0) * (double)(x - x0) + Math.pow(a, 4D) * (double)(y - y0) * (double)(y - y0));
double angle = Math.acos((double)(a * a * (y - y0)) / s);
if(x >= x0)
return PI - angle;
else
return angle;
}
public myGraphics() {
PI = 6.2831852000000001D;
}
public void fillCircle(Graphics g, int x0, int y0, int r, Color color) {
Color oldcolor = g.getColor();
g.setColor(color);
g.fillArc(x0 - r, y0 - r, 2 * r, 2 * r, 0, 360);
g.setColor(oldcolor);
}
public void fillCircle(Graphics g, int x0, int y0,int l, int r, Color color1,Color color2,double angle) {
Color oldcolor = g.getColor();
int x1=x0-(int)(r+l*Math.cos(angle));
int y1=y0-(int)(r+l*Math.sin(angle));
g.setColor(color1);
g.fillOval(x1,y1,2*r,2*r);
g.setColor(oldcolor);
}
public void Bar(Graphics g,int x,int y,int w,int h,int type)
{
if (type==0)
g.setColor(Color.white);
if (type==1)
g.setColor(Color.black);
g.drawLine(x,y,x+w,y);
g.drawLine(x,y,x,y+h);
if (type==1)
g.setColor(Color.white);
if (type==0)
g.setColor(Color.black);
g.drawLine(x+w,y,x+w,y+h);
g.draw