
clear all ;
clf;
%This script simulates the basic behavior of a geyser in a vaccumm 
%just press run and it will call on the path.m file
%all code is original
%because not using drag yet, current conditions apply to Earth


% global constants unchanged for the drag accelerration
%not yet relevant since initial simulation is in a vaccumm

global rho_air;
%this rho of air is based off of the atmosphere of Enceladus being
%primarily water vapor
rho_air=.6 %kg/m^3

%create area of 'geyser' for references of where (0,0) is 
range=50 %however big you want the square to be
xx = -range:1:range;
yy = -range:1:range;
[X,Y] = meshgrid(xx,yy);
view_start=20; % variable in case want to change the view later on dependent 
view([view_start 40]);

%size of 
hm=size(X);
Z=zeros(hm(2));


%plot the square
subplot(1,3,2)
mesh(X,Y,Z);
colormap winter
hold on





%choose how many particles you want to see the trajectory for
num_of_iterations=100;

%make arrays to plot the distribution of the landing point of the particles
last_x=zeros(num_of_iterations);
last_y=zeros(num_of_iterations);
last_z=zeros(num_of_iterations);

f=1
for i =1:num_of_iterations


%define inputs to input for the path
%use random so theta and phi can vary with minimal bias
theta=rand();
theta=theta*360.;
phi=rand();
phi=phi*360.;
Vo=rand();
Vo=Vo*100;
t=[0:.5:100];
gravity=9.8
[x,y,z]=path(t,gravity,Vo, theta, phi)

%[x,y,z]=path(Vo,t,9.8,theta,phi);

%set boundary must equal 0
%adjust the trajectory so that it just falls like below the last one
size_z=size(z);
    for i=1:size_z(2);
         if z(i) < 0;
%              x(i)=((x(i-1)*.5))+((x(i))*.5);
%             y(i)=((y(i-1))*.5)+((y(i))*.5);
            x(i)=(x(i-1));
            y(i)=(y(i-1));
            z(i)=1;
%             x = Vo*cosd(theta)*t ;
%             y=Vo*cosd(phi)*t;
        end
    end

x;
y;
z;

subplot(1,3,1) 
view([view_start+(i*(30)) 40]);
plot3(x,y,z);
%view([100 view_start+(i*(10))]);
%view([view_start+(i*(30)) 40]);
hold on


%=======================


    for j=2:size_z(2);
        subplot(1,3,2) ;
        plot3(x(j),y(j),z(j), '.')%, 'markerfacecolor', 'b', 'markeredgecolor','b');
        
        
       %consistently erase each and every one 
       %alternate way to represent data
       % if j <size_z(2);
       % subplot(1,2,2)
       % plot3(x(j-1),y(j-1),z(j-1),'o','markerfacecolor', 'w', 'markeredgecolor','w');
       % end
       
       
       %erase each one after its been to the end
       if j >= size_z(2);
       subplot(1,3,2);
       plot3(x(1:j-1),y(1:j-1),z(1:j-1),'.','markerfacecolor', 'w', 'markeredgecolor','w');
       plot3(x(j),y(j),z(j), 'o', 'markerfacecolor', 'b', 'markeredgecolor','b');
       title('Trajectory of Material from a Geyser') 
       
       last_x(i)=x(j);
       last_y(i)=y(j);
      
       saveas(gcf, ['GEYSERA_',sprintf('%03d',f),'.png'])
       f=f+1
       end    
       
       
       
      %  pause(.00001);

        

    end

%================

%the geyser will start at 0,0

%plot 2d distribution of final place of material
subplot(1,3,3);
plot(last_x,last_y, 'o', 'markerfacecolor', 'b', 'markeredgecolor','b');
title('X Y Distribution of Material on the Surface')
%saveas(gcf, ['GEYSERA_',sprintf('%03d',f),'.png'])

end


