Coding Challenge #1 - Code a Christmas Tree!
-
//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.