Class SpritePixels

java.lang.Object
  extended by SpritePixels
Direct Known Subclasses:
ArrowTurtle, BallTurtle, BoxTurtle, CrossTurtle, DiamondTurtle, TriangleTurtle, TurtleTurtle

public class SpritePixels
extends java.lang.Object

SpritePixels is an abstract class that another class extends when it wants to provide the pixels that make up the image of a Sprite.


Field Summary
static int BLACK_OPAQUE_PIXEL
          Value of a pixel which is solid black.
static java.lang.String CLASS_NAME
          Class name as a String.
static int MAX_SPRITE_HEIGHT
          Default maximum sprite image height.
static int MAX_SPRITE_WIDTH
          Default maximum sprite image width.
static int MIN_SPRITE_HEIGHT
          Default minimum sprite image height.
static int MIN_SPRITE_WIDTH
          Default minimum sprite image width.
static int ROTATE_LEFT_RIGHT
          Symbolic constant for rotation style where initial image faces left and remains facing left for headings 181-359 degrees, but flips to facing right for headings 0-180 degrees.
static int ROTATE_OFF
          Symbolic constant for no rotation of the turtle's shape.
static int ROTATE_ON
          Symbolic constant for standard 360 degree rotation style of turtle's shape, its Sprite.
static int ROTATE_RIGHT_LEFT
          Symbolic constant for rotation style where initial image faces right and remains facing right for headings 0-180 degrees, but flips to facing left for headings 181-359.
 
Constructor Summary
SpritePixels(int width, int height, java.awt.Color color, double heading)
          Instantiate a Sprite's Image given its dimensions, color, and an implementation of the initSpritePixels() method.
SpritePixels(PixelRectangle pixRect)
          Instantiate the pixels that make up a Sprite's Image given an array of pixels.
SpritePixels(PixelRectangle pixRect, int rotationStyle)
          Instantiate the pixels that make up a Sprite's Image given an array of pixels.
 
Method Summary
 int getHeight()
          Return the current height of this Sprite's image.
protected  int getMinimumHeight()
          Return the default minimum height of this Sprite's image.
protected  int getMinimumWidth()
          Return the default minimum width of this Sprite's image.
 int[] getPixels()
          Return a copy of this Sprite's pixels.
 int getSideSize()
          Return the length of a side of this Sprite's square array of pixels.
 int getWidth()
          Return the current width of this Sprite's image.
protected  void initSpritePixels(int spriteSideSize)
          Initializes the pixels that make up the turtle's image.
protected  void setCirclePixels(int ctrX, int ctrY, int radius, int rgbVal)
          Set the value of pixels along an approximation of the circumference of a circle.
protected  void setLinePixels(int x0, int y0, int x1, int y1, int rgbVal)
          Set the value of pixels along an approximation of a line.
protected  void setPixel(int x, int y, int rgbVal)
          Fill the specified (x,y) pixel in the Sprite's image with an RGB value.
 boolean setSpriteColor(java.awt.Color newColor)
          Fill inner pixels of the turtle with the specified color.
 boolean setSpriteHeading(double newHeading)
          Rotate the turtle to a specified heading (radians).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_NAME

public static final java.lang.String CLASS_NAME
Class name as a String.

See Also:
Constant Field Values

MAX_SPRITE_HEIGHT

public static final int MAX_SPRITE_HEIGHT
Default maximum sprite image height.

See Also:
Constant Field Values

MAX_SPRITE_WIDTH

public static final int MAX_SPRITE_WIDTH
Default maximum sprite image width.

See Also:
Constant Field Values

MIN_SPRITE_HEIGHT

public static final int MIN_SPRITE_HEIGHT
Default minimum sprite image height.

See Also:
Constant Field Values

MIN_SPRITE_WIDTH

public static final int MIN_SPRITE_WIDTH
Default minimum sprite image width.

See Also:
Constant Field Values

BLACK_OPAQUE_PIXEL

public static final int BLACK_OPAQUE_PIXEL
Value of a pixel which is solid black.

See Also:
Constant Field Values

ROTATE_ON

public static final int ROTATE_ON
Symbolic constant for standard 360 degree rotation style of turtle's shape, its Sprite.

See Also:
Constant Field Values

ROTATE_OFF

public static final int ROTATE_OFF
Symbolic constant for no rotation of the turtle's shape.

See Also:
Constant Field Values

ROTATE_LEFT_RIGHT

public static final int ROTATE_LEFT_RIGHT
Symbolic constant for rotation style where initial image faces left and remains facing left for headings 181-359 degrees, but flips to facing right for headings 0-180 degrees.

See Also:
Constant Field Values

ROTATE_RIGHT_LEFT

public static final int ROTATE_RIGHT_LEFT
Symbolic constant for rotation style where initial image faces right and remains facing right for headings 0-180 degrees, but flips to facing left for headings 181-359.

See Also:
Constant Field Values
Constructor Detail

SpritePixels

public SpritePixels(PixelRectangle pixRect)
Instantiate the pixels that make up a Sprite's Image given an array of pixels. The assumed orientation of the PixelRectangle is upright, facing the way you want for the turtle heading of 0, or north.


SpritePixels

public SpritePixels(PixelRectangle pixRect,
                    int rotationStyle)
Instantiate the pixels that make up a Sprite's Image given an array of pixels. The assumed orientation of the PixelRectangle is upright, facing the way you want for the turtle heading of 0, or north. Images are different from the built-in turtle shapes in the respect that they may consist of an object that appears to have direction, e.g., the Scratch cat facing right. A turtle that has such an assumed direction must be flipped when its heading changes. Users do not expect a right facing cat to be upside-down when its heading changes such that it's facing west.


SpritePixels

public SpritePixels(int width,
                    int height,
                    java.awt.Color color,
                    double heading)
Instantiate a Sprite's Image given its dimensions, color, and an implementation of the initSpritePixels() method. It is assumed that the produced pixels are for the heading 0.0 radians, so a desired heading (in radians) is also provided as a parameter.

Method Detail

getMinimumHeight

protected int getMinimumHeight()
Return the default minimum height of this Sprite's image. Subclasses should override this method if they support a different minimum height.


getMinimumWidth

protected int getMinimumWidth()
Return the default minimum width of this Sprite's image. Subclasses should override this method if they support a different minimum width.


initSpritePixels

protected void initSpritePixels(int spriteSideSize)
Initializes the pixels that make up the turtle's image. Overridden by the child subclass. A SpritePixels constructor invokes this method.


setCirclePixels

protected void setCirclePixels(int ctrX,
                               int ctrY,
                               int radius,
                               int rgbVal)
Set the value of pixels along an approximation of the circumference of a circle.

This is an implementation of the simplest form of the midpoint algorithm as described in Computer Graphics, Foley and van Dam

Parameters:
ctrX - the X coordinate of center of the circle.
ctrY - the Y coordinate of center of the circle.
radius - the distance from the center to pixels painted.
rgbVal - the RGB value of the pixels effected.

setLinePixels

protected void setLinePixels(int x0,
                             int y0,
                             int x1,
                             int y1,
                             int rgbVal)
Set the value of pixels along an approximation of a line.

Parameters:
x0 - the X coordinate of one end of the line.
y0 - the Y coordinate of one end of the line.
x1 - the X coordinate of the other end of the line.
y1 - the Y coordinate of the other end of the line.
rgbVal - the RGB value of the pixels effected.

setPixel

protected void setPixel(int x,
                        int y,
                        int rgbVal)
Fill the specified (x,y) pixel in the Sprite's image with an RGB value. Used in child's initSpritePixels() to paint single pixels in the turtle's image.

The origin for the coordinate system used is the top-left corner with X values increasing left to right and Y values increasing top to bottom.

Parameters:
x - the X coordinate of the pixel.
y - the Y coordinate of the pixel.
rgbVal - the new RGB value of the pixel.

getPixels

public int[] getPixels()
Return a copy of this Sprite's pixels.


getSideSize

public int getSideSize()
Return the length of a side of this Sprite's square array of pixels.


getHeight

public int getHeight()
Return the current height of this Sprite's image. This includes taking into account the current heading.


getWidth

public int getWidth()
Return the current width of this Sprite's image. This includes taking into account the current heading.


setSpriteColor

public boolean setSpriteColor(java.awt.Color newColor)
Fill inner pixels of the turtle with the specified color.


setSpriteHeading

public boolean setSpriteHeading(double newHeading)
Rotate the turtle to a specified heading (radians). Return true if the Sprite's image changed, false if not.