public class canvas
extends java.lang.Object
Constructor and Description |
---|
canvas() |
Modifier and Type | Method and Description |
---|---|
static void |
clear()
Clears the canvas and removes all shapes.
|
static Circle |
drawCircle(double x,
double y,
double radius)
Draws a circle with the given radius centered at the given point coordinates
in the default color.
|
static Circle |
drawCircle(double x,
double y,
double radius,
java.lang.String color)
Draws a circle with the given radius centered at the given point coordinates
in the given color.
|
static Image |
drawImage(double x,
double y,
java.lang.String filename)
Draws the image with the given filename centered at the given point coordinates.
|
static Line |
drawLine(double x1,
double y1,
double x2,
double y2)
Draws a line between the given point coordinates in the default color.
|
static Line |
drawLine(double x1,
double y1,
double x2,
double y2,
java.lang.String color)
Draws a line between the given point coordinates in the given color.
|
static Point |
drawPoint(double x,
double y)
Draws a point at the given coordinates in the default color.
|
static Point |
drawPoint(double x,
double y,
java.lang.String color)
Draws a point at the given coordinates in the given color.
|
static Rectangle |
drawRectangle(double x,
double y,
double w,
double h)
Draws a rectangle with the given width and height centered at the given point coordinates
in the default color.
|
static Rectangle |
drawRectangle(double x,
double y,
double w,
double h,
java.lang.String color)
Draws a rectangle with the given width and height centered at the given point coordinates
in the given color.
|
static Square |
drawSquare(double x,
double y,
double s)
Draws a square with the given side length centered at the given point coordinates
in the default color.
|
static Square |
drawSquare(double x,
double y,
double s,
java.lang.String color)
Draws a square with the given side length centered at the given point coordinates
in the given color.
|
static Text |
drawText(double x,
double y,
char ch)
Draws the given character centered at the given point coordinates
in the default color and size.
|
static Text |
drawText(double x,
double y,
char ch,
int size)
Draws the given character in the given size centered at the given point coordinates
in the default color.
|
static Text |
drawText(double x,
double y,
char ch,
int size,
java.lang.String color)
Draws the given character in the given size and color centered at the given point coordinates.
|
static Text |
drawText(double x,
double y,
char ch,
java.lang.String color)
Draws the given character in the given color and default size centered at the given point coordinates.
|
static Text |
drawText(double x,
double y,
double num)
Draws the given number centered at the given point coordinates
in the default color and size.
|
static Text |
drawText(double x,
double y,
double num,
int size)
Draws the given number in the given size centered at the given point coordinates
in the default color.
|
static Text |
drawText(double x,
double y,
double num,
int size,
java.lang.String color)
Draws the given number in the given size and color centered at the given point coordinates.
|
static Text |
drawText(double x,
double y,
double num,
java.lang.String color)
Draws the given number in the given color and default size centered at the given point coordinates.
|
static Text |
drawText(double x,
double y,
int num)
Draws the given number centered at the given point coordinates
in the default color and size.
|
static Text |
drawText(double x,
double y,
int num,
int size)
Draws the given number in the given size centered at the given point coordinates
in the default color.
|
static Text |
drawText(double x,
double y,
int num,
int size,
java.lang.String color)
Draws the given number in the given size and color centered at the given point coordinates.
|
static Text |
drawText(double x,
double y,
int num,
java.lang.String color)
Draws the given number in the given color and default size centered at the given point coordinates.
|
static Text |
drawText(double x,
double y,
java.lang.String str)
Draws the given string centered at the given point coordinates
in the default color and size.
|
static Text |
drawText(double x,
double y,
java.lang.String str,
int size)
Draws the given string in the given size centered at the given point coordinates
in the default color.
|
static Text |
drawText(double x,
double y,
java.lang.String str,
int size,
java.lang.String color)
Draws the given string in the given size and color centered at the given point coordinates.
|
static Text |
drawText(double x,
double y,
java.lang.String str,
java.lang.String color)
Draws the given string in the given color and default size centered at the given point coordinates.
|
static Triangle |
drawTriangle(double x1,
double y1,
double x2,
double y2,
double x3,
double y3)
Draws a triangle connecting the given points in the default color.
|
static Triangle |
drawTriangle(double x1,
double y1,
double x2,
double y2,
double x3,
double y3,
java.lang.String color)
Draws a triangle connecting the given points in the given color.
|
static int |
getHeight()
Returns the height of the canvas.
|
static java.lang.String |
getRandomColor()
Returns a random color name.
|
static int |
getWidth()
Returns the width of the canvas.
|
static char |
readChar(java.lang.String prompt)
Blocks with a keypad dialog box waiting for single character input.
|
static float |
readFloat(java.lang.String prompt)
Blocks with a keypad dialog box waiting for floating-point input.
|
static int |
readInt(java.lang.String prompt)
Blocks with a keypad dialog box waiting for integer input.
|
static float |
readSelection(java.lang.String prompt,
java.lang.Float... items)
Blocks with a list dialog box waiting for a float selection.
|
static int |
readSelection(java.lang.String prompt,
java.lang.Integer... items)
Blocks with a list dialog box waiting for an integer selection.
|
static java.lang.String |
readSelection(java.lang.String prompt,
java.lang.String... items)
Blocks with a list dialog box waiting for a string selection.
|
static java.lang.String |
readString(java.lang.String prompt)
Blocks with a keypad dialog box waiting for text input.
|
static void |
setBackground(java.lang.String color)
Changes the canvas background to the given color.
|
static void |
sleep(double secs)
Pauses the application execution for the given number of seconds.
|
static Fling |
waitForFling()
Blocks and waits for a fling event.
|
static Touch |
waitForTouch()
Blocks and waits for a touch event.
|
public static void clear()
public static Circle drawCircle(double x, double y, double radius)
x
- the x-coordinate of the circle centery
- the y-coordinate of the circle enterradius
- the circle radiuspublic static Circle drawCircle(double x, double y, double radius, java.lang.String color)
x
- the x-coordinate of the circle centery
- the y-coordinate of the circle enterradius
- the circle radiuscolor
- the circle colorpublic static Image drawImage(double x, double y, java.lang.String filename)
x
- the x-coordinate of the image centery
- the y-coordinate of the image enterfilename
- the number of the image filepublic static Line drawLine(double x1, double y1, double x2, double y2)
x1
- the x-coordinate of the first point positiony1
- the y-coordinate of the first point positionx2
- the x-coordinate of the first point positiony2
- the y-coordinate of the first point positionpublic static Line drawLine(double x1, double y1, double x2, double y2, java.lang.String color)
x1
- the x-coordinate of the first point positiony1
- the y-coordinate of the first point positionx2
- the x-coordinate of the first point positiony2
- the y-coordinate of the first point positioncolor
- the line colorpublic static Point drawPoint(double x, double y)
x
- the x-coordinate of the point positiony
- the y-coordinate of the point positionpublic static Point drawPoint(double x, double y, java.lang.String color)
x
- the x-coordinate of the point positiony
- the y-coordinate of the point positioncolor
- the point colorpublic static Rectangle drawRectangle(double x, double y, double w, double h)
x
- the x-coordinate of the rectangle centery
- the y-coordinate of the rectangle enterw
- the rectangle widthh
- the rectangle heightpublic static Rectangle drawRectangle(double x, double y, double w, double h, java.lang.String color)
x
- the x-coordinate of the rectangle centery
- the y-coordinate of the rectangle enterw
- the rectangle widthh
- the rectangle heightcolor
- the rectangle colorpublic static Square drawSquare(double x, double y, double s)
x
- the x-coordinate of the square centery
- the y-coordinate of the square enters
- the square side lengthpublic static Square drawSquare(double x, double y, double s, java.lang.String color)
x
- the x-coordinate of the square centery
- the y-coordinate of the square enters
- the square side lengthcolor
- the square colorpublic static Text drawText(double x, double y, char ch)
x
- the x-coordinate of the character centery
- the y-coordinate of the character enterch
- the character to drawpublic static Text drawText(double x, double y, char ch, int size)
x
- the x-coordinate of the character centery
- the y-coordinate of the character enterch
- the character to drawsize
- the size of the characterpublic static Text drawText(double x, double y, char ch, int size, java.lang.String color)
x
- the x-coordinate of the character centery
- the y-coordinate of the character enterch
- the character to drawsize
- the size of the charactercolor
- the color of the characterpublic static Text drawText(double x, double y, char ch, java.lang.String color)
x
- the x-coordinate of the character centery
- the y-coordinate of the character enterch
- the character to drawcolor
- the color of the characterpublic static Text drawText(double x, double y, double num)
x
- the x-coordinate of the number centery
- the y-coordinate of the number enternum
- the number to drawpublic static Text drawText(double x, double y, double num, int size)
x
- the x-coordinate of the number centery
- the y-coordinate of the number enternum
- the number to drawsize
- the size of the numberpublic static Text drawText(double x, double y, double num, int size, java.lang.String color)
x
- the x-coordinate of the number centery
- the y-coordinate of the number enternum
- the number to drawsize
- the size of the numbercolor
- the color of the numberpublic static Text drawText(double x, double y, double num, java.lang.String color)
x
- the x-coordinate of the number centery
- the y-coordinate of the number enternum
- the number to drawcolor
- the color of the numberpublic static Text drawText(double x, double y, int num)
x
- the x-coordinate of the number centery
- the y-coordinate of the number enternum
- the number to drawpublic static Text drawText(double x, double y, int num, int size)
x
- the x-coordinate of the number centery
- the y-coordinate of the number enternum
- the number to drawsize
- the size of the numberpublic static Text drawText(double x, double y, int num, int size, java.lang.String color)
x
- the x-coordinate of the number centery
- the y-coordinate of the number enternum
- the number to drawsize
- the size of the numbercolor
- the color of the numberpublic static Text drawText(double x, double y, int num, java.lang.String color)
x
- the x-coordinate of the number centery
- the y-coordinate of the number enternum
- the number to drawcolor
- the color of the numberpublic static Text drawText(double x, double y, java.lang.String str)
x
- the x-coordinate of the text centery
- the y-coordinate of the text enterstr
- the string to drawpublic static Text drawText(double x, double y, java.lang.String str, int size)
x
- the x-coordinate of the text centery
- the y-coordinate of the text enterstr
- the string to drawsize
- the size of the textpublic static Text drawText(double x, double y, java.lang.String str, int size, java.lang.String color)
x
- the x-coordinate of the text centery
- the y-coordinate of the text enterstr
- the string to drawsize
- the size of the textcolor
- the color of the textpublic static Text drawText(double x, double y, java.lang.String str, java.lang.String color)
x
- the x-coordinate of the text centery
- the y-coordinate of the text enterstr
- the string to drawcolor
- the color of the textpublic static Triangle drawTriangle(double x1, double y1, double x2, double y2, double x3, double y3)
x1
- the x-coordinate of the first vertex of the triangley1
- the y-coordinate of the first vertex of the trianglex2
- the x-coordinate of the second vertex of the triangley2
- the y-coordinate of the second vertex of the trianglex3
- the x-coordinate of the third vertex of the triangley3
- the y-coordinate of the third vertex of the trianglepublic static Triangle drawTriangle(double x1, double y1, double x2, double y2, double x3, double y3, java.lang.String color)
x1
- the x-coordinate of the first vertex of the triangley1
- the y-coordinate of the first vertex of the trianglex2
- the x-coordinate of the second vertex of the triangley2
- the y-coordinate of the second vertex of the trianglex3
- the x-coordinate of the third vertex of the triangley3
- the y-coordinate of the third vertex of the trianglecolor
- the triangle colorpublic static int getHeight()
Must be called only after a call to the run()
method
public static java.lang.String getRandomColor()
public static int getWidth()
Must be called only after a call to the run()
method
public static char readChar(java.lang.String prompt)
prompt
- the prompt to display above the dialog boxpublic static float readFloat(java.lang.String prompt)
prompt
- the prompt to display above the dialog boxpublic static int readInt(java.lang.String prompt)
prompt
- the prompt to display above the dialog boxpublic static float readSelection(java.lang.String prompt, java.lang.Float... items)
prompt
- the prompt to display above the dialog boxitems
- variable-length list of float choicespublic static int readSelection(java.lang.String prompt, java.lang.Integer... items)
prompt
- the prompt to display above the dialog boxitems
- variable-length list of integer choicespublic static java.lang.String readSelection(java.lang.String prompt, java.lang.String... items)
prompt
- the prompt to display above the dialog boxitems
- variable-length list of string choicespublic static java.lang.String readString(java.lang.String prompt)
prompt
- the prompt to display above the dialog boxpublic static void setBackground(java.lang.String color)
color
- the new background colorpublic static void sleep(double secs)
secs
- the number of seconds to pausepublic static Fling waitForFling()
public static Touch waitForTouch()