function xmas_tree(n)

%Ein Tannenbaum ist mindestens 9x9 (Satz)
if mod(n,9)~=0
    n=floor(n/9)*9+9;
end

tree=zeros(n,n);
nn=n/9;

%Stammfunktion
for i=nn+1:2*nn
    for j=4*nn+1:5*nn
        tree(i,j)=80;
    end
end

%der Baum (also das Gruen)
c=0;
for i=2*nn+1:4*nn
    if mod(i,3)==0
        c=c+2;
    else
        c=c+1;
    end
    
    for j=nn+1:8*nn
        if ((j>nn+c) && (j<=8*nn-c))
            tree(i,j)=32;
        end
    end
end

c=0;
for i=4*nn+1:6*nn
    c=c+1;
    for j=2*nn+1:7*nn
        if ((j>2*nn+c) && (j<=7*nn-c))
            tree(i,j)=32;
        end
    end
end

c=0;
for i=6*nn+1:8*nn+floor(nn/2)
    
    c=c+1;
    for j=3*nn+1:6*nn
        if ((j>3*nn+c) && (j<=6*nn-c))
            tree(i,j)=32;
        end
     end
end

tree2=zeros(n,n);
for i=1:n
    tree2(i,:)=tree(n-i+1,:);
end

%random rote Kugeln (maximal 200)
for z=1:200
   radius=nn/5; 
   pos_x=floor(n*rand(1))+1;
   pos_y=floor(n*rand(1))+1;
   yess=0;
   for i=1:n
        for j=1:n
             if (((pos_x-i)^2+(pos_y-j)^2)<radius^2)
                  if ((tree2(i,j)==55))
                      yess=1;
                  end
             end
        end
   end
   if (tree2(pos_x,pos_y)~=32)
       yess=1;
   end
   
   if (yess==0)
       for i=1:n
           for j=1:n
                if (((pos_x-i)^2+(pos_y-j)^2)<radius^2)
                    tree2(i,j)=55;
                end
           end
       end
   end
end


colormap(jet);
image(tree2);

end

