绘图类
import javax.swing.*;
import java.awt.*;
import java.awt.image.*;
import static java.lang.Math.*;
public class GenerateGraph{
private int x_axis=50;
private int y_axis=50;
double div;
private int scale=10;
public BufferedImage image;
public GenerateGraph(){
}
public void drawGraph(int width, int height){
//创建图像栅格
this.image=new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
WritableRaster raster=image.getRaster();
ColorModel model=image.getColorModel();
Color curvecolor=Color.red;
int argb=curvecolor.getRGB();
//依据颜色模型获取颜色数据
Object colordata=model.getDataElements(argb, null);
int backgroundcolor[]={
255, 255, 255, 255};//背景颜色
int axiscolor[]={
0, 0, 0, 255};//坐标轴颜色
for (int i=0;i<width;i++){
raster.setPixel(i, height-x_axis, axiscolor);
if (i%scale==0){
raster.setPixel(i, height-x_axis-1, axiscolor);
raster.setPixel(i, height-x_axis-2, axiscolor);
raster.setPixel(i, height-x_axis-3, axiscolor);
}//may occur out of bound exception!
}//绘制x轴
for (int j=0;j<height;j++){
raster.setPixel(y_axis, j, axiscolor);
if (j%scale==0){
raster.setPixel(y_axis+1, j, axiscolor);
raster