function sierpinski_random(Nstep)
	%% Sierpinski fractal - random points method

	if nargin < 1, Nstep=4; end
	if (Nstep > 8), disp('calculation may take to long, values more than 10 are not recommended'); end


	% triangle base
	tBase=800;
	
	points=zeros(Nstep,2);

	% triangle vertexes coordinates
	% upside triangle 
	v(1, :)=[1, 1];
	v(2, :)=[tBase, 1];
	v(3, :)=[ tBase/2, tBase];

	function fill_triangle(vertexes, color)
		fill( vertexes(:,1), vertexes(:,2), color);
	end
		

	%% fill initial triangle
	figure();
	fill_triangle(v, 'blue');
	hold on;

	%% the main recursive function which do all the work
	function work_on_triangle(vt, counter)
		% FIRST WE CHECK THE COUNTER TO STOP RECURSIVE CALLS
		if (counter == 0)
			return;
		end
		counter=counter-1;

		function fill_triangle(vertexes, color)
			fill( vertexes(:,1), vertexes(:,2), color);
		end

		% now we clear the middle triangle
		vmid(1,:)= ( vt(1,:) + vt(2,:) )/2;
		vmid(2,:)= ( vt(1,:) + vt(3,:) )/2;
		vmid(3,:)= ( vt(2,:) + vt(3,:) )/2;
		fill_triangle(vmid, 'white');

		% calculate vertexes of 3 sub triangles
		vt1(1,:)=vt(1,:);
		vt1(2,:)=vmid(1,:);
		vt1(3,:)=vmid(2,:);
		work_on_triangle(vt1, counter);

		vt2(1,:)=vt(2,:);
		vt2(2,:)=vmid(1,:);
		vt2(3,:)=vmid(3,:);
		work_on_triangle(vt2, counter);

		vt3(1,:)=vt(3,:);
		vt3(2,:)=vmid(2,:);
		vt3(3,:)=vmid(3,:);
		work_on_triangle(vt3, counter);
	end


	work_on_triangle(v, Nstep);
	

end

	




