// lissa juice
// 7/2017 christian perle

global_settings {
	max_trace_level 15
}

camera {
	location <.001, .001, -500>
	look_at 0
}

#declare Seed = clock;
#declare A = seed(Seed);

light_source { <-100, 40, -100> color rgb 1 }
light_source { <80, -42, -100> color rgb .7 }
light_source { <.001, .001, -500> color rgb .3 }

// background sphere
sphere {
	0, 1
	hollow
	texture {
		pigment {
			gradient y
			color_map {
				[0 color rgb .25]
				[1 color rgb .75]
			}
			scale 1.1
			translate -.55*y
		}
		finish { ambient 1 diffuse 0 }
	}
	texture {
		pigment {
			gradient y
			color_map {
				[0 color rgbf 1]
				[0.9 color rgbf 1]
				[1 color rgb 0]
			}
			scale .01
			translate -1000*y
		}
		finish { ambient 1 diffuse 0 }
	}
	rotate -5*z
	scale 3000
}

// (not) random p and q
//#declare p = rand(A)*10+1;
//#declare q = rand(A)*10+1;
#declare p = 5;
#declare q = 3;

// 640x480 "pixels"
#declare X0= 320;
#declare Y0 = 479;
#declare i = 0;
#declare n = 1;
#declare Liss = union {
#while (n < 150)
	// red dots at line joints
	sphere { <X0, Y0, 0>, 2 pigment { rgb <1, .1, .1> } }
	#declare i = i + p;
	#declare X1 = 320*(sin(i) + 1);
	#declare Y1 = 240*(cos(i*q) + 1);
	// colored lines
	cylinder {
		<X0, Y0, 0>, <X1, Y1, 0>, 1
		// line colors build from sin/cos
		pigment { rgb <sin(i), cos(i*q), 1> }
	}
	#declare X0 = X1;
	#declare Y0 = Y1;
	#declare n = n + 1;
#end
	translate <-320, -240, 0>
}

#declare GlBase = sor {
	8,
	<0.0, -0.5>,
	<3.0, 0.0>,
	<1.0, 0.2>,
	<0.7, 0.4>,
	<0.7, 4.0>,
	<2.0, 5.0>,
	<3.0, 10.0>,
	<4.0, 11.0>
}

#declare Glass = difference {
	object {
		GlBase
	}
	object {
		GlBase
		scale <.9, 1, .9>
	}
	pigment { rgbf<.95, .9, .85, .9> }
	finish { phong .6 reflection .01 ior 1.1 }
	normal { crackle .2 scale .1 }
	scale 20
}

#declare Juice = intersection {
	object {
		GlBase
		scale <.899, 1, .899>
	}
	plane { -y, -4 }
	plane { y, 8 }
	pigment { rgbf<.4, .7, 1, .9> }
	finish { phong .3 }
	normal { ripples }
	scale 20
}

union {
	object {
		Glass
		translate 5*y
	}
	object {
		Juice
		translate 5*y
	}
	object {
		Liss
		scale 0.8
		rotate 90*x
		translate -5*y
	}
	rotate -40*x
	rotate -20*y
	translate <10, -10, -10>
}