Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    Coding Challenge #1 - Code a Christmas Tree!

    Coding Challenges!
    11
    15
    999
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • L
      LucasJG25 last edited by LucasJG25

      //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)
      

      1 Reply Last reply Reply Quote 13
      • R
        Richard F last edited by Richard

        Isaac made this:
        96a8d5c9-8c33-445a-9f34-63f3367af393-image.png
        9d27971a-317d-40aa-a9fe-e1f2acf4b1ef-image.png

        1 Reply Last reply Reply Quote 13
        • Dave
          Dave Fuze Team last edited by

          @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!

          1 Reply Last reply Reply Quote 4
          • vinicity
            vinicity F last edited by vinicity

            Here is mine! It is a fractal Christmas tree!

            First I draw the initial image:
            B543DF89-815A-47A9-AF4B-B42A9DCE765F.jpeg

            Then I copy the copy the current image, and scale and rotate it in order to draw the branches:
            3B4F9721-78AB-4EAE-8835-1091F15396CD.jpeg

            Then I just draw the result on the screen and repeat the previous step.
            A49D8A4B-9621-4C60-9964-112C65D8D4A0.jpeg

            Download ID: 3RP33MND5C

            1 Reply Last reply Reply Quote 10
            • waldron
              waldron F last edited by

              1 Reply Last reply Reply Quote 10
              • ratrat44
                ratrat44 @Dave last edited by


                Code: ND597MNDXX (may still be pending)

                1 Reply Last reply Reply Quote 10
                • PB____
                  PB____ last edited by PB____

                  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).

                  1 Reply Last reply Reply Quote 8
                  • JMM161437
                    JMM161437 F last edited by

                    this was fun!

                    May be pending

                    ID:S4X23MNDSL

                    1 Reply Last reply Reply Quote 3
                    • Dinocoder
                      Dinocoder last edited by

                      I made a Christmas tree using shapes, currently pending. ID: N5FXURND9F

                      vinicity 1 Reply Last reply Reply Quote 6
                      • Dinocoder
                        Dinocoder last edited by

                        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?

                        1 Reply Last reply Reply Quote 2
                        • SteveZX81
                          SteveZX81 F last edited by

                          This post is deleted!
                          1 Reply Last reply Reply Quote 6
                          • vinicity
                            vinicity F @Dinocoder last edited by

                            @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!

                            1 Reply Last reply Reply Quote 2
                            • spikey
                              spikey F last edited by spikey

                              Shady little Christmas tree
                              did not came out as it should be
                              but your values lay inside
                              may your future be so bright.

                              Download code: NXK3BAGHN8 (pending)

                              Update: found the interpretation bug in my rudimentary SVG slurper

                              1 Reply Last reply Reply Quote 4
                              • spikey
                                spikey F last edited by spikey

                                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
                                2020122702493900-86FC867622BE2C2315A009D470F52DAE.jpg 2020122703120200-86FC867622BE2C2315A009D470F52DAE.jpg
                                The dark/light green structure in the tree, was a typo, but I decided that it looks nice 😄 so I left it.

                                1 Reply Last reply Reply Quote 3
                                • First post
                                  Last post