Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.12 KB | None | 0 0
  1. void drawXmasTree(int size) {
  2.     int stars = 1; //this is i
  3.     int space = (size-1); // this is j
  4.     int cutoff = ((size*2)-1);
  5.     int rowCounter = 0; //this checks which row we're on in the 'block'
  6.     int block = 1;  //this checks which 'block' we're on   
  7.    
  8.     while(block<=size){ //this will make sure the tree will be as long as it should be (how many loops occur)
  9.        
  10.         if(rowCounter==block){  //if we're at the end of the loop and need to move on to the next block...
  11.             rowCounter = 0; //reset the rowCount since we're moving on to the next block
  12.             ++block;    //move on to the next block
  13.             --space;    //the space will decrease by one each time we move up a block
  14.             stars = (stars +2); //stars also increase when we move on to the next block
  15.         }
  16.         else{
  17.             writePattern(' ', '*', ' ', 'x', 'x', space, stars, space, 0, 0, cutoff);
  18.             ++rowCounter; //move on to the next row
  19.         }
  20.     }
  21. }
  22.  
  23. /*                      If three:
  24.           i = # of *   j = # of space
  25.       |  *  | i = size-2   j = 2
  26.       | *** | i = size-1   j = 1
  27.       | *** |                    
  28.       |*****| i = 0;       j = ((size*2)-1)  
  29.       |*****|
  30.       |*****| height = 6
  31. ----------------------------------------------------------------------------------------------------------------
  32.             If four:
  33.      |   *   |  i = 1     j = 3
  34.      |  ***  |  i = i+2   j = 2     --- row appears 2 times
  35.      |  ***  |
  36.      | ***** |  i = i+2   j = 1     --- row appears 3 times
  37.      | ***** |
  38.      | ***** |
  39.      |*******|  i = i+2   j = 0     --- row appears 4 times (see the pattern?)
  40.      |*******|
  41.      |*******|
  42.      |*******|  height = 10...so there is no 'height' variable, it's how many times it will enter a loop.
  43.             For example, the 3 tree hits the loop...3 times. Here, it hits it 4 times, since there
  44.             are 4 different numbered rows of stars. Each loop will increase i (or the star value) by +2.
  45.            
  46.             But what I need to figure out is how to calculate j...how to calculate the spaces...
  47.             Here, it actually looks like the first loop would be (j = size-1)
  48.             Then it continues to decrement, so j will go... for(j>=0) { --j}, as long as j is initalized as (size-1)
  49. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement