// ======================================================================
// CORES E TEXTURAS

background { color rgb < 0.9,0.9,0.9 > }

#declare tx_esfera =
	texture {
	    pigment { color rgb < 1,0,1 > }
		finish{ diffuse 1 }
    }

// ======================================================================
// DESCRIÇÃO DA CENA 

// Partes da cena

#include "eixos.inc"

#declare esfera = sphere {
	< 0, 0, 0 >, 0.05
	texture{ tx_esfera }
}

#macro linearInterpolation(t0, v0, t1, v1, tt)
	#local r = (tt-t0)/(t1-t0);
	#local s = 1 - r;
	#local vv = s*v0 + r*v1;
	vv
#end

#macro bezierCurve(t0,t1,A,B,C,D,tt)
	#local AB = linearInterpolation(t0,A, t1,B, tt);
	#local BC = linearInterpolation(t0,B, t1,C, tt);
	#local CD = linearInterpolation(t0,C, t1,D, tt);
	
	#local ABC = linearInterpolation(t0,AB, t1,BC, tt);
	#local BCD = linearInterpolation(t0,BC, t1,CD, tt);
	
	#local ABCD = linearInterpolation(t0,ABC, t1,BCD, tt);
	
	ABCD
#end

#macro drawLine(A, B)
	#for (i, 0, 1, 0.01)
		object { esfera translate linearInterpolation(0,A, 1,B, i) }
	#end
#end

#macro drawBezier(A,B,C,D)
	#for (i, 0, 1, 0.001)
		object { esfera translate bezierCurve(0,1, A,B,C,D, i) }
	#end
#end

#macro drawSquare()
	union {
		drawLine(<-0.5,0.5,0>, <0.5,0.5,0>)
		drawLine(<0.5,0.5,0>, <0.5,-0.5,0>)
		drawLine(<0.5,-0.5,0>, <-0.5,-0.5,0>)
		drawLine(<-0.5,-0.5,0>, <-0.5,0.5,0>)
	}
#end

#macro drawCurve()
	union {
		drawBezier(<-1,0,-1>,<1,0.5,0.5>,<-0.5,0,0.5>,<0,0.5,0>)
		drawBezier(<0,0.5,0>,<0,1,0>,<0,0.5,-0.8>,<-0.4,0,-0.8>)
		drawBezier(<-0.4,0,-0.8>,<-1,-0.4,-1>,<-0.5,0.2,-0.5>,<-1,0,-1>)
	}
#end

// Aqui está a cena, finalmente:

object { eixos(1) }

object { drawCurve() rotate <0,0,0> translate <0,0,0> }

#include "camlight.inc"
#declare centro_cena = < 0,0,0 >;
#declare raio_cena = 2;
#declare dir_camera = < 90, 0, 90 >; // 0, -1, 90 for XY
#declare dist_camera = raio_cena;
#declare intens_luz = 1.5;
camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)