Graphics |
void |
setColor(Color color)
| Sets the foreground color for the drawing area. After setting the color, shapes you draw with functions
like fillCircle(x, y, radius) will be in this color |
void |
setBackgroundColor(Color color)
| Sets the background color of the drawing area |
void |
drawLine(int x1,
int y1, int x2, int y2)
| Draws a line from the given (x1, y1) location to the given (x2, y2) location |
void |
drawRectangle(int x,
int y, int width, int height)
| Draws an unfilled rectangle at the given (x, y) location of its top-left corner, with the given width and height |
void |
fillRectangle(int x,
int y, int width, int height)
| Draws a filled rectangle at the given (x, y) location of its top-left corner, with the given width and height |
void |
drawCircle(int x,
int y, int radius)
| Draws an unfilled circle at the given (x, y) location of its top-left corner, with the given radius |
void |
fillCircle(int x,
int y, int radius)
| Draws a filled circle at the given (x, y) location of its top-left corner, with the given radius |
void |
drawOval(int x,
int y, int width, int height)
| Draws an unfilled oval at the given (x, y) location of its top-left corner, with the given width and height |
void |
fillOval(int x,
int y, int width, int height)
| Draws a filled oval at the given (x, y) location of its top-left corner, with the given width and height |
void |
drawPolygon(int[] xPoints, int[] yPoints, int numPoints)
| Draws an unfilled polygon with the x-coordinates specified in xPoints, the y-coordinates specified in yPoints, and the number of points in the polygon in numPoints |
void |
fillPolygon(int[] xPoints, int[] yPoints, int numPoints)
| Draws a filled polygon with the x-coordinates specified in xPoints, the y-coordinates specified in yPoints, and the number of points in the polygon in numPoints |
void |
drawString(String str,
int x, int y)
| Draws the given String at the given (x, y) location |
void |
drawString(String str,
boolean bold, boolean italics, int size, int x,
int y)
| Draws the given String at the given (x, y) location with the given size, and possibly in bold and/or italics |
void |
clearDrawing()
| Clears the drawing area |
void |
clearRectangle(int x,
int y, int width, int height)
| Clears a portion of the drawing area defined by the rectangle at the given (x, y) location of its top-left corner, with the given width and height |
int |
getDrawingHeight()
| Returns the height of the drawing area so you know where the drawing areas top (0) and bottom edges (the returned value) are |
int |
getDrawingWidth()
| Returns the width of the drawing area so you know where the drawing areas left (0) and right edges (the returned value) are |
Input/Output |
int |
readInt()
| Returns int value typed in by user, expects any integer value (ex: -5) |
double |
readDouble()
| Returns double value typed in by user, expects any double value (ex: 3.25) |
String |
readString()
| Returns String value typed in by user, expects any String value (ex: I like to ride my bike.) |
boolean |
readBoolean()
| Returns boolean value typed in by user, expects true or false |
Color |
readColor()
| Returns Color value typed in by user, expects any of the names of Color Vales listed in the Color Values page (ex: Light blue) |
void |
printLine(int num)
| Prints out an int to the screen on its own line |
void |
printLine(double num)
| Prints out a double to the screen on its own line |
void |
printLine(String str)
| Prints out a String to the screen on its own line |
void |
printLine(boolean bool)
| Prints out a boolean to the screen on its own line |
void |
printLine(Color color)
| Prints out a Color to the screen on its own line |
void |
print(int num)
| Prints out an int to the screen |
void |
print(double num)
| Prints out a double to the screen |
void |
print(String str)
| Prints out a String to the screen |
void |
print(boolean bool)
| Prints out a boolean to the screen |
void |
print(Color color)
| Prints out a Color to the screen |
Math |
double |
floor(double num)
| Returns the floor of the given number (ex: floor of 17.81 = 17) |
double |
ceiling(double num)
| Returns the ceiling of the given number (ex: ceiling of 3.45 = 4) |
double |
round(double num)
| Returns the rounded number of the given number (ex: round of 3.45 = 3, round of 17.81 = 18) |
double |
absoluteValue(double num)
| Returns the absolute value of the given double (ex: if you give it -1.4, it will return 1.4) |
int |
absoluteValue(int num)
| Returns the absolute value of the given double (ex: if you give it -72, it will return 72) |
double |
squareRoot(double num)
| Returns the square root of the given number |
double |
power(double a, double b)
| Returns of value of the first argument raised to the power of the second argument
|
double |
log(double num)
| Returns the logarithm (base e) of the given number |
double |
sin(double angle)
| Returns the sine of an angle specified in radians |
double |
cos(double angle)
| Returns the cosine of an angle specified in radians |
double |
tan(double angle)
| Returns the tangent of an angle specified in radians |
double |
arcsin(double angle)
| Returns the arc sine of an angle specified in radians (in the range -pi/2 through pi/2) |
double |
arccos(double angle)
| Returns the arc cosine of an angle specified in radians (in the range 0.0 through pi) |
double |
arctan(double angle)
| Returns the arc tangent of an angle specified in radians (in the range -pi/2 through pi/2) |
double |
degreesToRadians(double degrees)
| Returns the angle measured in degrees converted to the equivalent angle measured in radians
|
double |
radiansToDegrees(double radians)
| Returns the angle measured in radians converted to the equivalent angle measured in degrees
|
double |
PI
| The value of the ratio of the circumference of a circle to its diameter |
double |
E
| The value of the base of natural logarithms |
int |
MIN_INT
| The minimum integer value (readInt() and readDouble() return this if a valid number is not entered) |
int |
MAX_INT
| The maximum integer value |
Strings |
int |
stringLength(String str)
| Returns the length of the string |
int |
indexOf(String haystack,
String needle)
| Returns the index of where the string needle is found in the string haystack, or -1 if not found |
int |
lastIndexOf(String haystack,
String needle)
| Returns the last index of where the string needle is found in the string haystack, or -1 if not found |
String |
substring(String str,
int beginIndex, int endIndex)
| Returns the substring beginning at beginIndex and ending at endIndex - 1 (so the length of the substring is endIndex - beginIndex) |
String |
substring(String str,
int beginIndex)
| Returns the substring beginning at beginIndex and extending to the end of the string |
String |
characterAt(String str, int index)
| Returns the character in str at index (as a String) |
int |
compareStrings(String str1, String str2)
| Compares two Strings alphabetically; returns a negative int if str1 is before str2, 0 if they are equal, and a positive int if str1 is after str2 |
String |
toUpperCase(String str)
| Returns the string will all letters converted to upper case |
String |
toLowerCase(String str)
| Returns the string will all letters converted to lower case |
Colors |
Color |
getColor(int red, int green, int blue)
| Returns the color value defined by the red, green, blue combination (each color component should be in the range 0 to 255) |
int |
getRed(Color color)
| Returns the red component of the color as an int between 0 and 255 |
int |
getGreen(Color color)
| Returns the green component of the color as an int between 0 and 255 |
int |
getBlue(Color color)
| Returns the blue component of the color as an int between 0 and 255 |
Color |
brighter(Color color)
| Returns a brighter copy of the given Color |
Color |
darker(Color color)
| Returns a darker copy of the given Color |
Mouse Handling |
boolean |
getMouseEvent()
| Returns true if there was a mouse event (mouse button pressed, mouse button released, mouse moved, or mouse dragged) |
int |
getMouseX()
| Returns the x location of the mouse (use after getMouseEvent() returns true) |
int |
getMouseY()
| Returns the y location of the mouse (use after getMouseEvent() returns true) |
boolean |
getMouseButton(int buttonNumber)
| Returns true if the specified mouse button is down (use after getMouseEvent() returns true) |
int |
getDragStartX()()
| Returns the x location of where mouse dragging started (use after getMouseEvent() returns true) |
int |
getDragStartY()()
| Returns the y location of where mouse dragging started (use after getMouseEvent() returns true) |
int |
getDragEndX()()
| Returns the x location of where mouse dragging ended (use after getMouseEvent() returns true) |
int |
getDragEndY()()
| Returns the y location of where mouse dragging ended (use after getMouseEvent() returns true) |
Keyboard Handling |
String |
readKey()
| Waits for the user to press a key. Returns the key they pressed as a String |
boolean |
getKeyState(String key)
| Returns true if the keyboard key is currently pressed down |
Time |
void |
delay(double seconds)
| Delays the running of your program by the given number of seconds (ex: 3 or .5) |
void |
startTimer()
| Starts the timer |
double |
stopTimer()
| Stops the timer and returns the number of seconds since it was started |
Miscellaneous |
void |
delay(double seconds)
| Delays the running of your program by the given number of seconds (ex: 3 or .5) |
int |
doubleToInt(double num)
| Returns the given double converted to an int |
double |
intToDouble(int num)
| Returns the given int converted to a double |
boolean |
equal(int firstInt,
int secondInt)
| Test to see if two int values are equal |
boolean |
equal(double firstDouble,
double secondDouble)
| Test to see if two double values are equal |
boolean |
equal(String firstString,
String secondString)
| Test to see if two String values are equal. Note: it is important that you do not use == to test if two Strings are equal |
boolean |
equal(boolean firstBoolean,
boolean secondBoolean)
| Test to see if two boolean values are equal |
boolean |
equal(Color firstColor,
Color secondColor)
| Test to see if two Color values are equal |
int |
arrayLength(int[] intArray)
| Returns the length of the given int array |
int |
arrayLength(double[] doubleArray)
| Returns the length of the given double array |
int |
arrayLength(String[] stringArray)
| Returns the length of the given String array |
int |
arrayLength(boolean[] booleanArray)
| Returns the length of the given boolean array |
int |
arrayLength(Color[] colorArray)
| Returns the length of the given Color array |
Random Values |
int |
randomInt(int max)
| Returns a random int value between 0 and max |
double |
randomDouble()
| Returns a random double value between 0 and 1 (ex: 0.614566671372701) |
boolean |
randomBoolean()
| Returns a random boolean (ex: true or false) |
Color |
randomColor()
| Returns a random Color value (ex: darkSeaGreen) |