Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void drawXmasTree(int size) {
- int stars = 1; //this is i
- int space = (size-1); // this is j
- int cutoff = ((size*2)-1);
- int rowCounter = 0; //this checks which row we're on in the 'block'
- int block = 1; //this checks which 'block' we're on
- while(block<=size){ //this will make sure the tree will be as long as it should be (how many loops occur)
- if(rowCounter==block){ //if we're at the end of the loop and need to move on to the next block...
- rowCounter = 0; //reset the rowCount since we're moving on to the next block
- ++block; //move on to the next block
- --space; //the space will decrease by one each time we move up a block
- stars = (stars +2); //stars also increase when we move on to the next block
- }
- else{
- writePattern(' ', '*', ' ', 'x', 'x', space, stars, space, 0, 0, cutoff);
- ++rowCounter; //move on to the next row
- }
- }
- }
- /* If three:
- i = # of * j = # of space
- | * | i = size-2 j = 2
- | *** | i = size-1 j = 1
- | *** |
- |*****| i = 0; j = ((size*2)-1)
- |*****|
- |*****| height = 6
- ----------------------------------------------------------------------------------------------------------------
- If four:
- | * | i = 1 j = 3
- | *** | i = i+2 j = 2 --- row appears 2 times
- | *** |
- | ***** | i = i+2 j = 1 --- row appears 3 times
- | ***** |
- | ***** |
- |*******| i = i+2 j = 0 --- row appears 4 times (see the pattern?)
- |*******|
- |*******|
- |*******| height = 10...so there is no 'height' variable, it's how many times it will enter a loop.
- For example, the 3 tree hits the loop...3 times. Here, it hits it 4 times, since there
- are 4 different numbered rows of stars. Each loop will increase i (or the star value) by +2.
- But what I need to figure out is how to calculate j...how to calculate the spaces...
- Here, it actually looks like the first loop would be (j = size-1)
- Then it continues to decrement, so j will go... for(j>=0) { --j}, as long as j is initalized as (size-1)
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement