Wednesday, January 14, 2015

Binary Tree Printer

Data Structures are often hard to visualize and understand.  I decided to do my best to create a visual representation of a binary tree.

I wanted it to be fast and easy to implement.  I ended up creating a system for printing a binary tree currently in Java and C#

My Results

Example Trees:

Balanced

         /---  0  ---\             
      /  1  \     /  2  \          
      3     4     5     6          

UnBalanced

           /---0                   
         /-1-\                     
        /2   3                     
        4                          

                           /------------------------------ 2 ------------------------------\                               
           /-------------- 7 --------------\                                               1                               
   /------26 ------\                       3                                                                               
  90 --\          25 --\                                                                                                   
      36              19 \                                                                                                 
                        17                                                                                                 

Huffman Tree

                           /----------------------------nul(13)----------------------------\                               
           /------------nul(5) ------------\                               /------------nul(8) ------------\               
         67(2)                     /----nul(3) ----\                     45(4)                     /----nul(4) ----\       
                                 34(1)         /nul(2) \                                         23(2)         /nul(2) \   
                                             78(1)   89(1)                                                   12(1)   56(1) 

Binary Heap Tree

       /------ 1 ------\           
   /-- 2 --\       /-- 3 --\       
  17      26      19     / 7 \     
                        25  90    
 GitHub

Toggle comment blocks with 1 character

IDEs that allow you block comment and uncomment seconds with a keystroke are awesome. Only problem is many IDEs have different keyboard combinations for this, and many times you may be working in a simple text editor for quick code.  I often disable chunks of code and never liked the amount of typing I would have to do. I developed a commenting style that works on any language that uses "//" for line comments and "/**/" for block comments.


The Basic Block

This will toggle a single block of code by adding 1 "/" to the first line

/* comment about block of code
inactive block of code
//*/


//* only line change is here
active code
//*/


You can toggle blocks by introducing a "/*/"


/* only line change is here
inactive
/*/
int active
//*/


//* only line change is here
int active
/*/
inactive
//*/
I have more examples here

GIF example:

OpenGL Lighting Demo

I was able to learn about OpenGL and how to write shaders. Lighting in games is an effect that I think everyone takes for granted. My application demonstrates basic aspects of lighting used in games.


It starts by rendering objects to the screen

Then adding basic diffuse lighting (the arrow is the light source)

I also included the ability to show the difference between the Fragment and Vertex Shader. The Vertex Shader runs for each point on the geometry that makes up the object on the screen.  The fragment shader is run for every pixel between those points and are displayed on the screen.  Lighting in the fragment shader is more intense, but looks much better.

The last lighting aspect I added was specularity.  The shiny effect surfaces get when they reflect some of the light into your eye.

The next examples show the difference between frag and vertex shaders

Vertex Shader
 Fragment Shader


Vertex Shader
 Fragment Shader