Random random = new Random();
int x = 20;
int y = 20;
for(int i=0;i<4;i++){
// void rotate(double theta, double x, double y)
// theta 弧度
// hudu = jiaodu * Math.PI / 180;
// 获取正负30之间的角度
int jiaodu = random.nextInt(60)-30;
double hudu = jiaodu * Math.PI / 180;
g.rotate(hudu, x, y);
// 获取下标
int index = random.nextInt(words.length());
// 返回指定下标位置的字符,随机获取下标
char ch = words.charAt(index);
// 写字符串
g.drawString(""+ch, x, y);
g.rotate(-hudu, x, y);//为什么加减号就返回0位置了?
x += 20;
}
// 设置颜色
g.setColor(Color.GREEN);
int x1,x2,y1,y2;
// 画干扰线
for(int i=0;i<4;i++){
x1 = random.nextInt(width);
y1 = random.nextInt(height);
x2 = random.nextInt(width);
y2 = random.nextInt(height);
g.drawLine(x1, y1, x2, y2);
}
// 输出到客户端
ImageIO.write(image, "jpg", response.getOutputStream());