Graphics Library
A simple graphics library has been created as part of the course. The library makes it
possible to draw a small set of geometric shapes on a canvas of the given dimensions:
(0,0)
+-------------> x
|
|
|
|
|
|
V +
y (400?,800?) not important
Available Shapes
Here is a list of the shapes that can be drawn using the canvas:
The valid color names are listed here: color names
canvas.drawPoint( X coord , Y coord , "color" );
canvas.drawLine( start X , start Y , end X , end Y , "color" );
canvas.drawCircle( center X , center Y , radius , "color" );
canvas.drawEllipse( center X , center Y , radius in X , radius in Y , "color" );
canvas.drawSquare( center X , center Y , side length , "color" );
canvas.drawRectangle( center X , center Y , width , height , "color" );
canvas.drawPie( center X , center Y , radius , start Angle , pie Angle , "color" );
canvas.drawTriangle( X1 , Y1 , X2 , Y2 , X3 , Y3 , "color" );
canvas.drawPolygon( "color" , X1 , Y1 , X2 , Y2 , X3 , Y3 , ... , Xn , Yn );
* unlike the other shapes , for polygons the color must come first
canvas.drawText( center X , center Y , "text message" , "color" );
canvas.drawImage( center X , center Y , "image file name" );
Shape Colors
For shapes the color can be specified in a number of ways:
"red" draws RED shape canvas.drawCircle( 100, 200, 80, "red" );
"red(blue)" draws RED shape canvas.drawCircle( 100, 200, 80, "red(blue)" );
with BLUE border/outline
"(blue)" draws empty shape canvas.drawCircle( 100, 200, 80, "(blue)" );
with BLUE border/outline
"red(blue)|4" draws RED shape canvas.drawCircle( 100, 200, 80, "red(blue)|4" );
with BLUE border/outline
outline is 4 units thick
"red(blue)|4|dashes" draws RED shape canvas.drawCircle( 100, 200, 80, "red(blue)|4|dashes" );
with BLUE border/outline
outline is 4 units thick
made up of DASHES
"red(blue)|4|dots" draws a RED shape canvas.drawCircle( 100, 200, 80, "red(blue)|4|dots" );
with BLUE border/outline
outline is 4 units thick
made up of DOTS
"red(blue)|dashes" as above, but outline canvas.drawCircle( 100, 200, 80, "red(blue)|dashes" );
1 unit thick (default)
"red(blue)|dots" as above, but outline canvas.drawCircle( 100, 200, 80, "red(blue)|dashes" );
1 unit thick (default)
Note:
* the order is "fillColor(outlineColor)|thickness|style" ; not all components are required
* "red" draws solid RED shape
"(red)" draws transparent shape with RED outline
* thickness, dashes, dots DO NOT work when NO outline color is given:
"red|dashes" <- error, missing oultine color for dashes
"red|4" <- error, missing oultine color for thickness
Text Colors
For text the color can be specified in a number of ways:
"red" draws RED text canvas.drawText( 100, 200, "Hello", "red" );
"red|18" draws RED text canvas.drawText( 100, 200, "Hello", "red|18" );
font size is 18pt
"red|18|B" draws RED text canvas.drawText( 100, 200, "Hello", "red(blue)|18|B" );
font size is 18pt
text is Bold
"red|18|IUB" draws RED text canvas.drawText( 100, 200, "Hello", "red(blue)|18|B" );
font size is 18pt
text is Italics, Underlined, and Bold
(IUB BUI UIB IB BI I B etc all work)
"red(blue)|18|IUB" as above, but text canvas.drawText( 100, 200, "Hello", "red(blue)|18" );
has BLUE border/outline
Note:
* the order is "textColor(outlineColor)|fontSize|style" ; not all components are required