Practice programming algorithms drawing stars
Create a function called createLine
that creates a line of stars for the given length.
At star is *
- "* "
- an asteric followed by a space.
createLine(5);
returns * * * * *
createLine(7);
returns * * * * * * *
To make things testable all functions from here on should return an array filled with stars.
Use the print
function to print the drawing on the screen.
The unit tests are giving you a good overview of the required results though.
Create a function called createSquare
that can draw a square of stars for the given dimension.
Note:
- Use the
createLine
function - The ``
createSquare(5);
draws:
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
createSquare(7);
draws:
* * * * * * *
* * * * * * *
* * * * * * *
* * * * * * *
* * * * * * *
* * * * * * *
* * * * * * *
Create a function called createRectangle
that can draw a square of stars for the given width and height.
createRectangle(5,3);
draws:
* * * * *
* * * * *
* * * * *
createRectangle(7,2);
draws:
* * * * * * *
* * * * * * *
Create a function called createTriangle
that can draw a triangle of stars for the given base.
createTriangle(5);
draws:
*
* *
* * *
* * * *
* * * * *
createTriangle(7,2);
draws:
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
Create a function called flatTopTriangle
that can draw a triangle of stars for the given base with a base on top.
flatTopTriangle(5);
draws:
* * * * *
* * * *
* * *
* *
*
flatTopTriangle(7);
draws:
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
Create a function called createSquareOutline
that can draw a square of stars for the given dimension that is outline only.
createSquareOutline(5);
draws:
* * * * *
* *
* *
* *
* * * * *
createSquareOutline(7);
draws:
* * * * * * *
* *
* *
* *
* *
* *
* * * * * * *
Try to create :
- a
createRectangleOutline
function, - a
createTriangleOutline
function, - a
drawDiamond
function.
Create the tests first.