Day 2 on the Christmas tree development has led to some interesting puzzles. Firstly, I have changed the simple build where each row was added one at a time. Now I can see that there is a clear pattern, as the tree increases in height the row length is reduced by one block at each end. Therefore, I can have a loop that is controlled by the height of the tree and each time the tree goes up a row the ends are reduced by 1 block each. So, I did the maths and worked out what I needed to do to the x coordinate every time I went around the loop…this so did not work. I had a tree that seemed to build upside down as if we had just entered the world of Mr Silly in the Mister Men.
With a few tweaks the tree looked even more bizarre with the tree being the right width at the bottom, then narrowed as it went upwards until we got to the top and then guess what….it went back to the full width. WHY!!!! Back to the drawing board and literally drawing out the tree on a piece of paper. I think I cracked it. Because Python will only count upwards in a FOR loop it is easier to create the tree from the top downwards. Finally, the loop works and the 2D tree is now looking correct. The code looks a real mess though, time to tidy it up and make it a bit slicker.
Next, lets turn it into a 3D tree. If this was difficult to get right, I dread to think what is going to happen in 3D.
Come and learn more about how to do this with your class at our twilight session with Tech For Life: https://t.co/dxOxSFLcaH