package nl.tudelft.simulation.examples.dsol.animation; import java.awt.Color; import java.awt.Font; import java.awt.Graphics2D; import java.awt.image.ImageObserver; import java.rmi.RemoteException; import javax.naming.NamingException; import nl.tudelft.simulation.dsol.animation.D2.Renderable2D; import nl.tudelft.simulation.dsol.simulators.SimulatorInterface; /** * The Animation of a Ball. *

* Copyright (c) 2003-2022 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See * for project information https://simulation.tudelft.nl. The DSOL * project is distributed under a three-clause BSD-style license, which can be found at * * https://simulation.tudelft.nl/dsol/3.0/license.html. *

* @author Peter Jacobs * @since 1.4 */ public class BallAnimation extends Renderable2D { /** */ private static final long serialVersionUID = 1L; /** * the color of the ballAnimation. */ private Color color = Color.ORANGE; /** * constructs a new BallAnimation. * @param source Locatable; the source * @param simulator SimulatorInterface.TimeDouble; the simulator * @throws NamingException on registration error * @throws RemoteException on remote animation error */ public BallAnimation(final Ball source, final SimulatorInterface.TimeDouble simulator) throws RemoteException, NamingException { super(source, simulator); // even numbered balls are vertically scaled; odd numbered balls not. Balls 6-10 are twice as small. int nr = Integer.parseInt(source.toString()); setScaleObject(nr > 5); setScaleY(nr % 2 == 1); } /** {@inheritDoc} */ @Override public void paint(final Graphics2D graphics, final ImageObserver observer) { graphics.setColor(this.color); graphics.fillOval(-(int) Ball.RADIUS, -(int) Ball.RADIUS, (int) (Ball.RADIUS * 2.0), (int) (Ball.RADIUS * 2.0)); graphics.setFont(graphics.getFont().deriveFont(Font.BOLD)); graphics.setColor(Color.GRAY); graphics.drawString(getSource().toString(), (float) (Ball.RADIUS * -1.0), (float) (Ball.RADIUS * 1.0)); } /** * @return Returns the color. */ public Color getColor() { return this.color; } /** * @param color Color; The color to set. */ public void setColor(final Color color) { this.color = color; } }