ch.aplu.turtle
Class TurtleRenderer

java.lang.Object
  |
  +--ch.aplu.turtle.TurtleRenderer
All Implemented Interfaces:
ImageObserver

public class TurtleRenderer
extends Object
implements ImageObserver

This class is responsible for creating and choosing the correct Turtle picture.

Version:
0.1
Author:
Regula Hoefer-Isenegger

Field Summary
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Method Summary
protected  Point2D.Double calcTopLeftCorner(double x, double y)
          Compute the top left corner of the Turtle image (dependent on the specified x- and y-coordinate and the image width and height.
protected  Point2D.Double calcTopLeftCorner(Point2D.Double p)
          Compute the top left corner of the Turtle image (dependent on the specified point p and the image width and height.
protected  int calcTopLeftCornerX(double x)
          Compute the x-coordinate of the top left corner of the Turtle image (it depends on the specified x-coordinate and the image width).
protected  int calcTopLeftCornerY(double y)
          Compute the y-coordinate of the top left corner of the Turtle image (it depends on the specified y-coordinate and the image height).
protected  void clipPaint(int x, int y, Graphics graphics)
          Defines how to paint in clip mode (and does it!)
 Image currentImage()
          Returns the current image.
protected  double getAngle()
           
 boolean imageChanged(double angle)
          Tells whether the image has changed.
 boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height)
          As an image stays unchanged, there's no need to ever update it.
 void init(TurtleFactory factory, int resolution)
          Creates the images.
protected  void internalPaint(double x, double y, Graphics graphics)
          Calls clipPaint and WrapPaint().
 void paint(double x, double y)
          This method is responsible for painting the turtle onto the playground at (x, y).
 void paint(double x, double y, Graphics graphics)
          This method is responsible for painting the Turtle at (x, y).
 void paint(Point2D.Double p)
          This method is responsible for painting the turtle onto the playground at p.
 void paint(Point2D.Double p, Graphics graphics)
          This method is responsible for painting the Turtle at p.
 void setAngle(double angle)
          Sets the current image to the one corresponding to the angle angle.
protected  void wrapPaint(int x, int y, Graphics graphics)
          Defines how to paint in wrap mode (and does it!)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

imageUpdate

public boolean imageUpdate(Image img,
                           int infoflags,
                           int x,
                           int y,
                           int width,
                           int height)
As an image stays unchanged, there's no need to ever update it. So this method returns always false. For further information cf. java.awt.image.ImageObserver.

Specified by:
imageUpdate in interface ImageObserver
See Also:
ImageObserver.imageUpdate(java.awt.Image, int, int, int, int, int)

currentImage

public Image currentImage()
Returns the current image.


imageChanged

public boolean imageChanged(double angle)
Tells whether the image has changed.


setAngle

public void setAngle(double angle)
Sets the current image to the one corresponding to the angle angle.


getAngle

protected double getAngle()
Returns:
the current angle

init

public void init(TurtleFactory factory,
                 int resolution)
Creates the images. There are resolution images (i.e. two subsequent images contain an angle of 2π/ or 360/resolution degrees).


paint

public final void paint(double x,
                        double y)
This method is responsible for painting the turtle onto the playground at (x, y).


paint

public final void paint(Point2D.Double p)
This method is responsible for painting the turtle onto the playground at p.


paint

public final void paint(double x,
                        double y,
                        Graphics graphics)
This method is responsible for painting the Turtle at (x, y).
The Graphics argument tells where to paint.


paint

public void paint(Point2D.Double p,
                  Graphics graphics)
This method is responsible for painting the Turtle at p.
The Graphics argument tells where to paint.


internalPaint

protected void internalPaint(double x,
                             double y,
                             Graphics graphics)
Calls clipPaint and WrapPaint(). You should override this method only, if you add a new (edge) behaviour to the turtle. I recommend to you then to first call this method from the overriding one.
If you want to change anything about the real painting, override clipPaint or wrapPaint.

See Also:
clipPaint(int, int, Graphics), wrapPaint(int, int, Graphics)

clipPaint

protected void clipPaint(int x,
                         int y,
                         Graphics graphics)
Defines how to paint in clip mode (and does it!)


wrapPaint

protected void wrapPaint(int x,
                         int y,
                         Graphics graphics)
Defines how to paint in wrap mode (and does it!)


calcTopLeftCornerX

protected int calcTopLeftCornerX(double x)
Compute the x-coordinate of the top left corner of the Turtle image (it depends on the specified x-coordinate and the image width).


calcTopLeftCornerY

protected int calcTopLeftCornerY(double y)
Compute the y-coordinate of the top left corner of the Turtle image (it depends on the specified y-coordinate and the image height).


calcTopLeftCorner

protected Point2D.Double calcTopLeftCorner(double x,
                                           double y)
Compute the top left corner of the Turtle image (dependent on the specified x- and y-coordinate and the image width and height.


calcTopLeftCorner

protected Point2D.Double calcTopLeftCorner(Point2D.Double p)
Compute the top left corner of the Turtle image (dependent on the specified point p and the image width and height.