read(IntBasis);

curve:=proc(functie_in_x,d,t,eps,x,projection_angle) local f,fre,fim,factor;
	f:=evalf(expand(subs(x=eps*(cos(t)+I*sin(t)),functie_in_x)));
	fre:=coeff(f,I,0)/eps;fim:=coeff(f,I,1)/eps;
	factor:=1/sqrt(1+fre^2+fim^2);
	f:=[factor*cos(d*t),factor*sin(d*t),factor*fre,factor*fim];
	f:=evalf([
	 cos(projection_angle)*f[1]+sin(projection_angle)*f[3],
	 cos(projection_angle)*f[2]+sin(projection_angle)*f[4],
	 sin(projection_angle)*f[1]-cos(projection_angle)*f[3],
	 sin(projection_angle)*f[2]-cos(projection_angle)*f[4]
	]);

#	f:=evalf([f[1..2],
#	 cos(2*projection_angle)*f[3]+sin(2*projection_angle)*f[4],
#	 sin(2*projection_angle)*f[3]-cos(2*projection_angle)*f[4]]);

#	f:=evalf([
#	 cos(2*projection_angle)*f[1]+sin(2*projection_angle)*f[2],
#	 sin(2*projection_angle)*f[1]-cos(2*projection_angle)*f[2],
#	f[3..4]]);

#	f:=evalf([
#	 cos(projection_angle+0.5)*f[1]+sin(projection_angle+0.5)*f[2],
#	 sin(projection_angle+0.5)*f[1]-cos(projection_angle+0.5)*f[2],
#	f[3..4]]);

	factor:=1-f[4];
	f:=[f[1]/factor,f[2]/factor,f[3]/factor];

# erbij gezet, om R^3 wat te deformeren.

	factor:=(f[1]^2+f[2]^2+f[3]^2+1)^(1/3);
	[f[1]/factor,f[2]/factor,f[3]/factor]

end:

plot_knot:=proc(f,x,y,pa)
	local ext_f,pui,ext_pui,i,curven,true_or_not,t,eps,cols;
global opt,pui2;
	opt:={args[5..nargs]};
# for i in opt do if type(i,numeric) then opt:=opt minus {i} fi od:
	if not member(numpoints,indets(opt)) then opt:=opt union {numpoints=150} fi;
	if not member(radius,indets(opt)) then opt:=opt union {radius=0.05} fi;
	if not member(tubepoints,indets(opt)) then opt:=opt union {tubepoints=5} fi;
	if not member(scaling,indets(opt)) then opt:=opt union {scaling=CONSTRAINED} fi;
	if not member(style,indets(opt)) then opt:=opt union {style=PATCH} fi;
	eps:=1;
	if member(epsilon,indets(opt)) then
		eps:=subs(opt,epsilon);
		opt:=opt minus {epsilon=eps}
	fi;
	cols:=[];
	if member(colours,indets(opt)) then
		cols:=subs(opt,colours);
		opt:=opt minus {colours=cols}
	fi;
if pa=0 then
	ext_f:=g_ext(f);
	pui:=`puiseux/technical_answer`(g_expand(subs(g_conversion1,f),ext_f)
	 ,x,y,0,ext_f);
	ext_f:=subs(g_conversion2,ext_f);
	ext_pui:=subs(g_conversion2,g_ext(pui));
	ext_pui:=[ext_pui[1..nops(ext_pui)-nops(ext_f)]];
	ext_f:=all_substitutions(ext_f);
	ext_f:=ext_f[1];
	ext_pui:=all_substitutions(subs(ext_f,ext_pui));
	pui:=subs(ext_f,subs(g_conversion2,pui));
	# Now replace the RootOf's by all corresponding floating point numbers
	pui2:={};
	for i in ext_pui do
		pui2:=pui2 union subs(i,pui)
	od;
	pui:=pui2;
	pui2:={};
	for i in pui do
		true_or_not:=element_of(i[1],i[3],pui2,x);
		if (not true_or_not) then pui2:=pui2 union {i} fi
	od;
	pui2:=[op(pui2)]
fi;
	curven:=NULL;
	for i in pui2 do curven:=curven,curve(i[1],i[3],t,eps,x,pa) od;
curven:=[curven];
	if printlevel>1 then print(`Number of branches:`,nops(curven)) fi;
	if cols=[] then
		plots[tubeplot](curven,t=0..2*Pi,op(opt))
	else
		curven:=[op(curven)];
plots[display](
		[seq(plots[tubeplot](curven[i],t=0..2*Pi,op(opt),
		 color=cols[1+irem(i,nops(cols))]),i=1..nops(curven))]
)
	fi
end:

N:=120;

f:=(y^2-x^3)*(y^2-x^3+7*x^10)*(y^2-x^3-7*x^10);
plotsetup(gif);
#plots[display](
for i from 0 to N-1  do
plotsetup(plotoutput=plaatje.(100+i));
plots[display](
plot_knot(f,y,x,evalf(2*Pi*i/N),epsilon=0.85, tubepoints=10,numpoints=500, # numpoints=60, # 
radius=0.03,colours=[blue,red,yellow],style = PATCHNOGRID,light=[0,0,1,1,1],
	ambientlight=[1/2,1/2,1/2],view=
#	[-8..8,-8..8,-8..8])
# na deformeren is ie kleiner:
	[-2.4..2.4,-2.4..2.4,-2.4..2.4])
,orientation=[135,0])
od;
quit

