Print

Print


Thank you for answering so fast!

Sean, I appreciate that you send me the code, I tested it and it works as I
wanted, thanks! And yes, I knew that I wasn't specifying any info to MASON
by only storing it. You are right when you pointed that I missunderstood
the purpose of the SimplePortrayals, I thought they could represent also
"areas" and not just "point objects". Having that in mind I know better how
to use them. Thanks!

Russell thanks for the clarification too!


2014-01-28 Russell Thomas <[log in to unmask]>

> Just to clarify for Javier and others:  you place the agent somewhere in
> your grid or space, and then use the "draw" method, below, to render the
> shape relative to the agent's location, measured in pixels.  So if your 2D
> grid is 10 X 10, and the display is 100px X 100px, then every cell in the
> grid is 10px X 10px.  You'd draw your shape (i.e. the rectangle) relative
> to
> the drawing origin of the cell (which is upper left corner, as I recall),
> with positive x to the right and positive y downward.
>
> Also important: this method allows you to draw any arbitrary shape of any
> size, not just something that fits in the cell that an agent would normally
> occupy with SimplePortrayal.
>
> Russ
>
>
> On 1/28/14 9:17 AM, "Sean Luke" <[log in to unmask]> wrote:
>
> > Javier, the fact that you're storing a java.awt.Rectangle in your field
> is
> > immaterial to MASON.  You could have stored a String there, or a Socket,
> for
> > all MASON cared.  In Continuous2D, simple portrayals like
> RectanglePortrayal2D
> > simply represent the objects they're portraying by (typically) drawing
> some
> > kind of shape which fills a 1x1 square region centered at the object's
> > location.  That's why you're seeing a square: because that's what you
> told
> > MASON to do.
> >
> > If you want to draw a rectangle of some sort, you'll need to customize
> > RectanglePortrayal2D to draw a rectangle as appropriate.  Let's say you
> want
> > to use your Rectangle object's width and height (you'll ignore its x and
> y
> > since you already have a specified location for it).  You could override
> the
> > draw method to do something like this:
> >
> >     public void draw(Object object, Graphics2D graphics, DrawInfo2D info)
> >         {
> > Rectangle obj = (Rectangle)object;     // I added this line
> >         Rectangle2D.Double draw = info.draw;
> >         final double width = draw.width*scale * obj.width;  // I
> modified this
> > line
> >         final double height = draw.height*scale * obj.height;  // I
> modified
> > this line
> >
> >         graphics.setPaint(paint);
> >         if (info.precise)
> >             {
> >             if (preciseRectangle == null) preciseRectangle= new
> > Rectangle2D.Double();
> >             preciseRectangle.setFrame(info.draw.x - width/2.0,
> info.draw.y -
> > height/2.0, width, height);
> >             if (filled) graphics.fill(preciseRectangle);
> >             else graphics.draw(preciseRectangle);
> >             return;
> >             }
> >
> >         final int x = (int)(draw.x - width / 2.0);
> >         final int y = (int)(draw.y - height / 2.0);
> >         final int w = (int)(width);
> >         final int h = (int)(height);
> >
> >         if (filled) graphics.fillRect(x,y,w,h);
> >         else graphics.drawRect(x,y,w,h);
> >         }
> >
> > You can do a similar thing for the hit testing function as well.
> >
> > Given that you're trying to specify rectangles and draw them, I think
> you may
> > be misunderstanding the purpose of MASON's SimplePortrayal facility.  The
> > default simple portrayals are really designed for small squarish or point
> > objects; if you want something else you have to make your own custom
> > portrayal.
> >
> > Sean
> >
> >
> >
> >
> > On Jan 28, 2014, at 11:38 AM, Kuu <[log in to unmask]> wrote:
> >
> >> Hello everyone,
> >>
> >> I have the following problem. I'm painting a Continuous2D world (this
> is the
> >> field that I paint) and I have a region in this world that I want to
> draw in
> >> another color, as well as use it as a special zone for my agents.
> >>
> >> I have the information of this region stored in a class that I defined,
> >> called "Rectangle" (as the shape is a rectangle, so original name :-)
> ). With
> >> the position and the size. Then, what I'm trying to do is to paint the
> zone
> >> as follows:
> >>
> >> In the start() method of my SimState I've done:
> >>
> >> world.setObjectLocation(AREA, new Double2D(AREA.getX(), AREA.getY()));
> >>
> >> While in setupPortrayals() in the GUIState class I've done:
> >>
> >> entityPortrayal.setPortrayalForClass(Rectangle.class, new
> >> RectanglePortrayal2D() {
> >>             @Override
> >>             public void draw(Object object, Graphics2D graphics,
> DrawInfo2D
> >> info) {
> >>                 paint = new Color(0f, 0f, 0f, 0.3f);
> >>                 super.draw(object, graphics, info);
> >>             }
> >>         });
> >>
> >> With this line I'm drawing a semi-transparent black rectangle, which
> center
> >> is located in the position that I gave. However, it is drawn as a
> square (and
> >> a big one by the way).
> >> The point is that I don't know how to specify the shape and size of this
> >> rectangle so it is drawn properly. I've been trying to look into the
> MASON
> >> examples but I don't get it...
> >>
> >> I'm also wondering how the "getNeighbors" would work if I want to know
> if my
> >> agent is in the zone (actually I don't need to access to this
> information
> >> this way as the rectangle is fixed to the same position and I can do the
> >> calculus about the zone manually).
> >>
> >> Thanks in advance for the help!
> >>
> >> Regards,
> >> Javier
>