|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.ObjectGenDraw
public final class GenDraw
Generalized draw. Our class GenDraw is a generalization of S&W's StdDraw that supports multiple drawings. StdDraw provides a basic capability for creating drawings with your programs. It uses a simple graphics model that allows you to create drawings consisting of points, lines, and curves in a window on your computer and to save the drawings to a file.
For documentation on StdDraw, see Section 1.5 of Introduction to Programming in Java: An Interdisciplinary Approach by Sedgewick and Wayne and http://www.cs.princeton.edu/introcs/15inout.
| Field Summary | |
|---|---|
static java.awt.Color |
BLACK
|
static java.awt.Color |
BLUE
|
static java.awt.Color |
CYAN
|
static java.awt.Color |
DARK_GRAY
|
static java.awt.Color |
GRAY
|
static java.awt.Color |
GREEN
|
static java.awt.Color |
LIGHT_GRAY
|
static java.awt.Color |
MAGENTA
|
static java.awt.Color |
ORANGE
|
static java.awt.Color |
PINK
|
static java.awt.Color |
RED
|
static java.awt.Color |
WHITE
|
static java.awt.Color |
YELLOW
|
| Constructor Summary | |
|---|---|
GenDraw()
Construct a GenDraw canvas. |
|
GenDraw(java.lang.String title)
Construct a GenDraw canvas with the specified title. |
|
| Method Summary | |
|---|---|
void |
arc(double x,
double y,
double r,
double angle1,
double angle2)
Draw an arc of radius r, centered on (x, y), from angle1 to angle2 (in degrees). |
void |
circle(double x,
double y,
double r)
Draw circle of radius r, centered on (x, y); degenerate to pixel if small |
void |
clear()
Clear the screen with the default color, white |
void |
clear(java.awt.Color color)
Clear the screen with the given color. |
java.lang.String |
clipStringXaxis(java.lang.String s,
double min,
double max,
double targetPercentage)
Clip a string to fit within a specified percentage of the range min..max along the x-axis. |
java.lang.String |
clipStringYaxis(java.lang.String s,
double min,
double max,
double targetPercentage)
Clip a string to fit within a specified percentage of the range min..max along the y-axis. |
void |
filledCircle(double x,
double y,
double r)
Draw filled circle of radius r, centered on (x, y); degenerate to pixel if small |
void |
filledPolygon(double[] x,
double[] y)
Draw a filled polygon with the given (x[i], y[i]) coordinates |
void |
filledSquare(double x,
double y,
double r)
Draw a filled square of side length 2r, centered on (x, y); degenerate to pixel if small |
java.awt.Image |
getImage(java.lang.String filename)
Drawing images. |
boolean |
hasNextKeyTyped()
Has the user typed a key? |
void |
line(double x0,
double y0,
double x1,
double y1)
Draw a line from (x0, y0) to (x1, y1) |
static void |
main(java.lang.String[] args)
|
double |
mouseX()
Where is the mouse? |
double |
mouseY()
Where is the mouse? |
char |
nextKeyTyped()
What is the next key that was typed by the user? |
void |
picture(double x,
double y,
java.lang.String s)
Draw picture (gif, jpg, or png) centered on (x, y). |
void |
picture(double x,
double y,
java.lang.String s,
double degrees)
Draw picture (gif, jpg, or png) centered on (x, y), rotated given number of degrees |
void |
picture(double x,
double y,
java.lang.String s,
double w,
double h)
Draw picture (gif, jpg, or png) centered on (x, y). |
void |
picture(double x,
double y,
java.lang.String s,
double w,
double h,
double degrees)
Draw picture (gif, jpg, or png) centered on (x, y), rotated given number of degrees, rescaled to w-by-h. |
void |
pixel(double x,
double y)
Draw one pixel at (x, y) |
void |
point(double x,
double y)
Draw a point at (x, y) |
void |
polygon(double[] x,
double[] y)
Draw a polygon with the given (x[i], y[i]) coordinates |
void |
rotText(double x,
double y,
double degrees,
java.lang.String s)
Write the given text string in the current font, center on (x, y) and rotate by the specified number of degrees. |
void |
save(java.lang.String filename)
Save to file - suffix must be png, jpg, or gif. |
void |
setCanvasSize(int w,
int h)
Set the window size to w-by-h pixels |
void |
setFont()
Set the font to be the default for all string writing |
void |
setFont(java.awt.Font f)
Set the font as given for all string writing |
void |
setPenColor()
Set the pen color to the default which is BLACK. |
void |
setPenColor(java.awt.Color color)
Set the pen color to the given color. |
void |
setPenRadius()
Set the pen size to the default |
void |
setPenRadius(double r)
Set the pen size to the given size |
void |
setXscale()
Set the X scale to be the default |
void |
setXscale(double min,
double max)
Set the X scale (a border is added to the values) |
void |
setYscale()
Set the Y scale to be the default |
void |
setYscale(double min,
double max)
Set the Y scale (a border is added to the values) |
void |
show()
Display on-screen; calling this method means that the screen WILL be redrawn after each line(), circle(), or square(). |
void |
show(int t)
Display on screen and pause for t milliseconds. |
void |
square(double x,
double y,
double r)
Draw squared of side length 2r, centered on (x, y); degenerate to pixel if small |
void |
text(double x,
double y,
java.lang.String s)
Write the given text string in the current font, center on (x, y). |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.awt.Color BLACK
public static final java.awt.Color BLUE
public static final java.awt.Color CYAN
public static final java.awt.Color DARK_GRAY
public static final java.awt.Color GRAY
public static final java.awt.Color GREEN
public static final java.awt.Color LIGHT_GRAY
public static final java.awt.Color MAGENTA
public static final java.awt.Color ORANGE
public static final java.awt.Color PINK
public static final java.awt.Color RED
public static final java.awt.Color WHITE
public static final java.awt.Color YELLOW
| Constructor Detail |
|---|
public GenDraw(java.lang.String title)
title - a title for the canvas.public GenDraw()
| Method Detail |
|---|
public void setCanvasSize(int w,
int h)
w - the width as a number of pixelsh - the height as a number of pixels
a - RunTimeException if the width or height is 0 or negative.public void setXscale()
public void setYscale()
public void setXscale(double min,
double max)
min - the minimum value of the X scalemax - the maximum value of the X scale
public void setYscale(double min,
double max)
min - the minimum value of the Y scalemax - the maximum value of the Y scalepublic void clear()
public void clear(java.awt.Color color)
color - the Color to make the backgroundpublic void setPenRadius()
public void setPenRadius(double r)
r - the radius of the pen
java.lang.RuntimeException - if r is negativepublic void setPenColor()
public void setPenColor(java.awt.Color color)
color - the Color to make the penpublic void setFont()
public void setFont(java.awt.Font f)
f - the font to make text
public void line(double x0,
double y0,
double x1,
double y1)
x0 - the x-coordinate of the starting pointy0 - the y-coordinate of the starting pointx1 - the x-coordinate of the destination pointy1 - the y-coordinate of the destination point
public void pixel(double x,
double y)
x - the x-coordinate of the pixely - the y-coordinate of the pixel
public void point(double x,
double y)
x - the x-coordinate of the pointy - the y-coordinate of the point
public void circle(double x,
double y,
double r)
x - the x-coordinate of the center of the circley - the y-coordinate of the center of the circler - the radius of the circle
java.lang.RuntimeException - if the radius of the circle is negative
public void filledCircle(double x,
double y,
double r)
x - the x-coordinate of the center of the circley - the y-coordinate of the center of the circler - the radius of the circle
java.lang.RuntimeException - if the radius of the circle is negative
public void arc(double x,
double y,
double r,
double angle1,
double angle2)
x - the x-coordinate of the center of the circley - the y-coordinate of the center of the circler - the radius of the circleangle1 - the starting angle. 0 would mean an arc beginning at 3 o'clock.angle2 - the angle at the end of the arc. For example, if
you want a 90 degree arc, then angle2 should be angle1 + 90.
java.lang.RuntimeException - if the radius of the circle is negative
public void square(double x,
double y,
double r)
x - the x-coordinate of the center of the squarey - the y-coordinate of the center of the squarer - radius is half the length of any side of the square
java.lang.RuntimeException - if r is negative
public void filledSquare(double x,
double y,
double r)
x - the x-coordinate of the center of the squarey - the y-coordinate of the center of the squarer - radius is half the length of any side of the square
java.lang.RuntimeException - if r is negative
public void polygon(double[] x,
double[] y)
x - an array of all the x-coordindates of the polygony - an array of all the y-coordindates of the polygon
public void filledPolygon(double[] x,
double[] y)
x - an array of all the x-coordindates of the polygony - an array of all the y-coordindates of the polygonpublic java.awt.Image getImage(java.lang.String filename)
public void picture(double x,
double y,
java.lang.String s)
x - the center x-coordinate of the imagey - the center y-coordinate of the images - the name of the image/picture, e.g., "ball.gif"
java.lang.RuntimeException - if the image's width or height are negative
public void picture(double x,
double y,
java.lang.String s,
double degrees)
x - the center x-coordinate of the imagey - the center y-coordinate of the images - the name of the image/picture, e.g., "ball.gif"degrees - is the number of degrees to rotate counterclockwise
java.lang.RuntimeException - if the image's width or height are negative
public void picture(double x,
double y,
java.lang.String s,
double w,
double h)
x - the center x coordinate of the imagey - the center y coordinate of the images - the name of the image/picture, e.g., "ball.gif"w - the width of the imageh - the height of the image
public void picture(double x,
double y,
java.lang.String s,
double w,
double h,
double degrees)
x - the center x-coordinate of the imagey - the center y-coordinate of the images - the name of the image/picture, e.g., "ball.gif"w - the width of the imageh - the height of the imagedegrees - is the number of degrees to rotate counterclockwise
java.lang.RuntimeException - if the image's width or height are negative
public void text(double x,
double y,
java.lang.String s)
x - the center x coordinate of the texty - the center y coordinate of the texts - the text
public java.lang.String clipStringXaxis(java.lang.String s,
double min,
double max,
double targetPercentage)
The results from clipStringXaxis and clipStringYaxis may differ because the scaling of the x-axis from user space to screen space may not be the same as the scaling for the y-axis.
s - the textmin - lower end of the bounding rangemax - upper end of the bounding rangetargetPercentage - the target for the percentage of the range that can be used by the string
public java.lang.String clipStringYaxis(java.lang.String s,
double min,
double max,
double targetPercentage)
The results from clipStringXaxis and clipStringYaxis may differ because the scaling of the x-axis from user space to screen space may not be the same as the scaling for the y-axis.
s - the textmin - lower end of the bounding rangemax - upper end of the bounding rangetargetPercentage - the target for the percentage of the range that can be used by the string
public void rotText(double x,
double y,
double degrees,
java.lang.String s)
x - the center x coordinate of the texty - the center y coordinate of the textdegrees - the number of degrees to rotate the texts - the textpublic void show(int t)
t - number of millisecondspublic void show()
public void save(java.lang.String filename)
filename - the name of the file with one of the required suffixespublic double mouseX()
public double mouseY()
public boolean hasNextKeyTyped()
public char nextKeyTyped()
public static void main(java.lang.String[] args)
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||