public class Drawing extends Object implements Pixellator
Graphics
, but renders only to
a one-bit-per-pixel bitmap. After drawings have been done, the
object can be used as a Pixellator
to get a list of the pixels
which have been hit at least once by one of the drawing methods called
during the life of the object. Pixels will not be repeated in this list.
The drawing methods are intended to be as efficient as possible. Bounds checking is done, so it is generally not problematic (or inefficient) to attempt drawing operations with coordinates far outside the drawing's range.
Constructor and Description |
---|
Drawing(Rectangle bounds)
Constructs a drawing with given pixel bounds.
|
Modifier and Type | Method and Description |
---|---|
void |
addPixel(int x,
int y)
Adds a single pixel to the list of pixels which have been plotted.
|
void |
addPixels(Pixellator pixellator)
Adds all the pixels from the given Pixellator to this drawing.
|
static Pixellator |
combinePixellators(Pixellator[] pixers)
Combines an array of given pixellators to produce a single one which
iterates over all the pixels.
|
void |
draw(Shape shape)
Draws the outline of an arbitrary shape.
|
void |
drawEllipse(int x0,
int y0,
int ax,
int ay,
int bx,
int by)
Draws the outline of an ellipse with no restrictions on the alignment
of its axes.
|
void |
drawLine(int x0,
int y0,
int x1,
int y1)
Draws a straight line between two points.
|
void |
drawOval(int x,
int y,
int width,
int height)
Draws the outline of an ellipse with horizontal/vertical axes.
|
void |
fill(Shape shape)
Fills an arbitrary shape.
|
void |
fillEllipse(int x0,
int y0,
int ax,
int ay,
int bx,
int by)
Fills an ellipse with no restrictions on the alignment of its axes.
|
void |
fillOval(int x,
int y,
int width,
int height)
Fills an ellipse with horizontal/vertical axes.
|
void |
fillRect(int x,
int y,
int width,
int height)
Fills a rectangle.
|
Rectangle |
getBounds()
Returns a copy of the bounding rectangle for this pixellator.
|
int |
getX()
Returns the X value for the current point.
|
int |
getY()
Returns the Y value for the current point.
|
boolean |
next()
Moves to the next point in the sequence.
|
void |
start()
Makes this object ready to iterate.
|
public Drawing(Rectangle bounds)
bounds
- rectangle giving the region in which pixels may be
plottedpublic Rectangle getBounds()
Pixellator
null
may be returned.getBounds
in interface Pixellator
public void addPixel(int x, int y)
x
- X coordinatey
- Y coordinatepublic void drawLine(int x0, int y0, int x1, int y1)
x0
- X coordinate of first pointy0
- Y coordinate of first pointx1
- X coordinate of second pointy1
- Y coordinate of second pointGraphics.drawLine(int, int, int, int)
public void fillRect(int x, int y, int width, int height)
x
- X coordinate of top left cornery
- Y coordinate of top left cornerwidth
- widthheight
- heightGraphics.fillRect(int, int, int, int)
public void drawOval(int x, int y, int width, int height)
x
- X coordinate of top left corner of enclosing rectangley
- Y coordinate of top left corner of enclosing rectanglewidth
- width of enclosing rectangleheight
- height of enclosing rectangleGraphics.drawOval(int, int, int, int)
public void fillOval(int x, int y, int width, int height)
x
- X coordinate of top left corner of enclosing rectangley
- Y coordinate of top left corner of enclosing rectanglewidth
- width of enclosing rectangleheight
- height of enclosing rectangleGraphics.drawOval(int, int, int, int)
public void drawEllipse(int x0, int y0, int ax, int ay, int bx, int by)
x0
- X coordinate of ellipse centrey0
- Y coordinate of ellipse centreax
- X component of semi-major (or -minor) axisay
- Y component of semi-major (or -minor) axisbx
- X component of semi-minor (or -major) axisby
- Y component of semi-minor (Or -major) axispublic void fillEllipse(int x0, int y0, int ax, int ay, int bx, int by)
x0
- X coordinate of ellipse centrey0
- Y coordinate of ellipse centreax
- X component of semi-major (or -minor) axisay
- Y component of semi-major (or -minor) axisbx
- X component of semi-minor (or -major) axisby
- Y component of semi-minor (Or -major) axispublic void fill(Shape shape)
shape
- shape to fillGraphics2D.fill(java.awt.Shape)
public void draw(Shape shape)
shape
- shape to drawGraphics2D.draw(java.awt.Shape)
public void addPixels(Pixellator pixellator)
pixellator
- iterator over pixels to addpublic void start()
Pixellator
Pixellator.next()
.start
in interface Pixellator
public boolean next()
Pixellator
Pixellator.getX()
/Pixellator.getY()
. Returns value indicates whether
there is a next point.next
in interface Pixellator
public int getX()
Pixellator
getX
in interface Pixellator
public int getY()
Pixellator
getY
in interface Pixellator
public static Pixellator combinePixellators(Pixellator[] pixers)
pixers
- array of pixellators to combineCopyright © 2024 Central Laboratory of the Research Councils. All Rights Reserved.