% create a random number of sphere

creaternd :- creaternd2(50,100,1,10).

createsingle(Alt,MaxDim,MinRad,MaxRad):-
	rt_rnd(XR),rt_rnd(YR),rt_rnd(ZR),
	rt_rnd(R),rt_rnd(G),rt_rnd(B),
	TX is (XR * MaxDim),
	TY is (YR * MaxDim),
	TZ is (ZR * MaxDim),
	X is ( TX * 2) - MaxDim,
	Y is ( TY * 2) - MaxDim,
	Z is ( TZ * 2) - MaxDim,
	rt_nspc(spr,Alt,MatName),
	write('Nome del materiale creato:'),write(MatName),nl,
	rt_createplanematerial( MatName,R,G,B),
	rt_rnd(RR),
	write(qui),nl,
	Radius is RR * (MaxRad-MinRad) + MinRad,
	write(fatto),nl,
	rt_createsphere(MatName,X,Y,Z,Radius,MatName).
	
creaternd2(0,MaxDim,MinRad,MaxRad) :- !.
creaternd2(Num,MaxDim,MinRad,MaxRad):- NextNum is Num -1,
	createsingle(Num,MaxDim,MinRad,MaxRad),
	creaternd2(NextNum,MaxDim,MinRad,MaxRad).
	
