独行之狼
3 years ago
21 changed files with 579 additions and 69 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,84 @@
|
||||
package com.fr.plugin.cool.cartnoon; |
||||
|
||||
import com.fr.intelli.record.Focus; |
||||
import com.fr.intelli.record.Original; |
||||
import com.fr.plugin.cool.cartnoon.utils.AnimatedGifEncoder; |
||||
import com.fr.plugin.cool.cartnoon.utils.DrawValueLine; |
||||
import com.fr.plugin.cool.cartnoon.web.ImageViewer; |
||||
import com.fr.record.analyzer.EnableMetrics; |
||||
import com.fr.script.AbstractFunction; |
||||
import com.fr.stable.ColumnRow; |
||||
import com.fr.stable.Primitive; |
||||
import com.fr.stable.fun.Authorize; |
||||
import net.coobird.thumbnailator.Thumbnails; |
||||
|
||||
import java.awt.*; |
||||
import java.awt.image.BufferedImage; |
||||
import java.io.ByteArrayOutputStream; |
||||
import java.io.IOException; |
||||
|
||||
@EnableMetrics |
||||
@Authorize(callSignKey = FunConstants.PLUGIN_ID) |
||||
public class FRAnimateArraow extends AbstractFunction { |
||||
@Override |
||||
@Focus(id = FunConstants.PLUGIN_ID, text = "Plugin-Function_FRAnimateArraow", source = Original.PLUGIN) |
||||
public Object run(Object[] args) { |
||||
if(!FunConstants.Author()){ |
||||
return FunConstants.AUTHOR_ERROR; |
||||
} |
||||
if(!FunConstants.CheckArgs(args,4)){ |
||||
return Primitive.ERROR_VALUE; |
||||
} |
||||
|
||||
final int width= Integer.parseInt(args[0].toString()); |
||||
final int height= Integer.parseInt(args[1].toString()); |
||||
final Color color = FunConstants.TextToColor(args[2].toString()); |
||||
final int stroke= Integer.parseInt(args[3].toString()); |
||||
|
||||
final String id=FunConstants.GetCellId(this); |
||||
final String url="/webroot/decision/url/img?id="+id; |
||||
|
||||
try { |
||||
CreateAnimateArra(id,width,height,color,stroke); |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
return "<img src=\""+url+"\" width=\""+width+"\" height=\""+height+"\" />"; |
||||
|
||||
} |
||||
private void CreateAnimateArra(String id,int width,int height,Color color,int stroke) throws IOException { |
||||
// 读数据
|
||||
AnimatedGifEncoder e = new AnimatedGifEncoder(); |
||||
|
||||
ByteArrayOutputStream out=new ByteArrayOutputStream(); |
||||
e.start(out); |
||||
e.setTransparent(new Color(255,255,255)); |
||||
//图片之间间隔时间
|
||||
e.setDelay(100); // 1 frame per sec
|
||||
//重复次数 0表示无限重复 默认不重复
|
||||
e.setRepeat(0); |
||||
//添加图片
|
||||
|
||||
int arraLen=width*8/10; |
||||
int len=arraLen/10; |
||||
for (int i = 1; i <= len; i++) { |
||||
final BufferedImage image = new BufferedImage(width,height,BufferedImage.TYPE_INT_ARGB); |
||||
e.addFrame(setFilter(image,i*10,stroke,stroke*2,color)); |
||||
} |
||||
e.finish(); |
||||
|
||||
byte[] data = out.toByteArray(); |
||||
ImageViewer.gifData.put(id,data); |
||||
} |
||||
//生成箭头
|
||||
private BufferedImage setFilter(BufferedImage src,int arraLen, float stroke, double alh,Color color) { |
||||
int sx=src.getWidth()/10; |
||||
int sy=src.getHeight()/10; |
||||
int ex=sx+arraLen; |
||||
int ey=sy; |
||||
DrawValueLine drawValueLine= new DrawValueLine(src,sx,sy,ex,ey,alh); |
||||
drawValueLine.DrawLine(stroke,color); |
||||
return src; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,32 @@
|
||||
package com.fr.plugin.cool.cartnoon; |
||||
|
||||
import com.fr.intelli.record.Focus; |
||||
import com.fr.record.analyzer.EnableMetrics; |
||||
import com.fr.stable.fun.Authorize; |
||||
import com.fr.stable.fun.impl.AbstractFunctionDefContainer; |
||||
import com.fr.stable.script.FunctionDef; |
||||
@EnableMetrics |
||||
@Authorize(callSignKey = FunConstants.PLUGIN_ID) |
||||
public class FRCartnoonFunctions extends AbstractFunctionDefContainer { |
||||
@Override |
||||
@Focus(id=FunConstants.PLUGIN_ID, text="字符动画函数") |
||||
public FunctionDef[] getFunctionDefs() { |
||||
return new FunctionDef[]{ |
||||
new FunctionDef("FRPrintText", "生成打字机动画效果。\n参数说明:\n参数1:字符型,打字的文本。\n参数2:整型,显示宽度。\n参数3:整型,显示高度。\n参数4:整型,文本字号。\n参数5:整型,动画刷新频率(毫秒)。\n示例:FRPrintText(\"123456790\",500,100,20,100,\"ffff00\")", FRPrintText.class.getName()), |
||||
new FunctionDef("FRRollText", "生成浮动文本动画效果。\n参数说明:\n参数1:字符型,要浮动的文本。\n参数2:整型,文本字号。\n参数3:字符型,文本颜色。\n示例:FRRollText(\"2021\",25,\"ff0000\")", FRRollText.class.getName()), |
||||
new FunctionDef("FRDissolveText", "生成溶解文本动画效果。\n参数说明:\n参数1:字符型,要溶解的文本。\n参数2:整型,文本宽度。\n参数3:整型,文本高度。\n参数4:整型,文本字号。\n参数5:整型,动画刷新频率(毫秒)。\n示例:FRDissolveText(\"88888888888\",180,50,25,300,\"ff0000\")", FRDissolveText.class.getName()), |
||||
new FunctionDef("FRRotateText", "生成旋转文本动画效果。\n参数说明:\n参数1:字符型,要旋转的文本。\n参数2:整型,文本宽度。\n参数3:整型,文本高度。\n参数4:整型,文本字号。\n参数5:整型,动画刷新频率(毫秒)。\n示例:FRRotateText(\"你好,世界\",180,180,25,300,\"ff0000\")", FRRotateText.class.getName()), |
||||
new FunctionDef("FRAnimateArraow", "生成箭头动画效果。\n参数说明:\n参数1:整型,页面占用宽度。\n参数2:整型,页面占用高度。\n参数3:文本,箭头颜色,如FF0000。\n参数4:整型,箭头粗细。\n示例:FRAnimateArraow(300,200,\"ff0000\",10)", FRAnimateArraow.class.getName()), |
||||
new FunctionDef("FRCountUp", "生成数字计数动画效果。\n参数说明:\n参数1:整型,要计数的数字。\n参数2:整型,显示宽度。\n参数3:整型,显示高度。\n参数4:整型,文本字号。\n参数5:整型,动画刷新频率(毫秒)。\n示例:FRCountUp(\"123456790\",500,100,20,100,\"ffff00\")", FRCountUp.class.getName()), |
||||
|
||||
}; |
||||
} |
||||
|
||||
@Override |
||||
public String getGroupName() { |
||||
if (!FunConstants.Author()) { |
||||
return FunConstants.AUTHOR_ERROR; |
||||
} |
||||
return "字符动画函数"; |
||||
} |
||||
} |
@ -0,0 +1,42 @@
|
||||
package com.fr.plugin.cool.cartnoon; |
||||
|
||||
import com.fr.intelli.record.Focus; |
||||
import com.fr.intelli.record.Original; |
||||
import com.fr.record.analyzer.EnableMetrics; |
||||
import com.fr.script.AbstractFunction; |
||||
import com.fr.stable.Primitive; |
||||
import com.fr.stable.fun.Authorize; |
||||
|
||||
import java.awt.*; |
||||
|
||||
@EnableMetrics |
||||
@Authorize(callSignKey = FunConstants.PLUGIN_ID) |
||||
public class FRCountUp extends AbstractFunction { |
||||
@Override |
||||
@Focus(id = FunConstants.PLUGIN_ID, text = "Plugin-Function_FRCountUp", source = Original.PLUGIN) |
||||
public Object run(Object[] args) { |
||||
if(!FunConstants.Author()){ |
||||
return FunConstants.AUTHOR_ERROR; |
||||
} |
||||
if(!FunConstants.CheckArgs(args,6)){ |
||||
return Primitive.ERROR_VALUE; |
||||
} |
||||
final Integer number = Integer.parseInt(args[0].toString()); |
||||
|
||||
int width= Integer.parseInt(args[1].toString()); |
||||
int height= Integer.parseInt(args[2].toString()); |
||||
int fontSize= Integer.parseInt(args[3].toString()); |
||||
int rate= Integer.parseInt(args[4].toString()); |
||||
final Color color = FunConstants.TextToColor(args[5].toString()); |
||||
|
||||
final String id=FunConstants.GetCellId(this); |
||||
final String url="/webroot/decision/url/img?id="+id; |
||||
|
||||
FunConstants.CreateCountUpAnimate(id,number,fontSize,rate,color,width); |
||||
return "<img src=\""+url+"\" width=\""+width+"\" height=\""+height+"\" />"; |
||||
|
||||
} |
||||
|
||||
|
||||
|
||||
} |
@ -0,0 +1,78 @@
|
||||
package com.fr.plugin.cool.cartnoon; |
||||
|
||||
import com.fr.intelli.record.Focus; |
||||
import com.fr.intelli.record.Original; |
||||
import com.fr.plugin.cool.cartnoon.utils.AnimatedGifEncoder; |
||||
import com.fr.plugin.cool.cartnoon.web.ImageViewer; |
||||
import com.fr.record.analyzer.EnableMetrics; |
||||
import com.fr.script.AbstractFunction; |
||||
import com.fr.stable.ColumnRow; |
||||
import com.fr.stable.Primitive; |
||||
import com.fr.stable.fun.Authorize; |
||||
import com.jhlabs.image.DissolveFilter; |
||||
|
||||
import java.awt.*; |
||||
import java.awt.image.BufferedImage; |
||||
import java.io.ByteArrayOutputStream; |
||||
|
||||
@EnableMetrics |
||||
@Authorize(callSignKey = FunConstants.PLUGIN_ID) |
||||
public class FRDissolveText extends AbstractFunction { |
||||
@Override |
||||
@Focus(id = FunConstants.PLUGIN_ID, text = "Plugin-Function_FRDissolveText", source = Original.PLUGIN) |
||||
public Object run(Object[] args) { |
||||
if(!FunConstants.Author()){ |
||||
return FunConstants.AUTHOR_ERROR; |
||||
} |
||||
if(!FunConstants.CheckArgs(args,6)){ |
||||
return Primitive.ERROR_VALUE; |
||||
} |
||||
final String text = args[0].toString(); |
||||
|
||||
int width= Integer.parseInt(args[1].toString()); |
||||
int height= Integer.parseInt(args[2].toString()); |
||||
int fontSize= Integer.parseInt(args[3].toString()); |
||||
int rate= Integer.parseInt(args[4].toString()); |
||||
final Color color = FunConstants.TextToColor(args[5].toString()); |
||||
|
||||
final String id=FunConstants.GetCellId(this); |
||||
final String url="/webroot/decision/url/img?id="+id; |
||||
|
||||
CreateDissoveText(id,text,fontSize,rate,color,width); |
||||
return "<img src=\""+url+"\" width=\""+width+"\" height=\""+height+"\" />"; |
||||
|
||||
} |
||||
private void CreateDissoveText(String id,String text,int fontSize,int rate,Color color,int width) { |
||||
|
||||
// 读数据
|
||||
AnimatedGifEncoder e = new AnimatedGifEncoder(); |
||||
|
||||
ByteArrayOutputStream out=new ByteArrayOutputStream(); |
||||
e.start(out); |
||||
|
||||
//图片之间间隔时间
|
||||
e.setDelay(rate); // 1 frame per sec
|
||||
//重复次数 0表示无限重复 默认不重复
|
||||
e.setRepeat(0); |
||||
//添加图片
|
||||
final BufferedImage image = FunConstants.ImageFromText(text, fontSize, color, width); |
||||
for (float i = 0; i <= 9; i++) { |
||||
float v=i/10; |
||||
e.addFrame(setFilter(image,v,v)); |
||||
} |
||||
e.finish(); |
||||
|
||||
byte[] data = out.toByteArray(); |
||||
ImageViewer.gifData.put(id,data); |
||||
} |
||||
//设置图像溶解效果
|
||||
private BufferedImage setFilter(BufferedImage src, float density, float softness) { |
||||
BufferedImage result = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_4BYTE_ABGR); |
||||
DissolveFilter dissolveFilter = new DissolveFilter(); |
||||
dissolveFilter.setDensity(density); |
||||
dissolveFilter.setSoftness(softness); |
||||
dissolveFilter.filter(src, result); |
||||
return result; |
||||
} |
||||
|
||||
} |
@ -1,19 +0,0 @@
|
||||
package com.fr.plugin.cool.cartnoon; |
||||
|
||||
import com.fr.stable.fun.impl.AbstractFunctionDefContainer; |
||||
import com.fr.stable.script.FunctionDef; |
||||
|
||||
public class FREncryptorFunction extends AbstractFunctionDefContainer { |
||||
@Override |
||||
public FunctionDef[] getFunctionDefs() { |
||||
return new FunctionDef[]{ |
||||
new FunctionDef("FRCoolGif", "FRCoolGif(varchar1,varchar2,logical3):生成Gif。", FRCoolGif.class.getName()), |
||||
new FunctionDef("FRRollNumber", "FRRollNumber(varchar1,varchar2,logical3):生成Gif。", FRRollNumber.class.getName()), |
||||
}; |
||||
} |
||||
|
||||
@Override |
||||
public String getGroupName() { |
||||
return "字符动画函数"; |
||||
} |
||||
} |
@ -0,0 +1,80 @@
|
||||
package com.fr.plugin.cool.cartnoon; |
||||
|
||||
import com.fr.intelli.record.Focus; |
||||
import com.fr.intelli.record.Original; |
||||
import com.fr.plugin.cool.cartnoon.utils.AnimatedGifEncoder; |
||||
import com.fr.plugin.cool.cartnoon.web.ImageViewer; |
||||
import com.fr.record.analyzer.EnableMetrics; |
||||
import com.fr.script.AbstractFunction; |
||||
import com.fr.stable.Primitive; |
||||
import com.fr.stable.fun.Authorize; |
||||
import net.coobird.thumbnailator.Thumbnails; |
||||
|
||||
import java.awt.*; |
||||
import java.awt.image.BufferedImage; |
||||
import java.io.ByteArrayOutputStream; |
||||
import java.io.IOException; |
||||
|
||||
@EnableMetrics |
||||
@Authorize(callSignKey = FunConstants.PLUGIN_ID) |
||||
public class FRRotateText extends AbstractFunction { |
||||
@Override |
||||
@Focus(id = FunConstants.PLUGIN_ID, text = "Plugin-Function_FRRotateText", source = Original.PLUGIN) |
||||
public Object run(Object[] args) { |
||||
if(!FunConstants.Author()){ |
||||
return FunConstants.AUTHOR_ERROR; |
||||
} |
||||
if(!FunConstants.CheckArgs(args,6)){ |
||||
return Primitive.ERROR_VALUE; |
||||
} |
||||
final String text = args[0].toString(); |
||||
|
||||
int width= Integer.parseInt(args[1].toString()); |
||||
int height= Integer.parseInt(args[2].toString()); |
||||
int fontSize= Integer.parseInt(args[3].toString()); |
||||
int rate= Integer.parseInt(args[4].toString()); |
||||
final Color color = FunConstants.TextToColor(args[5].toString()); |
||||
|
||||
final String id=FunConstants.GetCellId(this); |
||||
final String url="/webroot/decision/url/img?id="+id; |
||||
try { |
||||
CreateText(id,text,fontSize,rate,color); |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
return "<img src=\""+url+"\" width=\""+width+"\" height=\""+height+"\" />"; |
||||
|
||||
} |
||||
|
||||
|
||||
private void CreateText(String id,String text,int fontSize,int rate,Color color) throws IOException { |
||||
|
||||
// 读数据
|
||||
AnimatedGifEncoder e = new AnimatedGifEncoder(); |
||||
|
||||
ByteArrayOutputStream out=new ByteArrayOutputStream(); |
||||
e.start(out); |
||||
|
||||
//图片之间间隔时间
|
||||
e.setDelay(rate); // 1 frame per sec
|
||||
//重复次数 0表示无限重复 默认不重复
|
||||
e.setRepeat(0); |
||||
//添加图片
|
||||
final BufferedImage image = FunConstants.ImageFromMultiText(text, fontSize, color); |
||||
for (float i = 1; i <= 10; i++) { |
||||
// float scale=i/10;
|
||||
float rotate=i*36; |
||||
e.addFrame(setFilter(image,1,rotate)); |
||||
} |
||||
e.finish(); |
||||
|
||||
byte[] data = out.toByteArray(); |
||||
ImageViewer.gifData.put(id,data); |
||||
} |
||||
//设置图像旋转缩放
|
||||
private BufferedImage setFilter(BufferedImage src, float scale, float rotate) throws IOException { |
||||
BufferedImage result = Thumbnails.of(src).scale(scale).rotate(rotate).asBufferedImage(); |
||||
return result; |
||||
} |
||||
|
||||
} |
@ -1,37 +1,77 @@
|
||||
package com.fr.plugin.cool.cartnoon; |
||||
|
||||
import com.fr.base.BaseUtils; |
||||
import com.fr.plugin.cool.cartnoon.utils.AnimatedGifEncoder; |
||||
import com.fr.plugin.cool.cartnoon.utils.DrawValueLine; |
||||
import com.fr.plugin.cool.cartnoon.web.ImageViewer; |
||||
import javafx.scene.shape.Shape3D; |
||||
import net.coobird.thumbnailator.Thumbnails; |
||||
|
||||
import javax.imageio.ImageIO; |
||||
import java.awt.*; |
||||
import java.awt.geom.GeneralPath; |
||||
import java.awt.image.BufferedImage; |
||||
import java.io.*; |
||||
|
||||
public class TestFun { |
||||
public static final int SIZE = 200; |
||||
public static void main(String args[]) throws Exception { |
||||
BufferedImage image1 = ImageIO.read(new File("D:/123.jpg")); |
||||
BufferedImage image2 = ImageIO.read(new File("D:/456.jpg")); |
||||
AnimatedGifEncoder e = new AnimatedGifEncoder(); |
||||
//生成的图片路径
|
||||
// e.start(new FileOutputStream("D:/testgif.gif"));
|
||||
final FileOutputStream fileOutputStream = new FileOutputStream("D:/testgif.gif"); |
||||
ByteArrayOutputStream out=new ByteArrayOutputStream(); |
||||
e.start(out); |
||||
|
||||
//图片之间间隔时间
|
||||
e.setDelay(500); // 1 frame per sec
|
||||
//重复次数 0表示无限重复 默认不重复
|
||||
e.setRepeat(0); |
||||
//添加图片
|
||||
e.addFrame(image1); |
||||
e.addFrame(image2); |
||||
e.finish(); |
||||
|
||||
byte[] data = out.toByteArray(); |
||||
fileOutputStream.write(data); |
||||
ByteArrayInputStream input = new ByteArrayInputStream(data); |
||||
BufferedImage image = ImageIO.read(input); |
||||
File outputfile = new File("d:/bufferimage.gif"); |
||||
ImageIO.write(image, "GIF", outputfile); |
||||
// BufferedImage image1 = new BufferedImage(500, 500, BufferedImage.TYPE_4BYTE_ABGR);
|
||||
// DrawValueLine drawValueLine= new DrawValueLine(image1,50,50,250,50,24.0);
|
||||
// drawValueLine.DrawLine(10);
|
||||
// final BufferedImage image = BaseUtils.readImage("com/fr/plugin/cool/cartnoon/web/resource/images/click.png");
|
||||
BufferedImage image = BaseUtils.readImage("I:\\Users\\Administrator\\2020\\report-starter-10\\plugin-function-char-cartnoon\\src\\com\\fr\\plugin\\cool\\cartnoon\\web\\resource\\images\\click.png"); |
||||
final BufferedImage hour = BaseUtils.readImage("I:\\Users\\Administrator\\2020\\report-starter-10\\plugin-function-char-cartnoon\\src\\com\\fr\\plugin\\cool\\cartnoon\\web\\resource\\images\\hour.png"); |
||||
final BufferedImage minute = BaseUtils.readImage("I:\\Users\\Administrator\\2020\\report-starter-10\\plugin-function-char-cartnoon\\src\\com\\fr\\plugin\\cool\\cartnoon\\web\\resource\\images\\minute.png"); |
||||
image=setSize(image,300,300); |
||||
AnimatedGifEncoder encoder = new AnimatedGifEncoder(); |
||||
encoder.start("d:\\out.gif"); |
||||
encoder.setTransparent(Color.WHITE); |
||||
encoder.setRepeat(0); |
||||
encoder.setDelay(100); |
||||
Graphics2D g2d = image.createGraphics(); |
||||
int x1=image.getWidth()/2; |
||||
int y1=image.getHeight()/2; |
||||
int x2=x1; |
||||
int y2=y1/2; |
||||
int htime=9; |
||||
int mtime=20; |
||||
int hr=htime*(360+30)/12; |
||||
int hrr=htime*360/12; |
||||
int hrm=mtime*30/60; |
||||
int mr=mtime*360/60; |
||||
System.out.printf("\nhrm:"+hrm); |
||||
int o=36; |
||||
for (int i=0; i<=o; i++) { |
||||
g2d.setColor(Color.WHITE); |
||||
|
||||
BufferedImage hImage1=setFilter(hour,1,hrr+i*hrm/o); |
||||
BufferedImage hImage2=setSize(hImage1,image.getWidth(),image.getHeight()); |
||||
g2d.fillRect(x1/2,y1/2,x1,y1); |
||||
g2d.drawImage(hImage2,null,0,0); |
||||
|
||||
BufferedImage mImage1=setFilter(minute,1,i*mr/o); |
||||
BufferedImage mImage2=setSize(mImage1,image.getWidth(),image.getHeight()); |
||||
g2d.drawImage(mImage2,null,0,0); |
||||
encoder.addFrame(image); |
||||
|
||||
} |
||||
for (int i = 0; i <10 ; i++) { |
||||
encoder.addFrame(image); |
||||
} |
||||
|
||||
|
||||
g2d.dispose(); |
||||
encoder.finish(); |
||||
|
||||
} |
||||
//设置图像旋转缩放
|
||||
private static BufferedImage setFilter(BufferedImage src, float scale, float rotate) throws IOException { |
||||
BufferedImage result = Thumbnails.of(src).scale(scale).rotate(rotate).asBufferedImage(); |
||||
return result; |
||||
} |
||||
private static BufferedImage setSize(BufferedImage src, int width, int height) throws IOException { |
||||
BufferedImage result = Thumbnails.of(src).size(width,height).asBufferedImage(); |
||||
return result; |
||||
} |
||||
} |
||||
|
@ -0,0 +1,98 @@
|
||||
package com.fr.plugin.cool.cartnoon.utils; |
||||
|
||||
import java.awt.*; |
||||
import java.awt.geom.AffineTransform; |
||||
import java.awt.geom.GeneralPath; |
||||
import java.awt.image.BufferedImage; |
||||
|
||||
/* |
||||
* |
||||
* 划线 并 |
||||
* */ |
||||
final public class DrawValueLine { |
||||
private int startX; |
||||
private int startY; |
||||
private int endX; |
||||
private int endY; |
||||
private double alHeight; |
||||
private Graphics2D g2; |
||||
|
||||
//划线起止位置
|
||||
public DrawValueLine(BufferedImage image, int sx, int sy, int ex, int ey, double alH) { |
||||
g2 = (Graphics2D) image.getGraphics(); |
||||
startX = sx; |
||||
startY = sy; |
||||
endX = ex; |
||||
endY = ey; |
||||
alHeight = alH; |
||||
} |
||||
|
||||
//划线 (粗细,是否旋转)
|
||||
public void DrawLine(float stroke,Color color) { |
||||
g2.setColor(color); |
||||
g2.setStroke(new BasicStroke(stroke)); |
||||
// g2.drawLine(this.startX, this.startY, this.endX, this.endY);
|
||||
drawAL(this.startX, this.startY , this.endX, this.endY , alHeight); |
||||
|
||||
} |
||||
|
||||
//划箭头线
|
||||
public void drawAL(int sx, int sy, int ex, int ey, double alHeight) { |
||||
|
||||
double L = alHeight / 2; // 底边的一半
|
||||
int x3 = 0; |
||||
int y3 = 0; |
||||
int x4 = 0; |
||||
int y4 = 0; |
||||
double awrad = Math.atan(L / alHeight); // 箭头角度
|
||||
double arraow_len = Math.sqrt(L * L + alHeight * alHeight); // 箭头的长度
|
||||
double[] arrXY_1 = rotateVec(ex - sx, ey - sy, awrad, true, arraow_len); |
||||
double[] arrXY_2 = rotateVec(ex - sx, ey - sy, -awrad, true, arraow_len); |
||||
double x_3 = ex - arrXY_1[0]; // (x3,y3)是第一端点
|
||||
double y_3 = ey - arrXY_1[1]; |
||||
double x_4 = ex - arrXY_2[0]; // (x4,y4)是第二端点
|
||||
double y_4 = ey - arrXY_2[1]; |
||||
|
||||
Double X3 = new Double(x_3); |
||||
x3 = X3.intValue(); |
||||
Double Y3 = new Double(y_3); |
||||
y3 = Y3.intValue(); |
||||
Double X4 = new Double(x_4); |
||||
x4 = X4.intValue(); |
||||
Double Y4 = new Double(y_4); |
||||
y4 = Y4.intValue(); |
||||
// 画线
|
||||
g2.drawLine(sx, sy, ex, ey); |
||||
//
|
||||
GeneralPath triangle = new GeneralPath(); |
||||
double anglRate=(new Double(ey)-new Double(sy))/(new Double(ex)-new Double(sx)); |
||||
double angl=ex==sx?1:Math.atan(anglRate)/Math.PI*2; |
||||
triangle.moveTo(ex+new Double(L)*2*(1-angl), ey+new Double(L)*2*angl); |
||||
triangle.lineTo(x3+new Double(L)*2, y3); |
||||
triangle.lineTo(x4+new Double(L)*2, y4); |
||||
triangle.closePath(); |
||||
//实心箭头
|
||||
g2.fill(triangle); |
||||
|
||||
} |
||||
|
||||
// 计算
|
||||
private static double[] rotateVec(int px, int py, double ang, |
||||
boolean isChLen, double newLen) { |
||||
|
||||
double mathstr[] = new double[2]; |
||||
// 矢量旋转函数,参数含义分别是x分量、y分量、旋转角、是否改变长度、新长度
|
||||
double vx = px * Math.cos(ang) - py * Math.sin(ang); |
||||
double vy = px * Math.sin(ang) + py * Math.cos(ang); |
||||
if (isChLen) { |
||||
double d = Math.sqrt(vx * vx + vy * vy); |
||||
vx = vx / d * newLen; |
||||
vy = vy / d * newLen; |
||||
mathstr[0] = vx; |
||||
mathstr[1] = vy; |
||||
} |
||||
return mathstr; |
||||
|
||||
} |
||||
|
||||
} |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 6.5 KiB |
After Width: | Height: | Size: 6.9 KiB |
Loading…
Reference in new issue