do the_cactus;


include 'smpl_textures';
include 'smpl_bumps';


object pot is
	cone with
		end1 = 0 0 0;
		end2 = 0 0 2.0;
		radius1 = 1.0;
		radius2 = 1.25;
	end;
	cone with
		end1 = 0 0 0;
		end2 = 0 0 2.0;
		radius1 = .90;
		radius2 = 1.15;
	end; {sides of }
	torus with
		center = 0 0 0;
		normal = 0 0 1;
		inner_radius = 1.15;
		outer_radius = 1.25;
		scale by .5 along 0 0 1;
		move to 0 0 2.0;
	end; {Top cap for the sides }
	sphere with 
		center = 0 0 0;
		radius = 1.0;
		scale by .1 along 0 0 1;
	end; {Base of }
end;	{pot}


object water_catch is
	pot with
		scale by .25 along 0 0 1;
		scale by 1.25 along 1 0 0;
		scale by 1.25 along 0 1 0;
	end;
end;	{water_catch}


object cactus_pot is
	pot with move to 0 0 .1; end;
	water_catch with color = .9 .4 .2; end;
	flat speckled brown paraboloid with
		base = 0 0 1.90;
		top = 0 0 2.0;
		radius = 1.2;
	end; {soil}
end; 	{cactus_pot}


object spike is 

	cone with
		end1 = 0 0 0;
		end2 = 0 0 1;
		radius1 = .08;
		radius2 = .0001;
		color = .8 1 .65;
	end;
end; 	{cactus spike}


object cactus_spindle is
	spike; 
	spike with
		scale by 1.2 along 0 0 1;
		rotate by 30 around 1 0 0;
		rotate by 50 around 0 0 1;
	end;
	spike with
		scale by .8 along 0 0 1;
		rotate by 50 around 1 0 0;
		rotate by 120 around 0 0 1;
	end;
	spike with
		scale by .8 along 0 0 1;
		rotate by 20 around 1 0 0;
		rotate by 200 around 0 0 1;
	end;
	spike with
		scale by .9 along 0 0 1;
		rotate by 60 around 1 0 0;
		rotate by 300 around 0 0 1;
	end;
	spike with
		rotate by 35 around 1 0 0;
		rotate by 10 around 0 0 1;
	end;
end; 	{cactus_spindle}


object cactus_node is
	scalar f = 0;
	scalar sweep, d, ran, fy, fystep;
	sweep = 180 / 5;

	sphere with 
		center = 0 0 0;
		radius = 1.0;    
	end;
	sphere with
		center = 0 0 0;
		radius = .4;
		scale by .5 along 0 0 1;
		move to 0 0 .9; 
	end; {...comprising the main cactus fleshoid...}

	while f <> 5 do
		torus with
			center = 0 0 0;
			normal = 0 1 0;
			inner_radius = .80;
			outer_radius = 1.08;
			rotate by (f * sweep) around 0 0 1;
		end; {spine_ridges }
		f = f + 1;
	end; { create spin ridges }

	f = 0;
	ran = 0;
	fystep = .25 / 12;
	while f <> 5 do
		d = 20;
		fy = .20;
		while d <> 140 do
			glossy white cactus_spindle with
				magnify by fy;
				rotate by ran around 0 0 1;
				move to 0 0 1.07;
				rotate by d around 1 0 0;
				rotate by ((f * sweep)+ (sweep / 2)) 
					around 0 0 1;
			end; { place spike }
			glossy white cactus_spindle with
				magnify by fy;
				rotate by -ran around 0 0 1;
				move to 0 0 1.07;
				rotate by -d around 1 0 0;
				rotate by ((f * sweep)+ (sweep / 2)) 
					around 0 0 1;
			end; { place spike }
			ran = ran + 33;
			fy = fy + fystep;
			d = d + 10;
		end;
		f = f + 1;
	end; { place spike loop }
end; 	{cactus_node}


object flower is 
	hyperboloid1 with
		end1 = 0 0 0;
		end2 = 0 0 1;
		radius1 = .1;
		radius2 = .4;
		color = .4 .1 .9;
	end;
	sphere with
		center = 0 0 0;
		radius = .4;
		scale by .25 along 0 0 1;
		move to 0 0 1;
		color = .4 .1 .9;
	end;
	paraboloid with
		base = 0 0 3;
		top = 0 0 .60;
		radius = .95;
		color = .6 .1 .7;
	end;
	cylinder with 
		radius = .05;
		end1 = 0 0 .6;
		end2 = 0 0 1.8;
		rotate by 10 around 1 0 0;
		rotate by 100 around 0 0 1;
		color = red; 
	end;
	cylinder with 
		radius = .05;
		end1 = 0 0 .6;
		end2 = 0 0 1.8;
		rotate by 10 around 1 0 0;
		rotate by 200 around 0 0 1;
		color = red; 
	end;
	cylinder with 
		radius = .05;
		end1 = 0 0 .6;
		end2 = 0 0 1.8;
		rotate by 10 around 1 0 0;
		rotate by 300 around 0 0 1;
		color = red; 
	end;
end;	{object flower}


object flower_stalk is
	sphere with
		center = 0 0 0;
		radius = .25;
		scale by 2 along 0 0 1;
		color = .2 1 .1;
	end;
	glossy bumpy red flower with
		magnify by .25;
		rotate by 20 around 1 0 0;
		rotate by 30 around 0 0 1;
		move to 0 0 .5;
	end;
	glossy bumpy yellow flower with
		magnify by .35;
		rotate by 50 around 1 0 0;
		rotate by 230 around 0 0 1;
		move to 0 0 .5;
	end;
	glossy bumpy purple flower with
		magnify by .31;
		rotate by 70 around 1 0 0;
		rotate by 180 around 0 0 1;
		move to 0 0 .5;
	end;
end; 	{flower_stalk}


object cactus is
	glossy ridged (.9 .5 .3) cactus_pot;
	cactus_node with 
		scale by 2.25 along 0 0 1;
		magnify by .55;
		move to 0 0 3.20;
	end;
	flower_stalk with
		move to 0 0 11.15;
		magnify by .4;
	end;
	{
	glossy speckled grey sphere with 
		center = 0 0 0;
		radius =  5.0;
		scale by .01 along 0 0 1;
		move to 0 0 -.1;
	end; {table}
	}
end;	{object cactus}

 
picture the_cactus with  
	render_mode = shaded;
	facets = 0;
	edges = silhouette;
	field_of_view = 100;
	projection = fisheye;
	eye = (2.5 * cos 0) (3.5 * sin 0) 6.25;
	lookat = 0 0 3;
is
	distant_light with direction = .3 -.5 1; end;
	glossy bumpy dark green cactus; 
end; {the_cactus}

 
anim rolling_cactus with
	facets = 8;
is
	scalar rad1 = 180;
	while true do
		the_cactus;
		eye = (2.5 * cos rad1) (3.5 * sin rad1) 6.25;
		{
		eye = 0 -6 2;
		}
		rad1 = rad1 - 3;
	end;
end;	{ rolling_cactus }