% Script/Function Filename:uicontrol
%     hammingDistanceGUI.m
% Purpose:
%     Enter the purpose of the function/file here
%
% Record of modifications:
%     Programmer(s): {Your Name}
%     Date Due: YYYY-MM-DD
%     Date Submitted: YYYY-MM-DD
%     References: ????
%     Help Received: ????
%
% Variables Used:
%     Enter the variables that you use here

alphabet = 'a' : 'z';
len = randi( 20 );
word1 = alphabet( randi( 26 , 1 , len ) );
word2 = alphabet( randi( 26 , 1 , len ) );
spaces = randperm( length( word1 ) , randi( length( word1 ) + 1 ) - 1 );
word2( spaces ) = word1( spaces );

shorter = min( length( word1 ) , length( word2 ) );
longer = max( length( word1 ) , length( word2 ) );
letters = zeros( 2 , 20 );

for i = 1 : 20
    letters( 1 , i ) = uicontrol( 'style' , 'text' , 'units' , ...
        'normalized' , 'fontunits' , 'normalized' , 'fontname' , ...
        'fixedwidth' , 'string' , ' ' , 'fontsize' , 1 , ...
        'position' , [ ( i - 1 ) / 20 0.95 0.05 0.05 ] );
    letters( 2 , i ) = uicontrol( 'style' , 'text' , 'units' , ...
        'normalized' , 'fontunits' , 'normalized' , 'fontname' , ...
        'fixedwidth' , 'string' , ' ' , 'fontsize' , 1 , ...
        'position' , [ ( i - 1 ) / 20 0.90 0.05 0.05 ] );
end

for j = 1 : length( word1 )
    set( letters( 1 , j ) , 'string' , word1( j ) );
end

for k = 1 : length( word2 )
    set( letters( 2 , k ) , 'string' , word2( k ) );
end

for m = 1 : shorter
    if( word1( m ) == word2( m ) )
        set( letters( 1 , m ) , 'BackgroundColor' , [ 0 1 0 ] );
        set( letters( 2 , m ) , 'BackgroundColor' , [ 0 1 0 ] );
    else
        set( letters( 1 , m ) , 'BackgroundColor' , [ 1 0 0 ] );
        set( letters( 2 , m ) , 'BackgroundColor' , [ 1 0 0 ] );
    end
end

for n = shorter + 1 : longer
    set( letters( 1 , n ) , 'BackgroundColor' , [ 1 0 0 ] );
    set( letters( 2 , n ) , 'BackgroundColor' , [ 1 0 0 ] );
end

distance = uicontrol( 'style' , 'text' , 'units' , ...
    'normalized' , 'fontunits' , 'normalized' , 'fontname' , ...
    'fixedwidth' , 'string' , ' ' , 'fontsize' , 0.5 , ...
    'position' , [ 0.8 0 0.2 0.2 ] );

hamDist = calculateHammingDistance( word1 , word2 );
set( distance , 'string' , ...
    printHammingDistance( hamDist ) );