⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ovalportrayal2d.java

📁 MASON代表多主体邻里或网络仿真(Multi-Agent Simulator of Neighborhoods or Networks)。它是乔治梅森大学用Java开发的离散事件多主体仿真核心库
💻 JAVA
字号:
package sim.portrayal.simple;import sim.portrayal.*;import java.awt.*;import java.awt.geom.*;/**   A simple portrayal for 2D visualization of ovals. It extends the SimplePortrayal2D and   it manages the drawing and hit-testing for oval shapes.*/public class OvalPortrayal2D extends SimplePortrayal2D    {    public Paint paint;    public double scale;        public OvalPortrayal2D() { this(Color.gray,1.0); }    public OvalPortrayal2D(Paint paint) { this(paint,1.0); }    public OvalPortrayal2D(double scale) { this(Color.gray,scale); }        public OvalPortrayal2D(Paint paint, double scale)        {        this.paint = paint;        this.scale = scale;        }        // assumes the graphics already has its color set    public void draw(Object object, Graphics2D graphics, DrawInfo2D info)        {        final double width = info.draw.width*scale;        final double height = info.draw.height*scale;        graphics.setPaint(paint);        // we are doing a simple draw, so we ignore the info.clip        final int x = (int)(info.draw.x - width / 2.0);        final int y = (int)(info.draw.y - height / 2.0);        final int w = (int)(width);        final int h = (int)(height);        // draw centered on the origin        graphics.fillOval(x,y,w, h);        //System.out.println(""+x+" "+y+" "+w+" "+h);        }    /** If drawing area intersects selected area, add last portrayed object to the bag */    public boolean hitObject(Object object, DrawInfo2D range)        {        final double SLOP = 1.0;  // need a little extra area to hit objects        final double width = range.draw.width*scale;        final double height = range.draw.height*scale;        Ellipse2D.Double ellipse = new Ellipse2D.Double( range.draw.x-width/2-SLOP, range.draw.y-height/2-SLOP, width+SLOP*2,height+SLOP*2 );        return ( ellipse.intersects( range.clip.x, range.clip.y, range.clip.width, range.clip.height ) );        }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -