Coding Challenge #1 - Code a Christmas Tree!
-
Hey everyone! Hope you're all doing well and managing to stay safe and sane during one of the strangest Holiday Seasons we've had yet.
A brilliant idea was suggested to me by a user recently - this should've been a thing straight away really, but better late than never!
It would be cool to have some regular (hopefully weekly/fornightly) Coding Challenges which anybody and everybody could have a bash at. Post your results in the comments below (or share the program if it's quite long and you don't want to write out the code!).
The idea here is not about finding the "best" way of completing the challenge - it's not a competition with prizes other than the satisfaction of sharing in knowledge! Although, particularly innovative and creative ways to achieve the task will likely be acknolwedged and appreciated by everybody of course!
Simply having a go is what I'm after! I think it'll be awesome to see how the community interprets these tasks and hopefully we'll see diversity in the approaches, meaning everybody gets to learn! It's all about the learning.
However! That is not to say that you shouldn't show off! If you know how, go all-out! Amaze us :)
So, all of that said... Here's Coding Challenge #1!
Code a Christmas Tree
You must display a Christmas Tree on screen, made using code in some way.
Restrictions:
No using of Fuze Media Library
No using the Image/Map EditorsThis means you are left with text and regular drawing commands.
Feel free to get as fancy as you like!
Good luck!
Any questions about this particular Challenge, or questions/suggestions about the Coding Challenges in general, feel free to comment!
FAQ:
Q: Is the use of data within the code permitted, or does the code have to generate the data itself? (Eg: can I use a defined array of data to make the tree)
A: Yep! There is no problem with using data in this way. -
//Tree data tree = [384, 576, 1056, 4080, 5544, 2064, 7608, 16380, 21866, 15004, 32766, -32447, 640, 832, 384, 704] // The tree data is a 16x16x1 sprite following a pixel format of //one bit per pixel. So for example if you were to put 0xc which gives 1100 // The code below will print '** ' as 1 prints '*' and 0 print ' ' //If this was put into an image. Then you'd only need a 16x16 image, thus the -1 is not needed. //print "*" if 1 | print " " if 0 | print chr(10) if -1 function printPixel(data) if data == 0 then print(" ") update() else if data == 1 then print("*") update() else if data == -1 then print(chr(10)) update() endif endif endif return void //1 bit per pixel format. 16 pixels within a 2 byte array //in the code below I'm extracting each bit from 2 bytes by bitwise AND the //the tree data with the digits within a power of 2. //Since if you were to shift a variable to the left you are multiplying by 2 //Or adding that number to itself one time. Same for shifting to the right //in this case you're dividing by 2/ subtracting the number to itself by 1. for i = 0 to len(tree) loop printPixel(tree[i] & 0x1) printPixel((tree[i] & 0x2) >> 1) printPixel((tree[i] & 0x4) >> 2) printPixel((tree[i] & 0x8) >> 3) printPixel((tree[i] & 0x10) >> 4) printPixel((tree[i] & 0x20) >> 5) printPixel((tree[i] & 0x40) >> 6) printPixel((tree[i] & 0x80) >> 7) printPixel((tree[i] & 0x100) >> 8) printPixel((tree[i] & 0x200) >> 9) printPixel((tree[i] & 0x400) >> 10) printPixel((tree[i] & 0x800) >> 11) printPixel((tree[i] & 0x1000) >> 12) printPixel((tree[i] & 0x2000) >> 13) printPixel((tree[i] & 0x4000) >> 14) printPixel((tree[i] & 0x8000) >> 15) printPixel(-1) repeat update() sleep(5)
-
Isaac made this:
-
@LucasJG25 - Looks like you got in first! Congrats :) Awesome job.. That looks like a very clever way to do this indeed! I must study it :D Well done dude! Feel free to edit your post to add your explanation of how it works if you like!
@Richard - Absolutely AWESOME! Give Isaac a huge high-five for me! Love it, super creative. The tiny little "fuzes" at the top!
-
-
-
-
I went for something that I could build quickly:
loop clear() setView(0, -1, 4, 0) triangle({2,-1}, {1}, {3}, green, false) update() repeat
Or to make it a Christmas tree:
loop clear() setView(0, 1, 4, 0) // inverted the y here, because why not... triangle({2, 1}, {1}, {3}, green, false) triangle({2, 1}, {1}, {3}, yellow, true) // added this line for decorations update() repeat
edited: setView did not handle docking and undocking the way I expected, so I had to update my submission for that (now doing everything each loop).
-
this was fun!
May be pending
ID:S4X23MNDSL
-
I made a Christmas tree using shapes, currently pending. ID: N5FXURND9F
-
It appears my project name is the same as JMM161437's project, it asks me if I want to overwrite mine when I enter his code. Should I rename mine and resubmit?
-
This post is deleted! -
@Dinocoder said in Coding Challenge #1 - Code a Christmas Tree!:
I made a Christmas tree using shapes, currently pending. ID: N5FXURND9F
That looks great! Very arty!
-
-
Reading through the posts, I feel like my SVG approach is not fitting the core of this challenge. I will move it to a separate WIP thread. So, this submission fits better: download code NQ6HVMNDN8
The dark/light green structure in the tree, was a typo, but I decided that it looks nice 😄 so I left it.